Skip to content

Commit b00393c

Browse files
authored
fix(mcp): check project dir exists (#8607)
1 parent bdf399f commit b00393c

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/mcp/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { trackGA4 } from "../track.js";
2121
import { Config } from "../config.js";
2222
import { loadRC } from "../rc.js";
2323
import { EmulatorHubClient } from "../emulator/hubClient.js";
24+
import { existsSync } from "node:fs";
2425

2526
const SERVER_VERSION = "0.0.1";
2627

@@ -185,9 +186,13 @@ export class FirebaseMcpServer {
185186

186187
const projectId = await this.getProjectId();
187188
const accountEmail = await this.getAuthenticatedUser();
188-
if (!this.cachedProjectRoot) {
189-
return mcpError("No project root set. Please set the project root before calling tools.");
190-
}
189+
if (
190+
tool.mcp.name !== "firebase_update_environment" && // allow this tool only, to fix the issue
191+
(!this.cachedProjectRoot || !existsSync(this.cachedProjectRoot))
192+
)
193+
return mcpError(
194+
`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.`,
195+
);
191196
if (tool.mcp._meta?.requiresAuth && !accountEmail) return mcpAuthError();
192197
if (tool.mcp._meta?.requiresProject && !projectId) return NO_PROJECT_ERROR;
193198

src/mcp/tools/core/update_environment.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { z } from "zod";
22
import { tool } from "../../tool.js";
3-
import { toContent } from "../../util.js";
3+
import { mcpError, toContent } from "../../util.js";
44
import { setNewActive } from "../../../commands/use.js";
55
import { assertAccount, setProjectAccount } from "../../../auth.js";
6+
import { existsSync } from "node:fs";
67

78
export const update_environment = tool(
89
{
@@ -41,6 +42,10 @@ export const update_environment = tool(
4142
async ({ project_dir, active_project, active_user_account }, { config, rc, host }) => {
4243
let output = "";
4344
if (project_dir) {
45+
if (!existsSync(project_dir))
46+
return mcpError(
47+
`Cannot update project directory to '${project_dir}' as it does not exist.`,
48+
);
4449
host.setProjectRoot(project_dir);
4550
output += `- Updated project directory to '${project_dir}'\n`;
4651
}

0 commit comments

Comments
 (0)