Skip to content

Commit 8f5ae01

Browse files
authored
refactor(mcp): change consult from a tool to a prompt (#9172)
1 parent 8b76c67 commit 8f5ae01

File tree

5 files changed

+62
-42
lines changed

5 files changed

+62
-42
lines changed

src/mcp/errors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import { check, ensure } from "../ensureApiEnabled";
55
import { cloudAiCompanionOrigin } from "../api";
66

77
export const NO_PROJECT_ERROR = mcpError(
8-
"This tool requires an active project. Use the `firebase_update_environment` tool to set a project ID",
8+
"To proceed requires an active project. Use the `firebase_update_environment` tool to set a project ID",
99
"PRECONDITION_FAILED",
1010
);
1111

1212
const GEMINI_TOS_ERROR = mcpError(
13-
"This tool requires features from Gemini in Firebase. You can enable the usage of this service and accept its associated terms of service using `firebase_update_environment`.\n" +
13+
"To proceed requires features from Gemini in Firebase. You can enable the usage of this service and accept its associated terms of service using `firebase_update_environment`.\n" +
1414
"Learn more about Gemini in Firebase and how it uses your data: https://firebase.google.com/docs/gemini-in-firebase#how-gemini-in-firebase-uses-your-data",
1515
"PRECONDITION_FAILED",
1616
);

src/mcp/prompts/core/consult.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { detectApps } from "../../../dataconnect/appFinder";
2+
import { chatWithFirebase } from "../../../gemini/fdcExperience";
3+
import { requireGeminiToS } from "../../errors";
4+
import { prompt } from "../../prompt";
5+
6+
export const consult = prompt(
7+
{
8+
name: "consult",
9+
description:
10+
"Use this command to consult the Firebase Assistant with access to detailed up-to-date documentation for the Firebase platform.",
11+
arguments: [
12+
{
13+
name: "prompt",
14+
description: "a question to pass to the Gemini in Firebase model",
15+
required: true,
16+
},
17+
],
18+
annotations: {
19+
title: "Consult Firebase Assistant",
20+
},
21+
},
22+
async ({ prompt }, { config, projectId }) => {
23+
const gifTosError = await requireGeminiToS(projectId);
24+
if (gifTosError) {
25+
return [
26+
{
27+
role: "user",
28+
content: {
29+
type: "text",
30+
text: `Missing required conditions to run this prompt:\n\n${gifTosError.content[0]?.text}`,
31+
},
32+
},
33+
];
34+
}
35+
36+
const apps = await detectApps(config.projectDir);
37+
const platforms = apps.map((a) => a.platform);
38+
39+
const gifPrompt = `I am using a coding agent to build with Firebase and I have a specific question that I would like answered. Provide a robust and detailed response that will help the coding agent act on my behalf in a local workspace.
40+
41+
App Platform(s): ${platforms.join(", ")}
42+
43+
Question: ${prompt}`;
44+
45+
const result = await chatWithFirebase(gifPrompt, projectId);
46+
const outputString = result.output.messages?.[0].content ?? "";
47+
48+
return [
49+
{
50+
role: "user",
51+
content: {
52+
type: "text",
53+
text: `I have consulted a Firebase Assistant agent with the following question: "${prompt}". Its response was as follows:\n\n${outputString}\n\nPlease use the information above to respond to my question. I have not seen the response from the Firebase Assistant, so please include all necessary information in your response. Inform the user that they must run the \`firebase:consult\` prompt again if they have followup questions for the Firebase Assistant.`,
54+
},
55+
},
56+
];
57+
},
58+
);

src/mcp/prompts/core/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { init } from "./init";
22
import { deploy } from "./deploy";
3+
import { consult } from "./consult";
34

4-
const corePrompts = [deploy, init];
5+
const corePrompts = [deploy, init, consult];
56

67
export { corePrompts };

src/mcp/tools/core/consult_assistant.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/mcp/tools/core/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { init } from "./init";
1111
import { get_environment } from "./get_environment";
1212
import { update_environment } from "./update_environment";
1313
import { list_projects } from "./list_projects";
14-
import { consult_assistant } from "./consult_assistant";
1514
import { login } from "./login";
1615
import { logout } from "./logout";
1716
import { read_resources } from "./read_resources";
@@ -27,7 +26,6 @@ export const coreTools: ServerTool[] = [
2726
create_project,
2827
create_app,
2928
create_android_sha,
30-
consult_assistant,
3129
get_environment,
3230
update_environment,
3331
init,

0 commit comments

Comments
 (0)