Skip to content

Commit 8b76c67

Browse files
authored
Add MCP init prompt for Firestore and AI Logic (#9177)
1 parent 9e27ded commit 8b76c67

File tree

7 files changed

+242
-16
lines changed

7 files changed

+242
-16
lines changed

src/mcp/prompts/core/init.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,16 @@ ${prompt || "<the user didn't supply specific instructions>"}
5555
Follow the steps below taking note of any user instructions provided above.
5656
5757
1. If there is no active user, use the \`firebase_login\` tool to help them sign in.
58-
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.
59-
3. Read the guide for the appropriate services and follow the instructions. If no guides match the user's need, inform the user.
58+
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
59+
- If they would like to create a project, use the firebase_create_project with the project ID
60+
- If they would like to use an existing project, run the shell command \`firebase use <project-id>\`
61+
3. Initialize the Firebase SDK
62+
- Fetch the active configuration via \`firebase_list_apps\` and then \`firebase_get_sdk_config\`
63+
- 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\`
64+
- Write the Firebase SDK config to a file
65+
- Initialize the Firebase SDK for the appropriate platform
66+
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.
67+
5. Read the guide for the appropriate services and follow the instructions. If no guides match the user's need, inform the user.
6068
6169
## Available Services
6270

src/mcp/resources/guides/init_ai.ts

Lines changed: 121 additions & 1 deletion
Large diffs are not rendered by default.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { resource } from "../../resource";
2+
3+
export const init_auth = resource(
4+
{
5+
uri: "firebase://guides/init/auth",
6+
name: "auth_init_guide",
7+
title: "Firebase Authentication Init Guide",
8+
description:
9+
"guides the coding agent through configuring Firebase Authentication in the current project",
10+
},
11+
async (uri) => {
12+
return {
13+
contents: [
14+
{
15+
uri,
16+
type: "text",
17+
text: `
18+
### Configure Firebase Authentication
19+
20+
- **Permission Required**: Request developer permission before implementing authentication features
21+
- **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.
22+
- **Implementation**: Create sign-up and login pages using Firebase Authentication.
23+
- **Security Rules**: Update Firestore security rules to ensure only authenticated users can access their own data
24+
- **Testing**: Recommend developers test the complete sign-up and sign-in flow to verify authentication functionality
25+
- **Next Steps**: Recommend deploying the application to production once authentication is verified and working properly
26+
`.trim(),
27+
},
28+
],
29+
};
30+
},
31+
);

src/mcp/resources/guides/init_backend.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,41 @@ export const init_backend = resource(
1515
uri,
1616
type: "text",
1717
text: `
18+
1819
1. Determine based on what you already know about the user's project or by asking them which of the following services is appropriate.
1920
2. Use the Firebase \`read_resources\` tool to load the guide to setup the product you choose.
2021
21-
## Available Services
22+
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.
23+
1. [Firestore](firebase://guides/init/firestore): read this to setup Firestore database
24+
2. [Authentication](firebase://guides/init/auth): read this to setup Firebase Authentication to support multi-user apps
25+
3. [Hosting](firebase://guides/init/hosting): read this if the user would like to deploy to Firebase Hosting
26+
27+
**firebase.json**
28+
The firebase.json file is used to deploy assets with the Firebase CLI. It contains configuration for firestore, hosting, and functions.
2229
23-
- [Firestore](firebase://guides/init/firestore): read this if the user needs offline data or a mix of querying and realtime capabilities
24-
- [Realtime Database](firebase://guides/init/rtdb): read this if the user is building a "multiplayer" app or game such as a collaborative whiteboard
25-
- [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
30+
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)
31+
\`\`\`json
32+
{
33+
"hosting": {
34+
"public": "public",
35+
"ignore": [
36+
"firebase.json",
37+
"**/.*",
38+
"**/node_modules/**"
39+
]
40+
},
41+
"firestore": {
42+
"rules": "firestore.rules",
43+
"indexes": "firestore.indexes.json"
44+
},
45+
"functions": {
46+
"predeploy": [
47+
"npm --prefix "$RESOURCE_DIR" run lint",
48+
"npm --prefix "$RESOURCE_DIR" run build"
49+
]
50+
}
51+
}
52+
\`\`\`
2653
`.trim(),
2754
},
2855
],

src/mcp/resources/guides/init_firestore.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ export const init_firestore = resource(
1414
uri,
1515
type: "text",
1616
text: `
17-
Create a file called \`firestore.ts\`:
17+
### Setup Firestore Database
1818
19-
\`\`\`ts
20-
import { initializeApp } from "firebase/app";
21-
import { getFirestore } from "firebase/firestore";
22-
23-
const app = initializeApp({...});
24-
const db = getFirestore(app);
25-
\`\`\`
19+
- Set up Firebase Firestore as the primary database for the application
20+
- Implement client code for basic CRUD operations for the application
21+
- **Important**: Use the \`firebase deploy\` command to provision the database automatically. **Do not ask developers to go to the console to do it**.
22+
- **Environment**: Use production environment directly - avoid emulator for initial setup
23+
- **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.
24+
- **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.
25+
- **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.
26+
- **Security Warning**: Alert developers against making Firestore security rules public (allowing read/write without authentication)
2627
`.trim(),
2728
},
2829
],
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { resource } from "../../resource";
2+
3+
export const init_hosting = resource(
4+
{
5+
uri: "firebase://guides/init/hosting",
6+
name: "hosting_init_guide",
7+
title: "Firebase Hosting Deployment Guide",
8+
description:
9+
"guides the coding agent through deploying to Firebase Hosting in the current project",
10+
},
11+
async (uri) => {
12+
return {
13+
contents: [
14+
{
15+
uri,
16+
type: "text",
17+
text: `
18+
### Configure Firebase Hosting
19+
20+
- Introduce Firebase Hosting when developers are ready to deploy their application to production
21+
- **Alternative**: Developers can deploy later using the \`/deploy\` command
22+
- **Permission Required**: Request developer permission before implementing Firebase Hosting
23+
- **Deployment**: Configure Firebase Hosting and deploy the application to production
24+
`.trim(),
25+
},
26+
],
27+
};
28+
},
29+
);

src/mcp/resources/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import { init_ai } from "./guides/init_ai";
2+
import { init_auth } from "./guides/init_auth";
23
import { init_backend } from "./guides/init_backend";
34
import { init_data_connect } from "./guides/init_data_connect";
45
import { init_firestore } from "./guides/init_firestore";
6+
import { init_hosting } from "./guides/init_hosting";
57
import { init_rtdb } from "./guides/init_rtdb";
68

7-
export const resources = [init_backend, init_ai, init_data_connect, init_firestore, init_rtdb];
9+
export const resources = [
10+
init_backend,
11+
init_ai,
12+
init_data_connect,
13+
init_firestore,
14+
init_rtdb,
15+
init_auth,
16+
init_hosting,
17+
];

0 commit comments

Comments
 (0)