Repository navigation
fix(mcp): detect installed firebase CLI command and catch start rejections - #11309
Conversation
There was a problem hiding this comment.
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.
f8c211d to
3504bcd
Compare
…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
```
3504bcd to
5ab26d2
Compare
Description
FirebaseMcpServerpreviously suggestednpx firebase-tools@latestin prompts and tool instructions even whenfirebasewas installed onPATH, because--versionwas passed inside the executable name rather than in the arguments array. This updates the check to executecrossSpawn.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.start()to log failures instead of leaving unhandled promise rejections.Scenarios Tested
src/mcp/index.spec.tsexercising public interfaces:start(): Catches and logs backgrounddetectProjectSetup()rejections without unhandled rejections.mcpGetPrompt(): Usesfirebasein prompt instructions when CLI is present, verifies proper args and timeout passed tocrossSpawn.sync, and reuses cached command across calls.mcpGetPrompt(): Falls back tonpx firebase-tools@latestwhen CLI check fails.npx mocha "src/mcp/**/*.spec.ts"), passing all 180 tests in 1s.npm run lint:changed-files), and Prettier formatting pass with 0 errors.Sample Commands