Skip to content

Commit 9ded6d7

Browse files
committed
feat(mcp): Adds "get_environment" tool
1 parent d26423e commit 9ded6d7

File tree

4 files changed

+58
-6
lines changed

4 files changed

+58
-6
lines changed

src/mcp/index.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,11 @@ export class FirebaseMcpServer {
9797
return getProjectId(await this.resolveOptions());
9898
}
9999

100-
async getAuthenticated(): Promise<boolean> {
100+
async getAuthenticated(): Promise<string | null> {
101101
try {
102-
await requireAuth(await this.resolveOptions());
103-
return true;
102+
return (await requireAuth(await this.resolveOptions())) ?? null;
104103
} catch (e) {
105-
return false;
104+
return null;
106105
}
107106
}
108107

@@ -115,7 +114,7 @@ export class FirebaseMcpServer {
115114
_meta: {
116115
projectRoot: this.projectRoot,
117116
projectDetected: hasActiveProject,
118-
authenticated: await this.getAuthenticated(),
117+
authenticatedUser: await this.getAuthenticated(),
119118
activeFeatures: this.activeFeatures,
120119
detectedFeatures: this.detectedFeatures,
121120
},
@@ -129,7 +128,8 @@ export class FirebaseMcpServer {
129128
if (!tool) throw new Error(`Tool '${toolName}' could not be found.`);
130129

131130
const projectId = await this.getProjectId();
132-
if (tool.mcp._meta?.requiresAuth && !(await this.getAuthenticated())) return mcpAuthError();
131+
const accountEmail = await this.getAuthenticated();
132+
if (tool.mcp._meta?.requiresAuth && !accountEmail) return mcpAuthError();
133133
if (tool.mcp._meta?.requiresProject && !projectId) return NO_PROJECT_ERROR;
134134

135135
try {
@@ -141,6 +141,7 @@ export class FirebaseMcpServer {
141141
host: this,
142142
config,
143143
rc,
144+
accountEmail,
144145
});
145146
await trackGA4("mcp_tool_call", { tool_name: toolName, error: res.isError ? 1 : 0 });
146147
return res;

src/mcp/tool.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { RC } from "../rc";
77

88
export interface ServerToolContext {
99
projectId?: string;
10+
accountEmail?: string | null;
1011
config: Config;
1112
host: FirebaseMcpServer;
1213
rc: RC;

src/mcp/tools/core/get_environment.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { z } from "zod";
2+
import { tool } from "../../tool.js";
3+
import { toContent } from "../../util.js";
4+
import { getAliases } from "../../../projectUtils.js";
5+
import { dump } from "js-yaml";
6+
import { getAllAccounts } from "../../../auth.js";
7+
8+
export const get_environment = tool(
9+
{
10+
name: "get_environment",
11+
description:
12+
"Retrieves information about the current Firebase environment including current user, project directory, active project, and more.",
13+
inputSchema: z.object({}),
14+
annotations: {
15+
title: "Get Firebase Environment Info",
16+
readOnlyHint: true,
17+
},
18+
_meta: {
19+
requiresAuth: false,
20+
requiresProject: false,
21+
},
22+
},
23+
async (_, { projectId, host, accountEmail, rc, config }) => {
24+
const aliases = projectId ? getAliases({ rc }, projectId) : [];
25+
return toContent(`# Environment Information
26+
27+
Project Directory: ${host.projectRoot}${host.fixedRoot ? " (immutable - set via startup flag)" : ""}
28+
Project Config Path: ${config.path("firebase.json")}
29+
Active Project ID: ${
30+
projectId ? `${projectId}${aliases.length ? ` (alias: ${aliases.join(",")})` : ""}` : "<NONE>"
31+
}
32+
Authenticated User: ${accountEmail || "<NONE>"}
33+
34+
# Available Project Aliases (format: '[alias]: [projectId]')
35+
36+
${dump(rc.projects).trim()}
37+
38+
# Available Accounts:
39+
40+
${dump(getAllAccounts().map((account) => account.user.email)).trim()}
41+
42+
# firebase.json contents:
43+
44+
\`\`\`json
45+
${config.readProjectFile("firebase.json")}
46+
\`\`\``);
47+
},
48+
);

src/mcp/tools/core/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import { get_project } from "./get_project.js";
55
import { use_project } from "./use_project.js";
66
import { get_sdk_config } from "./get_sdk_config.js";
77
import { list_apps } from "./list_apps.js";
8+
import { get_environment } from "./get_environment.js";
89

910
export const coreTools: ServerTool[] = [
1011
get_project,
1112
use_project,
1213
list_apps,
1314
get_sdk_config,
1415
consult_assistant,
16+
// get_environment, // leaving commented out for the moment
1517
];

0 commit comments

Comments
 (0)