Skip to content

Commit afdc320

Browse files
authored
[MCP] Consult Firebase Tool (#8494)
1 parent 955bf42 commit afdc320

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

src/gif/fdcExperience.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import { cloudCompanionOrigin } from "../api";
33

44
const apiClient = new Client({ urlPrefix: cloudCompanionOrigin(), auth: true });
55
const schemaGeneratorExperience = "/appeco/firebase/fdc-schema-generator";
6+
const geminiInFirebaseChatExperience = "/appeco/firebase/firebase-chat/free";
67
const operationGeneratorExperience = "/appeco/firebase/fdc-query-generator";
78

89
export interface GenerateSchemaRequest {
910
input: { messages: { content: string; author: string }[] };
1011
experienceContext: { experience: string };
1112
}
1213

14+
export type ChatExperienceRequest = GenerateSchemaRequest;
15+
1316
export interface GenerateSchemaResponse {
1417
output: { messages: { content: string }[] };
1518
displayContext: {
@@ -20,6 +23,24 @@ export interface GenerateSchemaResponse {
2023
};
2124
}
2225

26+
export interface ChatExperienceResponse {
27+
output: { messages: { content: string; author: string }[] };
28+
outputDataContext: {
29+
additionalContext: { "@type": string };
30+
attributionContext: {
31+
citationMetadata: {
32+
citations: {
33+
startIndex: number;
34+
endIndex: number;
35+
url: string;
36+
title: string;
37+
license: string;
38+
}[];
39+
};
40+
};
41+
};
42+
}
43+
2344
export interface GenerateOperationRequest {
2445
input: { messages: { content: string; author: string }[] };
2546
experienceContext: { experience: string };
@@ -55,6 +76,28 @@ export async function generateSchema(prompt: string, project: string): Promise<s
5576
return res.body.output.messages[0].content;
5677
}
5778

79+
/**
80+
* chatWithFirebase interacts with the Gemini in Firebase integration providing deeper knowledge on Firebase.
81+
* @param prompt the interaction that the user would like to have with the service.
82+
* @param project project identifier.
83+
* @return ChatExperienceResponse includes not only the message from the service but also links to the resources used by the service.
84+
*/
85+
export async function chatWithFirebase(
86+
prompt: string,
87+
project: string,
88+
): Promise<ChatExperienceResponse> {
89+
const res = await apiClient.post<ChatExperienceRequest, ChatExperienceResponse>(
90+
`/v1beta/projects/${project}/locations/global/instances/default:completeTask`,
91+
{
92+
input: { messages: [{ content: prompt, author: "USER" }] },
93+
experienceContext: {
94+
experience: geminiInFirebaseChatExperience,
95+
},
96+
},
97+
);
98+
return res.body;
99+
}
100+
58101
/**
59102
* generateOperation generates an operation based on the users prompt and deployed Firebase Data Connect Service.
60103
* @param prompt description of the operation the user would like to generate.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { z } from "zod";
2+
import { tool } from "../../tool.js";
3+
import { toContent } from "../../util.js";
4+
import { chatWithFirebase } from "../../../gif/fdcExperience.js";
5+
6+
export const consult_firebase_assistant = tool(
7+
{
8+
name: "consult_firebase_assistant",
9+
description:
10+
"Send a question to an AI assistant specifically enhanced to answer Firebase questions.",
11+
inputSchema: z.object({
12+
prompt: z
13+
.string()
14+
.describe("A description of what the user is trying to do or learn with Firebase."),
15+
}),
16+
annotations: {
17+
title: "Helps answer queries and provide information related to Firebase.",
18+
readOnlyHint: true,
19+
},
20+
_meta: {
21+
requiresProject: true,
22+
requiresAuth: true,
23+
// TODO: Create an endpoint to check for GiF activiation.
24+
},
25+
},
26+
async ({ prompt }, { projectId }) => {
27+
const schema = await chatWithFirebase(prompt, projectId!);
28+
return toContent(schema);
29+
},
30+
);

src/mcp/tools/core/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
import { consult_firebase_assistant } from "./consult_firebase_assistant";
12
import { get_firebase_directory } from "./get_firebase_directory";
23
import { set_firebase_directory } from "./set_firebase_directory";
34

4-
export const coreTools = [get_firebase_directory, set_firebase_directory];
5+
export const coreTools = [
6+
get_firebase_directory,
7+
set_firebase_directory,
8+
consult_firebase_assistant,
9+
];

0 commit comments

Comments
 (0)