Skip to content

Commit bd4197e

Browse files
authored
Add short-circuiting functionality to the init prompt (#9179)
1 parent 3ee5150 commit bd4197e

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/mcp/prompts/core/init.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { getPlatformFromFolder } from "../../../dataconnect/appFinder";
22
import { Platform } from "../../../dataconnect/types";
33
import { prompt } from "../../prompt";
4+
import { init_ai } from "../../resources/guides/init_ai";
5+
import { init_backend } from "../../resources/guides/init_backend";
6+
import { ServerResource } from "../../resource";
7+
8+
const GUIDE_PARAMS: Record<string, ServerResource> = {
9+
"ai-logic": init_ai,
10+
backend: init_backend,
11+
};
412

513
export const init = prompt(
614
{
@@ -17,7 +25,25 @@ export const init = prompt(
1725
title: "Initialize Firebase",
1826
},
1927
},
20-
async ({ prompt }, { config, projectId, accountEmail }) => {
28+
async ({ prompt }, mcp) => {
29+
const { config, projectId, accountEmail } = mcp;
30+
31+
// This allows a "short circuit" feature where you can pass a specific
32+
// name, like "ai-logic" into the prompt and get a specific guide
33+
const resourceDefinition = prompt ? GUIDE_PARAMS[prompt] : undefined;
34+
if (resourceDefinition) {
35+
const resource = await resourceDefinition.fn(resourceDefinition.mcp.uri, mcp);
36+
return resource.contents
37+
.filter((resContents) => !!resContents.text)
38+
.map((resContents) => ({
39+
role: "user" as const,
40+
content: {
41+
type: "text",
42+
text: String(resContents.text),
43+
},
44+
}));
45+
}
46+
2147
const platform = await getPlatformFromFolder(config.projectDir);
2248

2349
return [

0 commit comments

Comments
 (0)