Skip to content

fix(core): resolve MCP tool FQN validation, schema export, and wildcards in subagents#22069

Merged
abhipatel12 merged 3 commits intomainfrom
abhi/fix-mcp-fqn-validation
Mar 12, 2026
Merged

fix(core): resolve MCP tool FQN validation, schema export, and wildcards in subagents#22069
abhipatel12 merged 3 commits intomainfrom
abhi/fix-mcp-fqn-validation

Conversation

@abhipatel12
Copy link
Copy Markdown
Contributor

Summary

Fixes an issue where subagents rejected standard mcp_{serverName}_{toolName} Fully Qualified Names (FQNs) due to outdated validation logic that incorrectly permitted only the deprecated server__tool legacy format. It additionally adds internal support for resolving generic and MCP wildcards during subagent tool loads.

Details

  • The isValidToolName logic in tool-names.ts now securely validates mcp_ names by strictly adhering to the parsing constraints given by mcp-tool.ts.
  • Explicitly removed the dead fallback block for parsing __ inside tool-registry.ts, as the Policy Engine normalizes structure to mcp_ before getTool(name) executes.
  • Cleaned up legacy checks and false-positive wildcard tests inside tool-names.test.ts.
  • Updated the agentLoader.ts Zod schema to allow wildcards when parsing the tools array of a subagent configuration file (by supplying { allowWildcards: true } to isValidToolName).
  • Implemented generic wildcard (*) and MCP wildcard (mcp_*, mcp_server_*) resolution natively inside local-executor.ts since subagents lacked the ability to expand tools organically.
  • Bug Fix: Removed the unnecessary duplicate tool filtering inside local-executor.ts prepareToolsList, and updated ToolRegistry.getFunctionDeclarationsFiltered (used by subagents) to properly rewrite the tool schema name to the Fully Qualified Name (e.g. mcp_server_tool) just like getFunctionDeclarations does. This ensures the model executes authorized tools instead of hallucinating stripped bare names.

Related Issues

N/A

How to Validate

  1. Configure an MCP server in your settings.json.
  2. Define a subagent using the new standard FQN pattern (e.g. mcp_serverName_*).
  3. Observe that it successfully validates and resolves to all the tools in the registry, and correctly outputs the delegated tool responses.
  4. Validate unit tests via npm run test across @google/gemini-cli-core.
  5. Run full validations via npm run preflight.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@abhipatel12 abhipatel12 requested a review from a team as a code owner March 11, 2026 20:14
@abhipatel12 abhipatel12 force-pushed the abhi/fix-mcp-fqn-validation branch from 68ddf38 to bbe0871 Compare March 11, 2026 20:15
@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Mar 11, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 enhances the system's ability to handle tool names within subagents by modernizing the validation and resolution mechanisms. It primarily addresses issues with Fully Qualified Names (FQNs) for MCP tools, ensuring that subagents can correctly interpret and utilize the standard mcp_ naming convention. Additionally, it introduces robust support for wildcards in tool declarations, providing greater flexibility in how subagents are configured and interact with available tools. These changes streamline tool management and improve the reliability of tool execution within the agent ecosystem.

Highlights

  • MCP Tool FQN Validation: Resolved an issue where subagents incorrectly rejected standard mcp_serverName_toolName Fully Qualified Names (FQNs) due to outdated validation logic, now strictly adhering to the mcp_ format.
  • Wildcard Support for Subagents: Added internal support for resolving generic (*) and MCP-specific (mcp_*, mcp_server_*) wildcards during subagent tool loading, enabling more flexible tool configurations.
  • Schema Export Correction: Ensured that ToolRegistry.getFunctionDeclarationsFiltered correctly rewrites the tool schema name to the Fully Qualified Name (e.g., mcp_server_tool) for MCP tools, preventing models from hallucinating stripped bare names.
  • Legacy Format Removal: Cleaned up and explicitly removed deprecated validation logic and fallback parsing for the server__tool legacy format across tool-names.ts and tool-registry.ts.
  • Subagent Configuration Schema Update: Updated the agentLoader.ts Zod schema to allow wildcards when parsing the tools array in subagent configuration files.
Changelog
  • packages/core/src/agents/agentLoader.ts
    • Updated the Zod schema for subagent configurations to permit tool names with wildcards.
  • packages/core/src/agents/local-executor.ts
    • Implemented native resolution for generic and MCP wildcards when loading subagent tools.
    • Refactored tool registration logic to support wildcard expansion.
    • Removed redundant tool filtering during schema generation.
  • packages/core/src/tools/mcp-tool.ts
    • Clarified parsing constraints for MCP tool names to ensure strict server_tool format.
  • packages/core/src/tools/tool-names.test.ts
    • Updated unit tests for isValidToolName to reflect the new validation logic for mcp_ FQNs and wildcard handling, removing legacy __ format tests.
  • packages/core/src/tools/tool-names.ts
    • Refactored isValidToolName to strictly validate mcp_ prefixed Fully Qualified Names (FQNs) and support wildcards, while deprecating and removing validation for the server__tool legacy format.
  • packages/core/src/tools/tool-registry.ts
    • Updated getFunctionDeclarationsFiltered to ensure MCP tool schemas use their fully qualified names.
    • Removed the deprecated fallback parsing logic for __ in getTool.
