feat(core): add tool name validation in TOML policy files#19281
feat(core): add tool name validation in TOML policy files#19281allenhutchison merged 10 commits intomainfrom
Conversation
When a user misspells a tool name in a TOML policy file, the rule silently does nothing. This adds validation that warns about unrecognized tool names with "did you mean?" suggestions. - Add tool name validation for built-in tools at TOML load time using Levenshtein distance (threshold ≤ 3) to detect likely typos while avoiding false positives for dynamic/agent tools - Add post-connection MCP tool name validation that cross-references policy rules against actually discovered MCP server tools - Add severity field to PolicyFileError so warnings display distinctly from errors - Rules still load normally regardless of warnings
Summary of ChangesHello @allenhutchison, 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 significantly improves the robustness of policy file processing by adding comprehensive validation for tool names specified in TOML policy configurations. It addresses a silent failure mode where misspelled tool names would lead to rules not being applied. By introducing both built-in and MCP-specific tool name validation, with intelligent typo detection and severity-aware feedback, the system now proactively informs users of potential misconfigurations without blocking policy loading. 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
|
|
Size Change: +3.95 kB (+0.02%) Total Size: 25.8 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable feature to validate tool names in TOML policy files, warning users about potential typos using Levenshtein distance. This improves user experience by preventing silent failures from misspelled tool names. The implementation correctly handles built-in tools at load time and MCP tools after server discovery. I've found one high-severity issue where a typo resembling an MCP tool name format could be missed by the validation logic. My review includes a suggestion to address this gap. Otherwise, the changes are well-implemented and thoroughly tested.
The validateMcpPolicyToolNames call in discover() would throw when getPolicyEngine() is unavailable. Wrap in try-catch since validation is best-effort and non-critical.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Accept main's version which correctly references result2 variable, uses proper Workspace/User source labels for tier 2/3, and adds Tier 3 test coverage. Also fixes pre-existing ESLint errors in devtoolsService.ts for unsafe any assignments from dynamic import.
Abhijit-2592
left a comment
There was a problem hiding this comment.
LGTM with a small NIT
The discover() method calls cliConfig.getPolicyEngine() but cliConfig is typed as McpContext, which didn't have that method. This caused a TypeScript compilation error that cascaded to all CI checks. - Add optional getPolicyEngine() to the McpContext interface - Use optional chaining at the call site for type safety
…ini#19281) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…ini#19281) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…ini#19281) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Summary
Fixes #12119
When a user misspells a tool name in a TOML policy file (e.g.,
toolName = "run_shell"instead of"run_shell_command"), the rule silently does nothing. This adds validation that warns about unrecognized tool names with "did you mean?" suggestions.McpClient.discover(), warning about typos likepeople.getxMe→people.getMeseverityfield toPolicyFileErrorso warnings display as warnings (not errors) in the UI viacoreEvents.emitFeedbackFiles changed
packages/core/src/policy/toml-loader.tstool_name_warningerror type,severityfield,validateToolName()for built-in tools,validateMcpPolicyToolNames()for MCP toolspackages/core/src/policy/config.tsformatPolicyErrorand error emission to use severitypackages/core/src/tools/mcp-client.tsvalidateMcpPolicyToolNamesafter MCP tool discoverypackages/core/src/policy/toml-loader.test.tsgetErrors/getWarningshelpers, update 7 existing tests, add 18 new testsTest plan
toml-loader.test.ts"grob") shows warning with suggestion ("glob")"delegate_to_agent") does NOT produce false positive"people.getxMe") shows warning after server connects