Skip to content

Commit d965588

Browse files
authored
[MCP] [Cleanup] Declare project ID a required string with default if missing (#8646)
1 parent f56d79a commit d965588

34 files changed

+52
-48
lines changed

src/mcp/index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,24 @@ export class FirebaseMcpServer {
184184
const tool = this.getTool(toolName);
185185
if (!tool) throw new Error(`Tool '${toolName}' could not be found.`);
186186

187-
const projectId = await this.getProjectId();
188-
const accountEmail = await this.getAuthenticatedUser();
189187
if (
190188
tool.mcp.name !== "firebase_update_environment" && // allow this tool only, to fix the issue
191189
(!this.cachedProjectRoot || !existsSync(this.cachedProjectRoot))
192-
)
190+
) {
193191
return mcpError(
194192
`The current project directory '${this.cachedProjectRoot || "<NO PROJECT DIRECTORY FOUND>"}' does not exist. Please use the 'update_firebase_environment' tool to target a different project directory.`,
195193
);
196-
if (tool.mcp._meta?.requiresAuth && !accountEmail) return mcpAuthError();
197-
if (tool.mcp._meta?.requiresProject && !projectId) return NO_PROJECT_ERROR;
194+
}
195+
let projectId = await this.getProjectId();
196+
if (tool.mcp._meta?.requiresProject && !projectId) {
197+
return NO_PROJECT_ERROR;
198+
}
199+
projectId = projectId || "";
200+
201+
const accountEmail = await this.getAuthenticatedUser();
202+
if (tool.mcp._meta?.requiresAuth && !accountEmail) {
203+
return mcpAuthError();
204+
}
198205

199206
const options = { projectDir: this.cachedProjectRoot, cwd: this.cachedProjectRoot };
200207
const toolsCtx: ServerToolContext = {

src/mcp/tool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { RC } from "../rc";
77
import { cleanSchema } from "./util";
88

99
export interface ServerToolContext {
10-
projectId?: string;
11-
accountEmail?: string | null;
10+
projectId: string;
11+
accountEmail: string | null;
1212
config: Config;
1313
host: FirebaseMcpServer;
1414
rc: RC;

src/mcp/tools/apphosting/fetch_logs.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export const fetch_logs = tool(
3636
},
3737
},
3838
async ({ buildLogs, backendId, location } = {}, { projectId }) => {
39-
projectId ||= "";
4039
location ||= "";
4140
if (!backendId) {
4241
return toContent(`backendId must be specified.`);

src/mcp/tools/auth/disable_user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const disable_user = tool(
2222
},
2323
},
2424
async ({ uid, disabled }, { projectId }) => {
25-
const res = await disableUser(projectId!, uid, disabled);
25+
const res = await disableUser(projectId, uid, disabled);
2626
if (res) {
2727
return toContent(`User ${uid} as been ${disabled ? "disabled" : "enabled"}`);
2828
}

src/mcp/tools/auth/get_user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ export const get_user = tool(
3838
if (email === undefined && phone_number === undefined && uid === undefined) {
3939
return mcpError(`No user identifier supplied in auth_get_user tool`);
4040
}
41-
return toContent(await findUser(projectId!, email, phone_number, uid));
41+
return toContent(await findUser(projectId, email, phone_number, uid));
4242
},
4343
);

src/mcp/tools/auth/list_users.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const list_users = tool(
2828
limit = 100;
2929
}
3030

31-
const users = await listUsers(projectId!, limit);
31+
const users = await listUsers(projectId, limit);
3232
const usersPruned = users.map((user) => {
3333
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3434
const { passwordHash, salt, ...prunedUser } = user;

src/mcp/tools/auth/set_claims.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ export const set_claim = tool(
4242
return mcpError(`Provided \`json_value\` was not valid JSON: ${json_value}`);
4343
}
4444
}
45-
return toContent(await setCustomClaim(projectId!, uid, { [claim]: value }, { merge: true }));
45+
return toContent(await setCustomClaim(projectId, uid, { [claim]: value }, { merge: true }));
4646
},
4747
);

src/mcp/tools/auth/set_sms_region_policy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export const set_sms_region_policy = tool(
3333
return code.toUpperCase();
3434
});
3535
if (policy_type === "ALLOW") {
36-
return toContent(await setAllowSmsRegionPolicy(projectId!, country_codes));
36+
return toContent(await setAllowSmsRegionPolicy(projectId, country_codes));
3737
}
38-
return toContent(await setDenySmsRegionPolicy(projectId!, country_codes));
38+
return toContent(await setDenySmsRegionPolicy(projectId, country_codes));
3939
},
4040
);

src/mcp/tools/core/consult_assistant.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const consult_assistant = tool(
2424
},
2525
},
2626
async ({ prompt }, { projectId }) => {
27-
const schema = await chatWithFirebase(prompt, projectId!);
27+
const schema = await chatWithFirebase(prompt, projectId);
2828
return toContent(schema);
2929
},
3030
);

src/mcp/tools/core/create_android_sha.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const create_android_sha = tool(
3535
async ({ app_id, sha_hash }, { projectId }) => {
3636
// Add the SHA certificate
3737
const certType = getCertHashType(sha_hash);
38-
const shaCertificate = await createAppAndroidSha(projectId!, app_id, {
38+
const shaCertificate = await createAppAndroidSha(projectId, app_id, {
3939
shaHash: sha_hash,
4040
certType,
4141
});

0 commit comments

Comments
 (0)