-
Notifications
You must be signed in to change notification settings - Fork 8k
Add detection of tools with bad schemas and automatically omit them with a warning #5694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @jakemac53, 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!
I've implemented a crucial enhancement to our tool discovery process. This change addresses an issue where MCP tools with untyped parameters in their schemas could cause failures with Gemini function calling. My solution now proactively validates the parameter schemas of discovered MCP tools, ensuring all properties have explicit types. If a tool's schema is found to be invalid, it will be automatically omitted from the available tools, and a warning will be logged to guide users to report the issue to the MCP server owner. This improves the robustness and usability of our CLI by preventing runtime errors caused by malformed tool definitions.
Highlights
- Robust Schema Validation: I've introduced a new utility function, "hasValidTypes", which recursively checks JSON schemas to ensure all properties and array items have a "type" defined.
- Proactive Tool Omission: During the "discoverTools" process, any MCP tool whose parameter schema fails the "hasValidTypes" validation will now be automatically skipped.
- Informative User Warnings: When a tool is skipped due to a malformed schema, a clear warning message is displayed to the user, instructing them to file an issue with the MCP server owner.
- Comprehensive Test Coverage: I've added several new unit tests to "mcp-client.test.ts" to verify the correct behavior of tool skipping for various invalid schema configurations (missing types at top-level, nested, and within arrays), as well as confirming valid schemas are still processed.
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
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 .gemini/
folder in the base of the repository. Detailed instructions can be found here.
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 or fill out our survey to provide feedback.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
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 introduces a validation mechanism to detect and omit MCP tools that have invalid parameter schemas, specifically when a type
property is missing. This is a valuable addition to prevent runtime errors with the Gemini API. The implementation is solid, but I've identified a potential issue in the hasValidTypes
function where it doesn't validate schemas within composition keywords like anyOf
, allOf
, or oneOf
. I've included a suggestion to address this. The tests are comprehensive and cover the intended functionality well.
Code Coverage Summary
CLI Package - Full Text Report
Core Package - Full Text Report
For detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
Added support for subschemas 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -448,6 +507,15 @@ export async function discoverTools( | |||
continue; | |||
} | |||
|
|||
if (!hasValidTypes(funcDecl.parametersJsonSchema)) { | |||
console.warn( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
users won't see console.warn messages unless they open the console. If we make this
console.error then they will see it but may get too concerned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have any more general framework for surfacing errors/warnings to users? I couldn't really find one but I did see other usages of console.warn. The UX is not ideal though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(fwiw, this message does appear without any special flags, at least in my VsCode terminal)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to go ahead and land this as is but I think there should be a separate issue for some sort of general framework for surfacing warnings/errors to the user as full on messages in the chat (but not the gemini history).
…utomatically omit them with a warning (google-gemini#5694)
TLDR
Checks MCP tool parameter schemas to ensure all properties have a specified type.
If they don't then we skip adding the tool, and emit a warning asking the user to file an issue on the MCP Server implementation.
Dive Deeper
Gemini function calling requires types on all schema properties, and if this is not the case then all requests will error out making the entire CLI unusable. It is best to pre-emptively skip these tools in this case since we know they will fail.
It is not actually clear to me if MCP itself allows un-typed parameters from the spec. But either way, Gemini does not.
Reviewer Test Plan
You can connect to a known MCP server that omits types, and should see a message on startup about the skipped tool. I just created my own, but awslabs/mcp#661 has a real one you could try installing and connecting.
Testing Matrix
Linked issues / bugs
Fixes #4594