From 2c770de5ddf2ddf74febeff9fd7aae8bed4f8fbd Mon Sep 17 00:00:00 2001 From: VishnuVardhanBR Date: Sun, 1 Mar 2026 21:37:47 -0500 Subject: [PATCH 1/2] fix(mcp): write firebase-debug.log to ~/.firebase/ instead of cwd When the Firebase MCP server starts, it calls useFileLogger() which writes firebase-debug.log to process.cwd(). This pollutes the user's project directory with an unrelated file, especially in projects that have no Firebase configuration. Write the MCP debug log to ~/.firebase/firebase-debug.log instead, creating the directory if needed. This matches the pattern of other Firebase tooling that uses ~/.firebase/ as a home for non-project data. Fixes #9982 --- CHANGELOG.md | 1 + src/bin/mcp.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a9de9e9842..d749ee51c2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,3 @@ +- Fixed MCP server writing `firebase-debug.log` to the user's project directory; logs now go to `~/.firebase/firebase-debug.log` instead. (#9982) - Updated the functions.config deprecation notice from March 2026 to March 2027 (#9941) - Detects when App Hosting fails to deploy, returning an error. (#8866) diff --git a/src/bin/mcp.ts b/src/bin/mcp.ts index 6ad168b1a7f..4f84df3a61d 100644 --- a/src/bin/mcp.ts +++ b/src/bin/mcp.ts @@ -1,6 +1,8 @@ #!/usr/bin/env node -import { resolve } from "path"; +import { resolve, join } from "path"; +import { mkdirSync } from "fs"; +import { homedir } from "os"; import { parseArgs } from "util"; import { useFileLogger } from "../logger"; import { FirebaseMcpServer } from "../mcp/index"; @@ -83,7 +85,11 @@ export async function mcp(): Promise { if (earlyExit) return; process.env.IS_FIREBASE_MCP = "true"; - useFileLogger(); + // Write debug logs to ~/.firebase/ to avoid polluting the user's project directory. + // See: https://github.com/firebase/firebase-tools/issues/9982 + const mcpLogDir = join(homedir(), ".firebase"); + mkdirSync(mcpLogDir, { recursive: true }); + useFileLogger(join(mcpLogDir, "firebase-debug.log")); const activeFeatures = (values.only || "") .split(",") .map((f) => f.trim()) From dbc38993bfafae74c721fb9ad4b20d6dab03cf30 Mon Sep 17 00:00:00 2001 From: VishnuVardhanBR Date: Sun, 1 Mar 2026 21:41:07 -0500 Subject: [PATCH 2/2] refactor(mcp): use async mkdir instead of mkdirSync Address code review feedback: use fs/promises mkdir with await instead of the synchronous mkdirSync, since mcp() is already async. This avoids blocking the event loop. --- src/bin/mcp.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/mcp.ts b/src/bin/mcp.ts index 4f84df3a61d..8ab12d94fab 100644 --- a/src/bin/mcp.ts +++ b/src/bin/mcp.ts @@ -1,7 +1,7 @@ #!/usr/bin/env node import { resolve, join } from "path"; -import { mkdirSync } from "fs"; +import { mkdir } from "fs/promises"; import { homedir } from "os"; import { parseArgs } from "util"; import { useFileLogger } from "../logger"; @@ -88,7 +88,7 @@ export async function mcp(): Promise { // Write debug logs to ~/.firebase/ to avoid polluting the user's project directory. // See: https://github.com/firebase/firebase-tools/issues/9982 const mcpLogDir = join(homedir(), ".firebase"); - mkdirSync(mcpLogDir, { recursive: true }); + await mkdir(mcpLogDir, { recursive: true }); useFileLogger(join(mcpLogDir, "firebase-debug.log")); const activeFeatures = (values.only || "") .split(",")