Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added 'hosting' to the 'firebase_init' MCP tool.
29 changes: 3 additions & 26 deletions src/mcp/resources/guides/init_backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const init_backend = resource(
description:
"guides the coding agent through configuring Firebase backend services in the current project",
},
async (uri) => {
async (uri, ctx) => {
return {
contents: [
{
Expand All @@ -25,31 +25,8 @@ The user will likely need to setup Firestore, Authentication, and Hosting. Read
3. [Firestore Rules](firebase://guides/init/firestore_rules): read this to setup the \`firestore.rules\` file for securing your database
4. [Hosting](firebase://guides/init/hosting): read this if the user would like to deploy to Firebase Hosting

**firebase.json**
The firebase.json file is used to deploy Firebase products with the firebase deploy command.

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)
\`\`\`json
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
},
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": {
"predeploy": [
"npm --prefix "$RESOURCE_DIR" run lint",
"npm --prefix "$RESOURCE_DIR" run build"
]
}
}
Once you are done setting up, ask the user if they would like to deploy.
If they say yes, run the command '${ctx.firebaseCliCommand} deploy --non-interactive' to do so.
\`\`\`
`.trim(),
},
Expand Down
25 changes: 15 additions & 10 deletions src/mcp/resources/guides/init_hosting.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getDefaultHostingSite } from "../../../getDefaultHostingSite";
import { resource } from "../../resource";

export const init_hosting = resource(
Expand All @@ -8,26 +9,30 @@ export const init_hosting = resource(
description:
"guides the coding agent through deploying to Firebase Hosting in the current project",
},
async (uri) => {
async (uri, ctx) => {
const defaultHostingSite = await getDefaultHostingSite(ctx);
return {
contents: [
{
uri,
type: "text",
text: `
### Configure Firebase Hosting
Default hosting site for ${ctx.projectId}: ${defaultHostingSite || "Does not exist"}
If there is not default hosting site configure, ask the user what the site ID should be, and suggest ${ctx.projectId} as a good choice.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super duper nit: "configured"

Next, use the 'firebase_init' tool to set up hosting. Below is an example of what the arguments to do so look like;
however, you should change the values to match the user's choices and project structure:
{
features: {
hosting: {
site_id: ${ctx.projectId},
public_directory: public,
}
}
}

**Security Warning:**
- 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.

**When to Deploy:**
- Introduce Firebase Hosting when developers are ready to deploy their application to production.
- Alternative: Developers can deploy later using the \`/firebase:deploy\` command.

**Deployment Process:**
- Request developer's permission before implementing Firebase Hosting
- Request developer's permission before deploying Firebase Hosting app to production.
- Configure Firebase Hosting and deploy the application to production
`.trim(),
},
],
Expand Down
33 changes: 33 additions & 0 deletions src/mcp/tools/core/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,31 @@ export const init = tool(
})
.optional()
.describe("Enable Firebase AI Logic feature for existing app"),
hosting: z
.object({
site_id: z
.string()
.optional()
.describe(
"The ID of the hosting site to configure. If omitted and there is a default hosting site, that will be used.",
),
public_directory: z
.string()
.optional()
.default("public")
.describe(
"The directory containing public files that will be served. If using a build tool, this likely should be the output directory of that tool.",
),
single_page_app: z
.boolean()
.optional()
.default(false)
.describe("Configure as a single-page app."),
})
.optional()
.describe(
"Provide this object to initialize Firebase Hosting in this project directory.",
),
}),
}),
annotations: {
Expand Down Expand Up @@ -219,6 +244,14 @@ export const init = tool(
displayName: appData.displayName,
};
}
if (features.hosting) {
featuresList.push("hosting");
featureInfo.hosting = {
newSiteId: features.hosting.site_id,
public: features.hosting.public_directory,
spa: features.hosting.single_page_app,
};
}
const setup: Setup = {
config: config?.src,
rcfile: rc?.data,
Expand Down
Loading