gemini-cli
gemini-cli copied to clipboard
fix(core): handle unsupported JSON Schema versions in MCP tool validation
Summary
MCP servers built with Rust rmcp v0.9.1+ send JSON Schema draft-2020-12, which AJV (the JSON validator) doesn't support by default. This causes tool invocations to fail with "no schema with key or ref" errors. This fix wraps schema compilation in a try-catch, skipping client-side validation when the schema version is unsupported rather than blocking the tool call.
Details
- Applied the same lenient validation pattern already used in
LenientJsonSchemaValidator(mcp-client.ts) for MCP output schemas - When
ajValidator.compile()throws (unsupported schema version, invalid $ref, etc.), skip validation and let the MCP server validate parameters instead - Works with any JSON Schema version (draft-04, 06, 07, 2019-09, 2020-12, future versions)
- No new dependencies required
Related Issues
Fixes #14970 Related to https://github.com/modelcontextprotocol/rust-sdk/issues/587
How to Validate
- Run unit tests:
npm run test -- packages/core/src/utils/schemaValidator.test.ts - Build an rmcp MCP server (e.g., from https://github.com/modelcontextprotocol/rust-sdk):
cd ~/rust-sdk
cargo build --example servers_counter_stdio -p mcp-server-examples
- Configure in ~/.gemini/settings.json:
{"mcpServers": {"counter": {"command": "/path/to/servers_counter_stdio"}}} - Run gemini, then /mcp schema should show tools without errors
- Invoke a tool like sum - should succeed instead of failing with schema error
Pre-Merge Checklist
- [ ] Updated relevant documentation and README (if needed)
- [x] Added/updated tests (if needed)
- [ ] Noted breaking changes (if any)
- [ ] Validated on required platforms/methods:
- [x] MacOS
- [x] npm run
- [ ] npx
- [ ] Docker
- [ ] Podman
- [ ] Seatbelt
- [ ] Windows
- [ ] npm run
- [ ] npx
- [ ] Docker
- [ ] Linux
- [ ] npm run
- [ ] npx
- [ ] Docker
- [x] MacOS