Skip to content

feat(core): add tool name validation in TOML policy files#19281

Merged
allenhutchison merged 10 commits intomainfrom
feat/tool-name-validation-toml-policy
Mar 2, 2026
Merged

feat(core): add tool name validation in TOML policy files#19281
allenhutchison merged 10 commits intomainfrom
feat/tool-name-validation-toml-policy

Conversation

@allenhutchison
Copy link
Collaborator

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.

  • Built-in tool validation at TOML load time: Uses Levenshtein distance (threshold ≤ 3) to detect likely typos of built-in tool names while avoiding false positives for dynamically registered tools (agent tools, custom tools)
  • MCP tool validation after server connection: Cross-references policy rules against actually discovered MCP server tools in McpClient.discover(), warning about typos like people.getxMepeople.getMe
  • Severity-aware error reporting: Adds severity field to PolicyFileError so warnings display as warnings (not errors) in the UI via coreEvents.emitFeedback
  • Non-blocking: Rules still load normally regardless of warnings

Files changed

File Change
packages/core/src/policy/toml-loader.ts Add tool_name_warning error type, severity field, validateToolName() for built-in tools, validateMcpPolicyToolNames() for MCP tools
packages/core/src/policy/config.ts Update formatPolicyError and error emission to use severity
packages/core/src/tools/mcp-client.ts Call validateMcpPolicyToolNames after MCP tool discovery
packages/core/src/policy/toml-loader.test.ts Add getErrors/getWarnings helpers, update 7 existing tests, add 18 new tests

Test plan

  • All 49 tests pass in toml-loader.test.ts
  • Pre-commit hooks (prettier, eslint) pass
  • Manual test: misspelled built-in tool name ("grob") shows warning with suggestion ("glob")
  • Manual test: dynamic/agent tool name ("delegate_to_agent") does NOT produce false positive
  • Manual test: misspelled MCP tool name ("people.getxMe") shows warning after server connects

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
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • Built-in Tool Name Validation: Introduced validation for tool names in TOML policy files, providing 'did you mean?' suggestions for likely typos of built-in tools using Levenshtein distance.
  • MCP Tool Name Validation: Implemented post-connection validation for MCP (Multi-Cloud Platform) tool names, cross-referencing policy rules against actually discovered MCP server tools.
  • Severity-Aware Error Reporting: Enhanced policy error reporting with a 'severity' field, allowing warnings to be displayed distinctly from errors in the UI via coreEvents.emitFeedback.
  • Non-Blocking Warnings: Ensured that policy rules continue to load and function normally even when warnings are present, making the validation process non-blocking.
Changelog
  • packages/core/src/policy/config.ts
    • Updated formatPolicyError to display 'warning' or 'error' based on the error's severity.
    • Modified coreEvents.emitFeedback to use the error's severity property when emitting feedback.
  • packages/core/src/policy/toml-loader.test.ts
    • Added getErrors and getWarnings helper functions to filter PolicyLoadResult errors by severity.
    • Updated 7 existing tests to use the new getErrors helper for assertions.
    • Added 18 new tests covering various scenarios for built-in and MCP tool name validation, including typos, wildcards, and dynamic tools.
  • packages/core/src/policy/toml-loader.ts
    • Added tool_name_warning to PolicyFileErrorType and a severity field to the PolicyFileError interface.
    • Introduced MAX_TYPO_DISTANCE constant and validateToolName function for built-in tool name validation using Levenshtein distance.
    • Integrated built-in tool name validation into loadPoliciesFromToml for both rule and safety_checker sections.
    • Exported validateMcpPolicyToolNames function to perform validation of MCP tool names against discovered tools.
  • packages/core/src/tools/mcp-client.ts
    • Imported validateMcpPolicyToolNames from toml-loader.ts.
    • Called validateMcpPolicyToolNames after MCP tool discovery to emit warnings for misspelled MCP tool names found in policy rules.
Activity
  • All 49 tests in toml-loader.test.ts passed.
  • Pre-commit hooks (prettier, eslint) passed.
  • Manual tests were conducted to verify warnings for misspelled built-in tool names, correct handling of dynamic/agent tool names, and warnings for misspelled MCP tool names after server connection.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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. 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

  1. 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.

@github-actions
Copy link

github-actions bot commented Feb 17, 2026

Size Change: +3.95 kB (+0.02%)

Total Size: 25.8 MB

Filename Size Change
./bundle/gemini.js 25.3 MB +3.95 kB (+0.02%)
ℹ️ View Unchanged
Filename Size
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 221 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 227 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 11.5 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB
./bundle/sandbox-macos-strict-open.sb 4.82 kB
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB

compressed-size-action

@gemini-cli gemini-cli bot added priority/p3 Backlog - a good idea but not currently a priority. area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Feb 17, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 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.

allenhutchison and others added 4 commits February 17, 2026 16:51
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.
@allenhutchison allenhutchison marked this pull request as ready for review February 23, 2026 17:17
@allenhutchison allenhutchison requested a review from a team as a code owner February 23, 2026 17:17
Copy link
Contributor

@Abhijit-2592 Abhijit-2592 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a small NIT

@allenhutchison allenhutchison added this pull request to the merge queue Feb 23, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 23, 2026
@allenhutchison allenhutchison added this pull request to the merge queue Mar 2, 2026
@allenhutchison allenhutchison removed this pull request from the merge queue due to a manual request Mar 2, 2026
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
@allenhutchison allenhutchison added this pull request to the merge queue Mar 2, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 2, 2026
@allenhutchison allenhutchison added this pull request to the merge queue Mar 2, 2026
Merged via the queue into main with commit bb6d1a2 Mar 2, 2026
27 checks passed
@allenhutchison allenhutchison deleted the feat/tool-name-validation-toml-policy branch March 2, 2026 21:58
BryanBradfo pushed a commit to BryanBradfo/gemini-cli that referenced this pull request Mar 5, 2026
…ini#19281)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
struckoff pushed a commit to struckoff/gemini-cli that referenced this pull request Mar 6, 2026
…ini#19281)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
…ini#19281)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. priority/p3 Backlog - a good idea but not currently a priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(policy): Add validation for tool names in TOML policy files

2 participants