fix(core): strip $schema from MCP tool parameters for API compatibility#21963
fix(core): strip $schema from MCP tool parameters for API compatibility#21963achaljhawar wants to merge 17 commits intogoogle-gemini:mainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where MCP tools utilizing Draft 2020-12 JSON schemas caused intermittent failures in the Gemini CLI due to the "$schema" property. The changes ensure seamless integration with the Gemini API by removing the "$schema" keyword from the schema presented to the API, while simultaneously preserving full local validation capabilities for tool parameters. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly addresses an API compatibility issue with MCP tools that use JSON Schema Draft 2020-12. The $schema property is stripped from the tool parameters sent to the Gemini API to prevent rejections. The implementation cleverly overrides getSchema for API compatibility while also overriding validateToolParams to use the original, un-stripped schema for local validation. This ensures that the correct schema validator version is used locally. The changes are well-reasoned, targeted, and accompanied by thorough unit tests. The implementation looks solid.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request correctly addresses an API compatibility issue by stripping the $schema property from MCP tool schemas before sending them to the Gemini API, while preserving it for local validation. The approach of overriding getSchema and validateToolParams is sound. However, I've found a critical regression in the getSchema override that causes the important wait_for_previous parameter to be dropped. My review includes a suggested fix for this issue.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request effectively addresses API incompatibility with MCP tools by stripping the $schema property before sending it to the Gemini API, ensuring local validation remains functional. A security review found no vulnerabilities, and the changes are well-structured, maintaining existing architectural patterns.
|
cc @galz10 (tagging for better visibility) |
|
Hi there! Thank you for your interest in contributing to Gemini CLI. To ensure we maintain high code quality and focus on our prioritized roadmap, we have updated our contribution policy (see Discussion #17383). We only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. All other community pull requests are subject to closure after 14 days if they do not align with our current focus areas. For this reason, we strongly recommend that contributors only submit pull requests against issues explicitly labeled as 'help-wanted'. This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding and for being part of our community! |
|
@achaljhawar, apologies for the bot closing this PR! We have reopened it. Please sync your branch to the latest |
|
@cocosheng-g I have resolved the merge conflicts |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates the DiscoveredMCPTool class to improve API compatibility and parameter validation. The getSchema method now strips the $schema property from the tool's parameter schema to ensure compatibility with the Gemini API. Additionally, validateToolParams has been overridden to correctly handle the internal wait_for_previous parameter during validation. New unit tests have been added to verify these changes. I have no feedback to provide.
|
✅ 64 tests passed successfully on gemini-3-flash-preview. 🧠 Model Steering GuidanceThis PR modifies files that affect the model's behavior (prompts, tools, or instructions).
This is an automated guidance message triggered by steering logic signatures. |
🛑 Action Required: Evaluation ApprovalSteering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged. Maintainers:
Once approved, the evaluation results will be posted here automatically. |
Summary
This PR fixes an issue where MCP tools using Draft 2020-12 JSON schemas (containing the $schema property) caused intermittent failures in the Gemini CLI. It ensures compatibility with the Gemini API's strict function declaration requirements while preserving full local validation support.
Details
parametersJsonSchemainDiscoveredMCPTool.getSchema(). This prevents the Gemini model from receiving the metadata keyword, which it often rejects or handles inconsistently.validateToolParamsto use the originalparameterSchema(with $schema intact). This allowsSchemaValidatorto correctly identify the schema as Draft 2020-12 and use the appropriate ajv2020 validator.BaseDeclarativeToolpattern by ensuring local validation still checks for custom parameter values.Related Issues
Fixes #17235
How to Validate
npm test -w @google/gemini-cli-core --src/tools/mcp-tool.test.tsPre-Merge Checklist