diff --git a/src/env.ts b/src/env.ts index 9589d9a59d7..440819e2e7b 100644 --- a/src/env.ts +++ b/src/env.ts @@ -10,11 +10,16 @@ export function isFirebaseStudio() { let isFirebaseMcpFlag = false; export function isFirebaseMcp() { - return isFirebaseMcpFlag; + return isFirebaseMcpFlag || process.env.IS_FIREBASE_MCP === "true"; } export function setFirebaseMcp(value: boolean) { isFirebaseMcpFlag = value; + if (value) { + process.env.IS_FIREBASE_MCP = "true"; + } else { + delete process.env.IS_FIREBASE_MCP; + } } // Detect if the CLI was invoked by a coding agent, based on well-known env vars. @@ -22,8 +27,9 @@ export function setFirebaseMcp(value: boolean) { // See: https://github.com/vercel/vercel/tree/main/packages/detect-agent export function detectAIAgent(): string { // 1. Standardized standard - if (process.env.AI_AGENT) { - return process.env.AI_AGENT.trim(); + const aiAgent = process.env.AI_AGENT?.trim(); + if (aiAgent) { + return aiAgent; } // 2. Specific agents (ordered as requested) diff --git a/src/mcp/index.ts b/src/mcp/index.ts index 6d430f7dc98..310f694fc05 100644 --- a/src/mcp/index.ts +++ b/src/mcp/index.ts @@ -136,6 +136,9 @@ export class FirebaseMcpServer { this.clientInfo = clientInfo; if (clientInfo?.name) { void this.trackGA4("mcp_client_connected"); + if (!process.env.AI_AGENT?.trim()) { + process.env.AI_AGENT = clientInfo.name; + } } if (!this.clientInfo?.name) this.clientInfo = { name: "" };