Skip to content

fix(mcp): detect installed firebase CLI command and catch start rejections - #11309

Merged
ajperel merged 1 commit into
mainfrom
ajp/fix_mcp_server_issues
Oct 19, 2026
Merged

ajperel merged 1 commit into
mainfrom
ajp/fix_mcp_server_issues

Conversation

@ajperel

@ajperel ajperel commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

  • Firebase CLI detection: FirebaseMcpServer previously suggested npx firebase-tools@latest in prompts and tool instructions even when firebase was installed on PATH, because --version was passed inside the executable name rather than in the arguments array. This updates the check to execute crossSpawn.sync("firebase", ["--version"], ...) with a 2-second timeout and instance-level caching so that installed CLI detection works reliably and subsequent context creation calls resolve instantaneously.
  • Background startup safety: Added an error rejection handler to background project detection in start() to log failures instead of leaving unhandled promise rejections.

Scenarios Tested

  • Added unit tests in src/mcp/index.spec.ts exercising public interfaces:
    • start(): Catches and logs background detectProjectSetup() rejections without unhandled rejections.
    • mcpGetPrompt(): Uses firebase in prompt instructions when CLI is present, verifies proper args and timeout passed to crossSpawn.sync, and reuses cached command across calls.
    • mcpGetPrompt(): Falls back to npx firebase-tools@latest when CLI check fails.
  • Ran full MCP unit test suite (npx mocha "src/mcp/**/*.spec.ts"), passing all 180 tests in 1s.
  • Executed the full E2E verification test suite across stdio and SSE transports covering installed PATH, missing binary, hung CLI shim timeout, caching speed (<15ms), concurrent in-flight requests, and corrupt configuration fault injection, passing all 8/8 scenarios.
  • Verified build compilation, linting (npm run lint:changed-files), and Prettier formatting pass with 0 errors.

Sample Commands

firebase mcp

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the Firebase MCP server to asynchronously detect the presence of the 'firebase' CLI using crossSpawn.spawn with a 2-second timeout, falling back to 'npx firebase-tools@latest' if it is not found or times out. It caches this detection promise across server instances, updates _createMcpContext to be asynchronous, and adds error handling for detectProjectSetup during startup. Additionally, comprehensive unit tests were added to cover these scenarios. The code review feedback suggests removing several 'any' type casts in the new test file to comply with the repository's style guide, recommending proper typing for fake child processes and using bracket notation to access private members.

Comment thread src/mcp/index.spec.ts Resolved
Comment thread src/mcp/index.spec.ts Resolved
Comment thread src/mcp/index.spec.ts Resolved
@ajperel
ajperel force-pushed the ajp/fix_mcp_server_issues branch 3 times, most recently from f8c211d to 3504bcd Compare October 19, 2026 19:54
…tions

### Description

- **Firebase CLI detection**: `FirebaseMcpServer` previously suggested `npx firebase-tools@latest` in prompts and tool instructions even when `firebase` was installed on `PATH`, because `--version` was passed inside the executable name rather than in the arguments array. This updates the check to execute `crossSpawn.sync("firebase", ["--version"], ...)` with a 2-second timeout and instance-level caching so that installed CLI detection works reliably and subsequent context creation calls resolve instantaneously.
- **Background startup safety**: Added an error rejection handler to background project detection in `start()` to log failures instead of leaving unhandled promise rejections.

### Scenarios Tested

- Added unit tests in `src/mcp/index.spec.ts` exercising public interfaces:
  - `start()`: Catches and logs background `detectProjectSetup()` rejections without unhandled rejections.
  - `mcpGetPrompt()`: Uses `firebase` in prompt instructions when CLI is present, verifies proper args and timeout passed to `crossSpawn.sync`, and reuses cached command across calls.
  - `mcpGetPrompt()`: Falls back to `npx firebase-tools@latest` when CLI check fails.
- Ran full MCP unit test suite (`npx mocha "src/mcp/**/*.spec.ts"`), passing all 180 tests in 1s.
- Executed the full E2E verification test suite across stdio and SSE transports covering installed PATH, missing binary, hung CLI shim timeout, caching speed (<15ms), concurrent in-flight requests, and corrupt configuration fault injection, passing all 8/8 scenarios.
- Verified build compilation, linting (`npm run lint:changed-files`), and Prettier formatting pass with 0 errors.

### Sample Commands

```bash
firebase mcp
```
@ajperel
ajperel force-pushed the ajp/fix_mcp_server_issues branch from 3504bcd to 5ab26d2 Compare October 19, 2026 20:09
@ajperel
ajperel requested a review from joehan October 19, 2026 20:12
@ajperel
ajperel merged commit 2662e15 into main Oct 19, 2026
75 of 77 checks passed
@ajperel
ajperel deleted the ajp/fix_mcp_server_issues branch October 19, 2026 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants