Skip to content

Commit dbb9ddd

Browse files
feat: Add hosting to firebase_init MCP tool, and use it in the init prompt (#9375)
* feat: Add hosting to firebase_init MCP tool Adds hosting to the firebase_init MCP tool. It lets users configure the siteId, public directory, and whether to configure it as a single page app. * Improvements and changelog * More arg renaming for consistency, and use the tool in init prompt * Move deploy up into backend guide * format * typo --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 0576d13 commit dbb9ddd

File tree

4 files changed

+52
-36
lines changed

4 files changed

+52
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Added 'hosting' to the 'firebase_init' MCP tool.

src/mcp/resources/guides/init_backend.ts

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const init_backend = resource(
88
description:
99
"guides the coding agent through configuring Firebase backend services in the current project",
1010
},
11-
async (uri) => {
11+
async (uri, ctx) => {
1212
return {
1313
contents: [
1414
{
@@ -25,31 +25,8 @@ The user will likely need to setup Firestore, Authentication, and Hosting. Read
2525
3. [Firestore Rules](firebase://guides/init/firestore_rules): read this to setup the \`firestore.rules\` file for securing your database
2626
4. [Hosting](firebase://guides/init/hosting): read this if the user would like to deploy to Firebase Hosting
2727
28-
**firebase.json**
29-
The firebase.json file is used to deploy Firebase products with the firebase deploy command.
30-
31-
Here is an example firebase.json file with Firebase Hosting, Firestore, and Cloud Functions. Note that you do not need entries for services that the user isn't using. Do not remove sections from the user's firebase.json unless the user gives explicit permission. For more information, refer to [firebase.json file documentation](https://firebase.google.com/docs/cli/#the_firebasejson_file)
32-
\`\`\`json
33-
{
34-
"hosting": {
35-
"public": "public",
36-
"ignore": [
37-
"firebase.json",
38-
"**/.*",
39-
"**/node_modules/**"
40-
]
41-
},
42-
"firestore": {
43-
"rules": "firestore.rules",
44-
"indexes": "firestore.indexes.json"
45-
},
46-
"functions": {
47-
"predeploy": [
48-
"npm --prefix "$RESOURCE_DIR" run lint",
49-
"npm --prefix "$RESOURCE_DIR" run build"
50-
]
51-
}
52-
}
28+
Once you are done setting up, ask the user if they would like to deploy.
29+
If they say yes, run the command '${ctx.firebaseCliCommand} deploy --non-interactive' to do so.
5330
\`\`\`
5431
`.trim(),
5532
},

src/mcp/resources/guides/init_hosting.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getDefaultHostingSite } from "../../../getDefaultHostingSite";
12
import { resource } from "../../resource";
23

34
export const init_hosting = resource(
@@ -8,26 +9,30 @@ export const init_hosting = resource(
89
description:
910
"guides the coding agent through deploying to Firebase Hosting in the current project",
1011
},
11-
async (uri) => {
12+
async (uri, ctx) => {
13+
const defaultHostingSite = await getDefaultHostingSite(ctx);
1214
return {
1315
contents: [
1416
{
1517
uri,
1618
type: "text",
1719
text: `
1820
### Configure Firebase Hosting
21+
Default hosting site for ${ctx.projectId}: ${defaultHostingSite || "Does not exist"}
22+
If there is not a default hosting site configured, ask the user what the site ID should be, and suggest ${ctx.projectId} as a good choice.
23+
Next, use the 'firebase_init' tool to set up hosting. Below is an example of what the arguments to do so look like;
24+
however, you should change the values to match the user's choices and project structure:
25+
{
26+
features: {
27+
hosting: {
28+
site_id: ${ctx.projectId},
29+
public_directory: public,
30+
}
31+
}
32+
}
1933
2034
**Security Warning:**
2135
- Files included in the public folder of a hosting site are publicly accessible. Do not include sensitive API keys for services other than Firebase in these files.
22-
23-
**When to Deploy:**
24-
- Introduce Firebase Hosting when developers are ready to deploy their application to production.
25-
- Alternative: Developers can deploy later using the \`/firebase:deploy\` command.
26-
27-
**Deployment Process:**
28-
- Request developer's permission before implementing Firebase Hosting
29-
- Request developer's permission before deploying Firebase Hosting app to production.
30-
- Configure Firebase Hosting and deploy the application to production
3136
`.trim(),
3237
},
3338
],

src/mcp/tools/core/init.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,31 @@ export const init = tool(
140140
})
141141
.optional()
142142
.describe("Enable Firebase AI Logic feature for existing app"),
143+
hosting: z
144+
.object({
145+
site_id: z
146+
.string()
147+
.optional()
148+
.describe(
149+
"The ID of the hosting site to configure. If omitted and there is a default hosting site, that will be used.",
150+
),
151+
public_directory: z
152+
.string()
153+
.optional()
154+
.default("public")
155+
.describe(
156+
"The directory containing public files that will be served. If using a build tool, this likely should be the output directory of that tool.",
157+
),
158+
single_page_app: z
159+
.boolean()
160+
.optional()
161+
.default(false)
162+
.describe("Configure as a single-page app."),
163+
})
164+
.optional()
165+
.describe(
166+
"Provide this object to initialize Firebase Hosting in this project directory.",
167+
),
143168
}),
144169
}),
145170
annotations: {
@@ -219,6 +244,14 @@ export const init = tool(
219244
displayName: appData.displayName,
220245
};
221246
}
247+
if (features.hosting) {
248+
featuresList.push("hosting");
249+
featureInfo.hosting = {
250+
newSiteId: features.hosting.site_id,
251+
public: features.hosting.public_directory,
252+
spa: features.hosting.single_page_app,
253+
};
254+
}
222255
const setup: Setup = {
223256
config: config?.src,
224257
rcfile: rc?.data,

0 commit comments

Comments
 (0)