Activity
  • The author, abhipatel12, has updated relevant documentation and README where needed.
  • The author, abhipatel12, has added and updated tests as required.
  • The author, abhipatel12, has validated the changes on MacOS using npm run.
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
Copy Markdown

github-actions bot commented Mar 11, 2026

Size Change: +286 B (0%)

Total Size: 26.5 MB

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

compressed-size-action

Copy link
Copy Markdown
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 effectively addresses several issues related to MCP tool name validation and subagent tool loading. The transition to validating fully qualified mcp_ names in tool-names.ts and removing legacy __ parsing logic is a great improvement for consistency and correctness. The added support for wildcards in subagent definitions within local-executor.ts is also a valuable feature enhancement.

I've found one minor bug in the new validation logic where tool names consisting only of underscores could pass validation. I've left a specific comment with a suggested fix. Overall, this is a solid set of changes that improves the robustness of tool handling for subagents.

@abhipatel12 abhipatel12 force-pushed the abhi/fix-mcp-fqn-validation branch from bbe0871 to 6eca4bb Compare March 11, 2026 20:41
return;
}

if (tool instanceof DiscoveredMCPTool) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are there ever cases where this instanceof check wouldn't work right at runtime due to the object being deserialized instead of constructed the normal way?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Taking a look through the code and double checking with Gemini, it appears this is safe. Also seems we do this same thing more than 20 places around the codebase, so should be safe.

Copy link
Copy Markdown
Member

@gundermanc gundermanc left a comment

Choose a reason for hiding this comment

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

Approved with a suggestion.

@abhipatel12 abhipatel12 force-pushed the abhi/fix-mcp-fqn-validation branch from 4ae29de to 9cf4e2a Compare March 12, 2026 05:33
@abhipatel12 abhipatel12 enabled auto-merge March 12, 2026 05:35
@abhipatel12 abhipatel12 added this pull request to the merge queue Mar 12, 2026
Merged via the queue into main with commit 8432bce Mar 12, 2026
27 checks passed
@abhipatel12 abhipatel12 deleted the abhi/fix-mcp-fqn-validation branch March 12, 2026 14:31
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
@abhipatel12
Copy link
Copy Markdown
Contributor Author

/patch both

@github-actions
Copy link
Copy Markdown

🚀 [Step 1/4] Patch workflow(s) waiting for approval!

📋 Details:

  • Channels: stable,preview
  • Commit: 8432bcee752bb36e2b55274a9426ffac604812ab
  • Workflows Created: 2

⏳ Status: The patch creation workflow has been triggered and is waiting for deployment approval. Please visit the specific workflow links below and approve the runs.

🔗 Track Progress:

github-actions bot pushed a commit that referenced this pull request Mar 12, 2026
@github-actions
Copy link
Copy Markdown

🚀 [Step 2/4] Patch PR Created!

📋 Patch Details:

📝 Next Steps:

  1. Review and approve the hotfix PR: #22205
  2. Once merged, the patch release will automatically trigger
  3. You'll receive updates here when the release completes

🔗 Track Progress:

github-actions bot pushed a commit that referenced this pull request Mar 12, 2026
@github-actions
Copy link
Copy Markdown

🚀 [Step 2/4] Patch PR Created!

📋 Patch Details:

📝 Next Steps:

  1. Review and approve the hotfix PR: #22206
  2. Once merged, the patch release will automatically trigger
  3. You'll receive updates here when the release completes

🔗 Track Progress:

@github-actions
Copy link
Copy Markdown

🚀 [Step 3/4] Patch Release Waiting for Approval!

📋 Release Details:

  • Environment: prod
  • Channel: preview → publishing to npm tag preview
  • Version: v0.34.0-preview.1
  • Hotfix PR: Merged ✅
  • Release Branch: release/v0.34.0-preview.1-pr-22069

⏳ Status: The patch release has been triggered and is waiting for deployment approval. Please visit the specific workflow run link below and approve the deployment. You'll receive another update when it completes.

🔗 Track Progress:

@github-actions
Copy link
Copy Markdown

🚀 [Step 3/4] Patch Release Waiting for Approval!

📋 Release Details:

  • Environment: prod
  • Channel: stable → publishing to npm tag latest
  • Version: v0.33.0
  • Hotfix PR: Merged ✅
  • Release Branch: release/v0.33.0-pr-22069

⏳ Status: The patch release has been triggered and is waiting for deployment approval. Please visit the specific workflow run link below and approve the deployment. You'll receive another update when it completes.

🔗 Track Progress:

@github-actions
Copy link
Copy Markdown

[Step 4/4] Patch Release Complete!

📦 Release Details:

🎉 Status: Your patch has been successfully released and published to npm!

📝 What's Available:

🔗 Links:

@github-actions
Copy link
Copy Markdown

[Step 4/4] Patch Release Complete!

📦 Release Details:

  • Version: 0.33.1
  • NPM Tag: latest
  • Channel: stable
  • Dry Run: false

🎉 Status: Your patch has been successfully released and published to npm!

📝 What's Available:

🔗 Links:

@marsam2489-lang
Copy link
Copy Markdown

Done bro

SUNDRAM07 pushed a commit to SUNDRAM07/gemini-cli that referenced this pull request Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants