Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 10 additions & 2 deletions src/mcp/prompts/core/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
Contents of \`firebase.json\` config file:

\`\`\`json
${config.readProjectFile("firebase.json", { fallback: "<FILE DOES NOT EXIST>" })}

Check warning on line 46 in src/mcp/prompts/core/init.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "any" of template literal expression
\`\`\`

## User Instructions
Expand All @@ -55,8 +55,16 @@
Follow the steps below taking note of any user instructions provided above.

1. If there is no active user, use the \`firebase_login\` tool to help them sign in.
2. Determine which of the services listed below are the best match for the user's needs based on their instructions or by asking them.
3. Read the guide for the appropriate services and follow the instructions. If no guides match the user's need, inform the user.
2. If there is no active Firebase project, ask the user if they would like to create a project, or use an existing one, and ask them for the project ID
- If they would like to create a project, use the firebase_create_project with the project ID
- If they would like to use an existing project, run the shell command \`firebase use <project-id>\`
3. Initialize the Firebase SDK
- Fetch the active configuration via \`firebase_list_apps\` and then \`firebase_get_sdk_config\`
- If there isn't an app that matches the current platform, use the \`firebase_create_app\` tool to create the app with the appropriate platform, and then run \`firebase_get_sdk_config\`
- Write the Firebase SDK config to a file
- Initialize the Firebase SDK for the appropriate platform
4. Determine which of the services listed below are the best match for the user's needs based on their instructions or by asking them.
5. Read the guide for the appropriate services and follow the instructions. If no guides match the user's need, inform the user.

## Available Services

Expand Down
122 changes: 121 additions & 1 deletion src/mcp/resources/guides/init_ai.ts

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions src/mcp/resources/guides/init_auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { resource } from "../../resource";

export const init_auth = resource(
{
uri: "firebase://guides/init/auth",
name: "auth_init_guide",
title: "Firebase Authentication Init Guide",
description:
"guides the coding agent through configuring Firebase Authentication in the current project",
},
async (uri) => {
return {
contents: [
{
uri,
type: "text",
text: `
### Configure Firebase Authentication

- **Permission Required**: Request developer permission before implementing authentication features
- **Provider Setup**: Guide developers to enable authentication providers (Email/Password, Google Sign-in, etc.) in the [Firebase Auth Console](https://console.firebase.google.com/). Ask developers to confirm which authentication method they selected before proceeding to implementation.
- **Implementation**: Create sign-up and login pages using Firebase Authentication.
- **Security Rules**: Update Firestore security rules to ensure only authenticated users can access their own data
- **Testing**: Recommend developers test the complete sign-up and sign-in flow to verify authentication functionality
- **Next Steps**: Recommend deploying the application to production once authentication is verified and working properly
`.trim(),
},
],
};
},
);
35 changes: 31 additions & 4 deletions src/mcp/resources/guides/init_backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,41 @@ export const init_backend = resource(
uri,
type: "text",
text: `

1. Determine based on what you already know about the user's project or by asking them which of the following services is appropriate.
2. Use the Firebase \`read_resources\` tool to load the guide to setup the product you choose.

## Available Services
The user will likely need to setup Firestore, Authentication, and Hosting. Read the following guides in order. Do not run the app until you have completed all 3 guides.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nonblocking thing to test: should this instead tell the AI to run the init MCP tool with Firestore, Auth, and Hosting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooh hadn't seen that tool - let me check that out in a follow up

1. [Firestore](firebase://guides/init/firestore): read this to setup Firestore database
2. [Authentication](firebase://guides/init/auth): read this to setup Firebase Authentication to support multi-user apps
3. [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 assets with the Firebase CLI. It contains configuration for firestore, hosting, and functions.

- [Firestore](firebase://guides/init/firestore): read this if the user needs offline data or a mix of querying and realtime capabilities
- [Realtime Database](firebase://guides/init/rtdb): read this if the user is building a "multiplayer" app or game such as a collaborative whiteboard
- [Data Connect - PostgreSQL](firebase://guides/init/data-connect): read this if the user needs robust relational querying capabilities or expressly indicates interest in a SQL database
Here is an example firebase.json file with all 3 services. 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"
]
}
}
\`\`\`
`.trim(),
},
],
Expand Down
17 changes: 9 additions & 8 deletions src/mcp/resources/guides/init_firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ export const init_firestore = resource(
uri,
type: "text",
text: `
Create a file called \`firestore.ts\`:
### Setup Firestore Database

\`\`\`ts
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";

const app = initializeApp({...});
const db = getFirestore(app);
\`\`\`
- Set up Firebase Firestore as the primary database for the application
- Implement client code for basic CRUD operations for the application
- **Important**: Use the \`firebase deploy\` command to provision the database automatically. **Do not ask developers to go to the console to do it**.
- **Environment**: Use production environment directly - avoid emulator for initial setup
- **Verification**: Guide developers to verify database creation at the [Firebase Console](https://console.firebase.google.com/) by clicking on the "Firestore Database" tab in the left navigation to confirm the database is created.
- **Testing**: Recommend developers test their application and verify data appears correctly in the console. Ask developers to confirm they can see their test data in the console before proceeding to the next step.
- **Security**: Recommend implementing authentication if the application handles sensitive user data. Guide users to navigate to the "Firestore Database" section and click on the "Rules" tab to view and configure their security rules.
- **Security Warning**: Alert developers against making Firestore security rules public (allowing read/write without authentication)
Copy link
Contributor

Choose a reason for hiding this comment

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

Note for later: there's a really thorough prompt in studio about how to make secure rules - we might want to pull that into here as another guide, and link the AI to it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'm hoping to bring that in and add a bunch more rules tooling soon

`.trim(),
},
],
Expand Down
29 changes: 29 additions & 0 deletions src/mcp/resources/guides/init_hosting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { resource } from "../../resource";

export const init_hosting = resource(
{
uri: "firebase://guides/init/hosting",
name: "hosting_init_guide",
title: "Firebase Hosting Deployment Guide",
description:
"guides the coding agent through deploying to Firebase Hosting in the current project",
},
async (uri) => {
return {
contents: [
{
uri,
type: "text",
text: `
### Configure Firebase Hosting
- Introduce Firebase Hosting when developers are ready to deploy their application to production
- **Alternative**: Developers can deploy later using the \`/deploy\` command
- **Permission Required**: Request developer permission before implementing Firebase Hosting
- **Deployment**: Configure Firebase Hosting and deploy the application to production
Copy link
Contributor

Choose a reason for hiding this comment

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

Nonblocking note for later - does this actually work? Seems like we'd want more explicit instructions on how to do this...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was my thought too. We're starting with Charlotte's prompts for now, but we'll likely iterate on this. Surprisingly this works decently well

`.trim(),
},
],
};
},
);
12 changes: 11 additions & 1 deletion src/mcp/resources/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { init_ai } from "./guides/init_ai";
import { init_auth } from "./guides/init_auth";
import { init_backend } from "./guides/init_backend";
import { init_data_connect } from "./guides/init_data_connect";
import { init_firestore } from "./guides/init_firestore";
import { init_hosting } from "./guides/init_hosting";
import { init_rtdb } from "./guides/init_rtdb";

export const resources = [init_backend, init_ai, init_data_connect, init_firestore, init_rtdb];
export const resources = [
init_backend,
init_ai,
init_data_connect,
init_firestore,
init_rtdb,
init_auth,
init_hosting,
];
Loading