Skip to content

Commit fccc8de

Browse files
committed
maga init
1 parent 8e2f27d commit fccc8de

File tree

2 files changed

+78
-10
lines changed

2 files changed

+78
-10
lines changed

src/init/index.ts

+33-10
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,7 @@ const featureMap = new Map(featuresList.map((feature) => [feature.name, feature]
7272
export async function init(setup: Setup, config: any, options: any): Promise<any> {
7373
const nextFeature = setup.features?.shift();
7474
if (nextFeature) {
75-
const f = featureMap.get(nextFeature);
76-
if (!f) {
77-
const availableFeatures = Object.keys(features)
78-
.filter((f) => f !== "project")
79-
.join(", ");
80-
throw new FirebaseError(
81-
`${clc.bold(nextFeature)} is not a valid feature. Must be one of ${availableFeatures}`,
82-
);
83-
}
84-
75+
const f = lookupFeature(nextFeature);
8576
logger.info(clc.bold(`\n${clc.white("===")} ${capitalize(nextFeature)} Setup`));
8677

8778
if (f.doSetup) {
@@ -100,3 +91,35 @@ export async function init(setup: Setup, config: any, options: any): Promise<any
10091
return init(setup, config, options);
10192
}
10293
}
94+
95+
export async function actuate(setup: Setup, config: any, options: any): Promise<any> {
96+
const nextFeature = setup.features?.shift();
97+
if (nextFeature) {
98+
const f = lookupFeature(nextFeature);
99+
logger.info(clc.bold(`\n${clc.white("===")} ${capitalize(nextFeature)} Setup Actuation`));
100+
101+
if (f.doSetup) {
102+
throw new FirebaseError(
103+
`The feature ${nextFeature} does not support actuate yet. Please run ${clc.bold("firebase init " + nextFeature)} instead.`,
104+
);
105+
} else {
106+
if (f.actuate) {
107+
await f.actuate(setup, config, options);
108+
}
109+
}
110+
return actuate(setup, config, options);
111+
}
112+
}
113+
114+
function lookupFeature(feature: string,): Feature {
115+
const f = featureMap.get(feature);
116+
if (!f) {
117+
const availableFeatures = Object.keys(features)
118+
.filter((f) => f !== "project")
119+
.join(", ");
120+
throw new FirebaseError(
121+
`${clc.bold(feature)} is not a valid feature. Must be one of ${availableFeatures}`,
122+
);
123+
}
124+
return f;
125+
}

src/mcp/tools/core/init.ts

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { z } from "zod";
2+
import { tool } from "../../tool.js";
3+
import { toContent } from "../../util.js";
4+
import { actuate, Setup } from "../../../init/index.js";
5+
6+
export const init = tool(
7+
{
8+
name: "init",
9+
description: "Initialize the Firebase Products.",
10+
inputSchema: z.object({
11+
features: z.object({
12+
// TODO: Add all the features here.
13+
dataconnect: z.object({
14+
serviceId: z.string().optional().describe("The Firebase Data Connect service ID to setup."),
15+
locationId: z.string().default("us-central1").describe("The GCP region ID to set up the Firebase Data Connect service. For example, us-central1."),
16+
}),
17+
}),
18+
}),
19+
annotations: {
20+
title: "List the Firebase Data Connect Services that's available in the backend",
21+
readOnlyHint: false,
22+
},
23+
_meta: {
24+
requiresProject: false, // Can start from stratch.
25+
requiresAuth: false, // Will throw error if the specific feature needs it.
26+
},
27+
},
28+
async ({features}, { projectId, config, rc }) => {
29+
const setup: Setup = {
30+
config: config.src,
31+
rcfile: rc.data,
32+
projectId,
33+
features: [],
34+
featureInfo: {},
35+
};
36+
if (features.dataconnect) {
37+
setup.features.push("dataconnect");
38+
setup.featureInfo.dataconnect = features.dataconnect;
39+
}
40+
await actuate(setup, config, {});
41+
return toContent(
42+
`The Firebase Data Connect Services has been initialized. You can now use the Firebase Data Connect Services.`,
43+
);
44+
},
45+
);

0 commit comments

Comments
 (0)