feat(core): add draft-2020-12 JSON Schema support with lenient fallback#15060
Conversation
Summary of ChangesHello @afarber, 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 introduces a robust solution to prevent tool invocation failures caused by the client-side JSON schema validator's inability to process newer or unsupported JSON Schema draft versions. By implementing a lenient validation approach, the system now gracefully handles schema compilation errors, effectively skipping client-side validation when a schema's version is not recognized. This ensures broader compatibility with evolving JSON Schema standards and maintains the functionality of tools interacting with updated MCP servers. Highlights
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 intends to prevent crashes from unsupported JSON Schema versions by using a "try-catch" block for schema compilation, allowing tool calls to rely on server-side validation. However, this introduces a high-severity security bypass vulnerability in packages/core/src/utils/schemaValidator.ts. Silently skipping input validation on compilation failure could allow malicious data to reach downstream tools. It is strongly recommended to implement a fail-secure approach where compilation failures are treated as errors. Furthermore, adding a log message when validation is skipped would improve debuggability.
There was a problem hiding this comment.
Code Review
This pull request introduces a lenient validation approach to handle unsupported JSON Schema versions from MCP servers, where client-side validation is skipped if schema compilation fails. However, this change introduces a high-severity validation bypass vulnerability in packages/core/src/utils/schemaValidator.ts. By silently ignoring schema compilation errors, the current 'fail-open' implementation allows an attacker to bypass validation, potentially leading to serious security implications. A 'fail-secure' approach, where validation errors result in data rejection, is strongly recommended. Furthermore, the silent error handling hinders debugging and could mask other schema-related problems; logging is advised for improved visibility.
There was a problem hiding this comment.
Code Review
This pull request aims to address issues with tool invocations failing due to unsupported JSON Schema versions by wrapping schema compilation in a try-catch block to skip client-side validation for incompatible schemas. However, a high-severity security vulnerability has been identified: the current implementation in schemaValidator.ts introduces a security bypass flaw by 'failing open'. When schema compilation fails, the validator incorrectly reports success, allowing unvalidated data to pass through, which removes a critical layer of defense. This needs to be remediated by ensuring the function fails securely. Additionally, it's recommended to add logging to the catch block to aid in debugging and prevent other potential issues from being silently masked.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request addresses tool invocation failures due to unsupported JSON Schema versions by implementing a try-catch block in SchemaValidator to skip validation and log a warning for problematic schemas. However, this approach introduces a high-severity validation bypass vulnerability. The current 'fail-open' mechanism, which allows parameter validation to be bypassed when an unsupported or malformed schema is encountered, is insecure. While the changes include comprehensive unit tests and align with existing lenient validation patterns, it is critical to revise this to a 'fail-closed' principle. This ensures that if a schema cannot be processed, validation explicitly fails, blocking the tool call and preventing potential security exploits.
9c7e7e0 to
aaed29b
Compare
|
I did a quick test of this on Linux and it also resolved my schema validation issues when testing an MCP server written with the rmcp library |
aaed29b to
0de7446
Compare
0de7446 to
cd97ab7
Compare
|
According to AVJ, it does support draft-2020-12, but you need to import it from a different package: import Ajv2020 from "ajv/dist/2020"
const ajv = new Ajv2020()So instead of skipping validation, can we detect if this schema is used and then use the right version of the AJV validator? |
830691a to
dbdc99f
Compare
18b5340 to
53bc253
Compare
53bc253 to
d7da4cc
Compare
c51b99c to
b9524eb
Compare
|
@afarber looks like this fails to build and lint job is complaining? Mind taking a look. |
ba23400 to
a582c7b
Compare
|
@jackwotherspoon I think now it's ready, thanks @Adib234 |
a582c7b to
0affb47
Compare
0affb47 to
0925393
Compare
|
@jackwotherspoon do you have any clue when this will get merged? |
0925393 to
ad4c3ee
Compare
…ck (#15060) Co-authored-by: A.K.M. Adib <adibakm@google.com> Co-authored-by: Jack Wotherspoon <jackwoth@google.com>
…ck (google-gemini#15060) Co-authored-by: A.K.M. Adib <adibakm@google.com> Co-authored-by: Jack Wotherspoon <jackwoth@google.com>
…ck (google-gemini#15060) Co-authored-by: A.K.M. Adib <adibakm@google.com> Co-authored-by: Jack Wotherspoon <jackwoth@google.com>
…ck (google-gemini#15060) Co-authored-by: A.K.M. Adib <adibakm@google.com> Co-authored-by: Jack Wotherspoon <jackwoth@google.com>

Summary
Add JSON Schema draft-2020-12 validation support for MCP servers (e.g., rmcp/Rust SDK), while keeping a lenient fallback for unknown future schema versions:
ajvDefaultajv2020Related Issues
Fixes #14970
Related to modelcontextprotocol/rust-sdk#587
How to Validate
npm run test -- packages/core/src/utils/schemaValidator.test.ts{"mcpServers": {"counter": {"command": "/path/to/servers_counter_stdio"}}}Pre-Merge Checklist