-
Notifications
You must be signed in to change notification settings - Fork 10.2k
fix(core): relax tool name validation to support unprefixed MCP tools #15522
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @kevin-ramdass, 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 updates the tool name validation logic within the core package to be more flexible. The primary goal is to enable proper recognition and usage of unprefixed tools, particularly those originating from the MCP runtime, which were previously being erroneously rejected due to overly strict validation rules. This ensures that agents can correctly utilize a broader range of valid tool names. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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
|
|
Size Change: +55 B (0%) Total Size: 22 MB ℹ️ View Unchanged
|
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 relaxes the tool name validation to support unprefixed tool names, which is a sensible change to align with the runtime behavior. The implementation is straightforward. However, I've identified a potential security vulnerability where tool names could be set to constructor or prototype, which could lead to prototype pollution. I've suggested a fix to the regex to prevent this. I also noted that the same vulnerability exists in another part of the function for namespaced tools, which should also be addressed.
|
|
||
| return false; | ||
| // Allow any valid slug to support unprefixed MCP tools or other dynamic tools | ||
| const slugRegex = /^[a-z0-9-_]+$/i; |
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.
The current regex allows tool names like constructor and prototype. If these tool names are later used as keys in plain JavaScript objects, this could lead to prototype pollution vulnerabilities. It's safer to explicitly disallow these names in the regex.
Note that the same vulnerability exists for the namespaced tool validation on line 87. While that line is not part of this diff, it should also be updated to prevent this vulnerability for namespaced tools (e.g., server__constructor).
| const slugRegex = /^[a-z0-9-_]+$/i; | |
| const slugRegex = /^(?!(?:constructor|prototype)$)[a-z0-9-_]+$/i; |
Summary
Relaxes the tool name validation logic in isValidToolName to accept any valid slug (alphanumeric with dashes/underscores). This fixes an issue where valid, unprefixed MCP tools were being rejected by the agent configuration validator.
Details
Previously, isValidToolName enforced a strict
namespace__toolformat for all non-built-in tools. However, the MCP runtime typically registers tools without a prefix by default (unless there is a name collision). This mismatch caused the static validator to reject valid tool names that the runtime was capable of executing, effectively blocking agents from using them.This change aligns isValidToolName with the runtime's behavior by allowing any tool name that matches the standard slug pattern
^[a-z0-9-_]+$/i.Related Issues
How to Validate
~/.gemini/agents/test.toml) to include this tool using its simple, unprefixed name:Validation failed: tools.0: Invalid tool nameerror.Pre-Merge Checklist