Skip to content

Commit 284ad53

Browse files
authored
[MCP] Organize MCP tools && update README (#8523)
1 parent 4ae9b6c commit 284ad53

13 files changed

+65
-46
lines changed

src/mcp/README.md

+22-8
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,29 @@ In `.cursor/mcp.json` in your workspace directory, add the Firebase MCP server:
2929

3030
### Command Line Options
3131

32-
- `--dir <absolute_dir_path>`: The absolute path of a directory containing `firebase.json` to set a project context for the MCP server. If unspecified, the `{get|set}_firebase_directory` tools will become available and the default directory will be the working directory where the MCP server was started.
32+
- `--dir <absolute_dir_path>`: The absolute path of a directory containing `firebase.json` to set a project context for the MCP server. If unspecified, the `{get|set}_project_directory` tools will become available and the default directory will be the working directory where the MCP server was started.
3333
- `--only <feature1,feature2>`: A comma-separated list of feature groups to activate. Use this to limit the tools exposed to only features you are actively using.
3434

3535
## Tools
3636

37-
| Tool Name | Feature Group | Description |
38-
| ------------------------ | ------------- | ------------------------------------------------------------------------------------------------------------------- |
39-
| `get_firebase_directory` | `core` | When running without the `--dir` command, retrieves the current directory (defaults to current working directory). |
40-
| `set_firebase_directory` | `core` | When running without the `--dir` command, sets the current project directory (i.e. one with `firebase.json` in it). |
41-
| `get_project` | `project` | Get basic information about the active project in the current Firebase directory. |
42-
| `list_apps` | `project` | List registered apps for the currently active project. |
43-
| `get_sdk_config` | `project` | Get an Firebase client SDK config for a specific platform. |
37+
| Tool Name | Feature Group | Description |
38+
| -------------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
39+
| `get_project_directory` | `directory` | When running without the `--dir` command, retrieves the current directory (defaults to current working directory). |
40+
| `set_project_directory` | `directory` | When running without the `--dir` command, sets the current project directory (i.e. one with `firebase.json` in it). |
41+
| `firebase_get_project` | `core` | Get basic information about the active project in the current Firebase directory. |
42+
| `firebase_list_apps` | `core` | List registered apps for the currently active project. |
43+
| `firebase_get_sdk_config` | `core` | Get an Firebase client SDK config for a specific platform. |
44+
| `firebase_consult_assistant` | `core` | Consult Gemini in Firebase agent for help |
45+
| `firestore_list_collections` | `firestore` | Retrieves a list of collections from a Firestore database in the current project. |
46+
| `firestore_get_documents` | `firestore` | Retrieves one or more Firestore documents from a database in the current project by full document paths. Use this if you know the exact path of a document. |
47+
| `firestore_get_rules` | `firestore` | Retrieves the active Firestore security rules for the current project. |
48+
| `auth_get_user` | `auth` | Retrieves a user based on an email address, phone number, or UID. |
49+
| `auth_disable_user` | `auth` | Disables or enables a user based on a UID. |
50+
| `auth_set_claims` | `auth` | Sets custom claims on a specific user's account. Use to create trusted values associated with a user e.g. marking them as an admin. Claims are limited in size and should be succinct in name and value. |
51+
| `auth_set_sms_region_policy` | `auth` | Sets an SMS Region Policy for Firebase Auth to restrict the regions which can receive text messages based on an ALLOW or DENY list of country codes. This policy will override any existing policies when set. |
52+
| `dataconnect_list_services` | `dataconnect` | List the Firebase Data Connect services available in the current project. |
53+
| `dataconnect_generate_schema` | `dataconnect` | Generates a Firebase Data Connect Schema based on the users description of an app. |
54+
| `dataconnect_generate_operation` | `dataconnect` | Generates a single Firebase Data Connect query or mutation based on the currently deployed schema and the provided prompt. |
55+
| `dataconnect_get_schema` | `dataconnect` | List the Firebase Data Connect Schema in the project, which includes Cloud SQL data sources and the GraphQL Schema describing what tables are available. |
56+
| `dataconnect_get_connector` | `dataconnect` | Get the Firebase Data Connect Connectors in the project, which includes the pre-defined GraphQL queries accessible to client SDKs. |
57+
| `storage_get_rules` | `storage` | Retrieves the Firebase Cloud Storage Rules for the default bucket. |

src/mcp/index.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ import {
99
} from "@modelcontextprotocol/sdk/types.js";
1010
import { mcpError } from "./util.js";
1111
import { ServerFeature } from "./types.js";
12-
import { tools } from "./tools/index.js";
12+
import { availableTools } from "./tools/index.js";
1313
import { ServerTool } from "./tool.js";
1414
import { configstore } from "../configstore.js";
15-
import { coreTools } from "./tools/core/index.js";
1615
import { Command } from "../command.js";
1716
import { requireAuth } from "../requireAuth.js";
1817
import { Options } from "../options.js";
@@ -47,14 +46,7 @@ export class FirebaseMcpServer {
4746
}
4847

4948
get availableTools(): ServerTool[] {
50-
const toolDefs: ServerTool[] = this.fixedRoot ? [] : [...coreTools];
51-
const activeFeatures = this.activeFeatures?.length
52-
? this.activeFeatures
53-
: (Object.keys(tools) as ServerFeature[]);
54-
for (const key of activeFeatures || []) {
55-
toolDefs.push(...tools[key]);
56-
}
57-
return toolDefs;
49+
return availableTools(!!this.fixedRoot, this.activeFeatures);
5850
}
5951

6052
getTool(name: string): ServerTool | null {

src/mcp/tools/core/consult_firebase_assistant.ts renamed to src/mcp/tools/core/consult_assistant.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { tool } from "../../tool.js";
33
import { toContent } from "../../util.js";
44
import { chatWithFirebase } from "../../../gif/fdcExperience.js";
55

6-
export const consult_firebase_assistant = tool(
6+
export const consult_assistant = tool(
77
{
8-
name: "consult_firebase_assistant",
8+
name: "consult_assistant",
99
description:
1010
"Send a question to an AI assistant specifically enhanced to answer Firebase questions.",
1111
inputSchema: z.object({
@@ -20,7 +20,7 @@ export const consult_firebase_assistant = tool(
2020
_meta: {
2121
requiresProject: true,
2222
requiresAuth: true,
23-
// TODO: Create an endpoint to check for GiF activiation.
23+
// TODO: Create an endpoint to check for GiF activation.
2424
},
2525
},
2626
async ({ prompt }, { projectId }) => {

src/mcp/tools/core/index.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { consult_firebase_assistant } from "./consult_firebase_assistant";
2-
import { get_firebase_directory } from "./get_firebase_directory";
3-
import { set_firebase_directory } from "./set_firebase_directory";
1+
import type { ServerTool } from "../../tool.js";
42

5-
export const coreTools = [
6-
get_firebase_directory,
7-
set_firebase_directory,
8-
consult_firebase_assistant,
9-
];
3+
import { consult_assistant } from "./consult_assistant.js";
4+
import { get_project } from "./get_project.js";
5+
import { get_sdk_config } from "./get_sdk_config.js";
6+
import { list_apps } from "./list_apps.js";
7+
8+
export const coreTools: ServerTool[] = [get_project, list_apps, get_sdk_config, consult_assistant];
File renamed without changes.

src/mcp/tools/core/get_firebase_directory.ts renamed to src/mcp/tools/directory/get_project_directory.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { tool } from "../../tool.js";
33
import { mcpError, toContent } from "../../util.js";
44
import { detectProjectRoot } from "../../../detectProjectRoot.js";
55

6-
export const get_firebase_directory = tool(
6+
export const get_project_directory = tool(
77
{
8-
name: "get_firebase_directory",
8+
name: "get_project_directory",
99
description:
10-
"Gets the current Firebase project directory. If this has been set using the `set_firebase_directory` tool it will return that, otherwise it will look for a PROJECT_ROOT environment variable or the current working directory of the running Firebase MCP server.",
10+
"Gets the current Firebase project directory. If this has been set using the `set_project_directory` tool it will return that, otherwise it will look for a PROJECT_ROOT environment variable or the current working directory of the running Firebase MCP server.",
1111
inputSchema: z.object({}),
1212
annotations: {
1313
title: "Get Firebase Project Directory",
@@ -18,7 +18,7 @@ export const get_firebase_directory = tool(
1818
if (!detectProjectRoot({ cwd: host.projectRoot }))
1919
return Promise.resolve(
2020
mcpError(
21-
`There is no detected 'firebase.json' in directory '${host.projectRoot}'. Please use the 'set_firebase_directory' tool to activate a Firebase project directory.`,
21+
`There is no detected 'firebase.json' in directory '${host.projectRoot}'. Please use the 'set_project_directory' tool to activate a Firebase project directory.`,
2222
),
2323
);
2424
return Promise.resolve(

src/mcp/tools/directory/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { get_project_directory } from "./get_project_directory";
2+
import { set_project_directory } from "./set_project_directory";
3+
4+
export const directoryTools = [get_project_directory, set_project_directory];

src/mcp/tools/core/set_firebase_directory.ts renamed to src/mcp/tools/directory/set_project_directory.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { mcpError, toContent } from "../../util.js";
44
import { existsSync } from "fs";
55
import { join } from "path";
66

7-
export const set_firebase_directory = tool(
7+
export const set_project_directory = tool(
88
{
9-
name: "set_firebase_directory",
9+
name: "set_project_directory",
1010
description:
1111
"Sets the project directory for the Firebase MCP server to utilize for project detection and authentication. This should be a directory with a `firebase.json` file in it. This information is persisted between sessions.",
1212
inputSchema: z.object({

src/mcp/tools/index.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,28 @@ import { ServerFeature } from "../types.js";
33
import { authTools } from "./auth/index.js";
44
import { dataconnectTools } from "./dataconnect/index.js";
55
import { firestoreTools } from "./firestore/index.js";
6-
import { projectTools } from "./project/index.js";
6+
import { directoryTools } from "./directory/index.js";
7+
import { coreTools } from "./core/index.js";
78
import { storageTools } from "./storage/index.js";
89

9-
export const tools: Record<ServerFeature, ServerTool[]> = {
10-
project: projectTools,
10+
/** availableTools returns the list of MCP tools available given the server flags */
11+
export function availableTools(fixedRoot: boolean, activeFeatures?: ServerFeature[]): ServerTool[] {
12+
// Core tools are always present.
13+
const toolDefs: ServerTool[] = addPrefixToToolName("firebase_", coreTools);
14+
if (!fixedRoot) {
15+
// Present if the root is not fixed.
16+
toolDefs.push(...directoryTools);
17+
}
18+
if (!activeFeatures || !activeFeatures.length) {
19+
activeFeatures = Object.keys(tools) as ServerFeature[];
20+
}
21+
for (const key of activeFeatures) {
22+
toolDefs.push(...tools[key]);
23+
}
24+
return toolDefs;
25+
}
26+
27+
const tools: Record<ServerFeature, ServerTool[]> = {
1128
firestore: addPrefixToToolName("firestore_", firestoreTools),
1229
auth: addPrefixToToolName("auth_", authTools),
1330
dataconnect: addPrefixToToolName("dataconnect_", dataconnectTools),

src/mcp/tools/project/index.ts

-7
This file was deleted.

src/mcp/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export const SERVER_FEATURES = ["project", "firestore", "storage", "dataconnect", "auth"] as const;
1+
export const SERVER_FEATURES = ["firestore", "storage", "dataconnect", "auth"] as const;
22
export type ServerFeature = (typeof SERVER_FEATURES)[number];

0 commit comments

Comments
 (0)