Skip to content

Stop checking MCP tool schemas for type definitions#9574

Merged
bbiggs merged 24 commits into
google-gemini:mainfrom
geoffdowns:remove-type-checks
Sep 26, 2025
Merged

Stop checking MCP tool schemas for type definitions#9574
bbiggs merged 24 commits into
google-gemini:mainfrom
geoffdowns:remove-type-checks

Conversation

@geoffdowns

Copy link
Copy Markdown
Contributor

TLDR

This change removes the hasValidTypes method added in #5694 as the check is overly restrictive and prevents the use of valid MCP tools.

Dive Deeper

The hasValidTypes method attempted to enforce that MCP tools provide a JSON schema that would be accepted by the Gemini/Vertex AI APIs (after first being converted into a FunctionDeclaration by the GenAI SDK). The restriction was added in response to #4594 and (related): awslabs/mcp#661

However, the JSON schema generated by the MCP server referenced in those issues is a valid JSON schema and has types defined for all the schema elements. The MCP inputSchema is:

"inputSchema":{
  "$defs":{
    "DiagramType":{
      "description":"Enum for supported diagram types.",
      "enum":["aws","sequence","flow","class","k8s","onprem","custom","all"],
      "title":"DiagramType",
      "type":"string"
    }
  },
  "properties":{
    "diagram_type":{
      "$ref":"#/$defs/DiagramType",
      "default":"all",
      "description":"Type of diagram example to return. Options: aws, sequence, flow, class, k8s, onprem, custom, all"
    }
  },
  "title":"mcp_get_diagram_examplesArguments",
  "type":"object"
}}

This JSON schema uses JSON pointer references. The hasValidTypes method incorrectly rejects MCP tools that use this JSON schema feature.

The original error was caused by lossy conversion of the MCP input schema in the GenAI SDK. The information loss was remediated by setting the functionDeclaration.parametersJsonSchema instead of converting to the genai-js types.Schema object and setting the functionDeclaration.parameters field. This change was made in: googleapis/js-genai@36f6350#diff-fdde9372aec859322b7c5a5efe467e0ad25a57210c7229724586ee90ea4f5a30

The original intent of #5694 was to prevent one bad MCP tool schema from causing all Gemini API calls to fail. The underlying issue was never with the MCP tool schemas, however, and the Gemini API accepts JSON schemas that use $ref/$def or even omit type information altogether.

Reviewer Test Plan

Use GCLI with any MCP tool that uses the $refs JSON schema feature. The tool should no longer be filtered out during initialization. Gemini API calls should succeed and the tool should work as expected.

Testing Matrix

🍏 🪟 🐧
npm run x
npx
Docker
Podman - -
Seatbelt - -

Linked issues / bugs

Fixes #6219

@geoffdowns geoffdowns requested a review from a team as a code owner September 25, 2025 06:39
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @geoffdowns, 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 refines the handling of Model Context Protocol (MCP) tools by eliminating an overly stringent schema validation check. The hasValidTypes method, originally implemented to ensure compatibility with Gemini/Vertex AI APIs, was inadvertently rejecting valid MCP tool schemas that employed JSON pointer references. Its removal ensures that all correctly defined MCP tools can be seamlessly integrated and utilized, thereby resolving a prior issue where such tools were being filtered out.

Highlights

  • Removal of hasValidTypes function: The hasValidTypes method, which was previously added to validate MCP tool schemas, has been entirely removed. This function was found to be overly restrictive and incorrectly rejected valid tool schemas.
  • Improved MCP Tool Compatibility: MCP tools that utilize advanced JSON schema features, such as JSON pointer references ($ref and $defs), are now correctly processed and no longer filtered out. This resolves issues where valid tools were being prevented from use.
  • Resolution of Issue version >= 0.1.18 rejects MCP functions with ambiguous type info #6219: This change directly addresses and fixes issue version >= 0.1.18 rejects MCP functions with ambiguous type info #6219, which reported problems with MCP tools being incorrectly rejected due to the restrictive schema validation.
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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 correctly removes the hasValidTypes validation for MCP tool schemas, which was overly restrictive. The function and its direct tests have been removed. However, a related test case that verifies the skipping of tools with invalid schemas was missed and will now fail. This needs to be removed to complete the change.

@geoffdowns

Copy link
Copy Markdown
Contributor Author

Code Review

This pull request correctly removes the hasValidTypes validation for MCP tool schemas, which was overly restrictive. The function and its direct tests have been removed. However, a related test case that verifies the skipping of tools with invalid schemas was missed and will now fail. This needs to be removed to complete the change.

fixed

@bbiggs bbiggs added this pull request to the merge queue Sep 25, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 25, 2025
@bbiggs bbiggs added this pull request to the merge queue Sep 25, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 25, 2025
geoffdowns and others added 17 commits September 25, 2025 17:24
…options (google-gemini#9540)

Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
…ni#9517)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Shreya Keshive <skeshive@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@geoffdowns geoffdowns requested a review from a team as a code owner September 26, 2025 00:25
@bbiggs bbiggs added this pull request to the merge queue Sep 26, 2025
Merged via the queue into google-gemini:main with commit 11c995e Sep 26, 2025
16 of 17 checks passed
dtometzki pushed a commit to dtometzki/gemini-cli that referenced this pull request Sep 26, 2025
Co-authored-by: Gal Zahavi <38544478+galz10@users.noreply.github.com>
Co-authored-by: anthony bushong <agmsb@users.noreply.github.com>
Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
Co-authored-by: Sandy Tao <sandytao520@icloud.com>
Co-authored-by: Jacob MacDonald <jakemac@google.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: christine betts <chrstn@uw.edu>
Co-authored-by: Adam Weidman <65992621+adamfweidman@users.noreply.github.com>
Co-authored-by: matt korwel <matt.korwel@gmail.com>
Co-authored-by: Shreya Keshive <skeshive@gmail.com>
Co-authored-by: HugoMurillo <mhugorodrigo@google.com>
Co-authored-by: Shreya Keshive <shreyakeshive@google.com>
Co-authored-by: Miguel Solorio <miguelsolorio@google.com>
Co-authored-by: Christie Warwick (Wilson) <bobcatfish@gmail.com>
Co-authored-by: shrutip90 <shruti.p90@gmail.com>
jkcinouye pushed a commit that referenced this pull request Sep 29, 2025
Co-authored-by: Gal Zahavi <38544478+galz10@users.noreply.github.com>
Co-authored-by: anthony bushong <agmsb@users.noreply.github.com>
Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
Co-authored-by: Sandy Tao <sandytao520@icloud.com>
Co-authored-by: Jacob MacDonald <jakemac@google.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: christine betts <chrstn@uw.edu>
Co-authored-by: Adam Weidman <65992621+adamfweidman@users.noreply.github.com>
Co-authored-by: matt korwel <matt.korwel@gmail.com>
Co-authored-by: Shreya Keshive <skeshive@gmail.com>
Co-authored-by: HugoMurillo <mhugorodrigo@google.com>
Co-authored-by: Shreya Keshive <shreyakeshive@google.com>
Co-authored-by: Miguel Solorio <miguelsolorio@google.com>
Co-authored-by: Christie Warwick (Wilson) <bobcatfish@gmail.com>
Co-authored-by: shrutip90 <shruti.p90@gmail.com>
thacio added a commit to thacio/auditaria that referenced this pull request Oct 4, 2025
semgrep-ci Bot pushed a commit to semgrep/semgrep that referenced this pull request Oct 6, 2025
…-proprietary#4774)

In the past, Gemini CLI doesn't work with the Semgrep MCP server when we use our custom types. [Other MCP servers are also running into this error.](google-gemini/gemini-cli#6219) Gemini recently [released a fix ](google-gemini/gemini-cli#9574 this, so we should add the types back so models like GPT-5 can call our tools properly.

Fixes SAF-2262

## Test plan:

```

 ███            █████████  ██████████ ██████   ██████ █████ ██████   █████ █████
░░░███         ███░░░░░███░░███░░░░░█░░██████ ██████ ░░███ ░░██████ ░░███ ░░███
  ░░░███      ███     ░░░  ░███  █ ░  ░███░█████░███  ░███  ░███░███ ░███  ░███
    ░░░███   ░███          ░██████    ░███░░███ ░███  ░███  ░███░░███░███  ░███
     ███░    ░███    █████ ░███░░█    ░███ ░░░  ░███  ░███  ░███ ░░██████  ░███
   ███░      ░░███  ░░███  ░███ ░   █ ░███      ░███  ░███  ░███  ░░█████  ░███
 ███░         ░░█████████  ██████████ █████     █████ █████ █████  ░░█████ █████
░░░            ░░░░░░░░░  ░░░░░░░░░░ ░░░░░     ░░░░░ ░░░░░ ░░░░░    ░░░░░ ░░░░░

                                                v0.9.0-nightly.20251001.163dba7e
Tips for getting started:
1. Ask questions, edit files, or run commands.
2. Be specific for the best results.
3. Create GEMINI.md files to customize your interactions with Gemini.
4. /help for more information.

> /mcp

Configured MCP servers:

🟢 serverName - Ready (7 tools, 2 prompts)
  Tools:
  - get_abstract_syntax_tree
  - get_supported_languages
  - semgrep_findings
  - semgrep_rule_schema
  - semgrep_scan
  - semgrep_scan_supply_chain
  - semgrep_scan_with_custom_rule
  Prompts:
  - setup_semgrep_mcp
  - write_custom_semgrep_rule


💡 Tips:
  - Use /mcp desc to show server and tool descriptions
  - Use /mcp schema to show tool parameter schemas
  - Use /mcp nodesc to hide descriptions
  - Use /mcp auth <server-name> to authenticate with OAuth-enabled servers
  - Press Ctrl+T to toggle tool descriptions on/off

Using: 1 MCP server (ctrl+t to view)
╭──────────────────────────────────────────────────────────────────────────────────╮
│ >   Type your message or @path/to/file                                           │
╰──────────────────────────────────────────────────────────────────────────────────╯
~/Desktop/semgrep-proprietary          no sandbox (see   gemini-2.5-pro (100%
(katrina/mcp-types*)                   /docs)           context left)
```

Also tested that Cursor was able to call `semgrep_scan` after the change with the GPT-5 model (and that it was not able to call the tool nicely before the change)

![image.png](https://app.graphite.dev/user-attachments/assets/dd7a3921-5c61-4f48-b262-12b893a037e7.png)

synced from Pro 6ee3493829fff70665a892703aef809bf8899094
semgrep-ci Bot pushed a commit to semgrep/semgrep that referenced this pull request Oct 7, 2025
…-proprietary#4774)

In the past, Gemini CLI doesn't work with the Semgrep MCP server when we use our custom types. [Other MCP servers are also running into this error.](google-gemini/gemini-cli#6219) Gemini recently [released a fix ](google-gemini/gemini-cli#9574 this, so we should add the types back so models like GPT-5 can call our tools properly.

Fixes SAF-2262

## Test plan:

```

 ███            █████████  ██████████ ██████   ██████ █████ ██████   █████ █████
░░░███         ███░░░░░███░░███░░░░░█░░██████ ██████ ░░███ ░░██████ ░░███ ░░███
  ░░░███      ███     ░░░  ░███  █ ░  ░███░█████░███  ░███  ░███░███ ░███  ░███
    ░░░███   ░███          ░██████    ░███░░███ ░███  ░███  ░███░░███░███  ░███
     ███░    ░███    █████ ░███░░█    ░███ ░░░  ░███  ░███  ░███ ░░██████  ░███
   ███░      ░░███  ░░███  ░███ ░   █ ░███      ░███  ░███  ░███  ░░█████  ░███
 ███░         ░░█████████  ██████████ █████     █████ █████ █████  ░░█████ █████
░░░            ░░░░░░░░░  ░░░░░░░░░░ ░░░░░     ░░░░░ ░░░░░ ░░░░░    ░░░░░ ░░░░░

                                                v0.9.0-nightly.20251001.163dba7e
Tips for getting started:
1. Ask questions, edit files, or run commands.
2. Be specific for the best results.
3. Create GEMINI.md files to customize your interactions with Gemini.
4. /help for more information.

> /mcp

Configured MCP servers:

🟢 serverName - Ready (7 tools, 2 prompts)
  Tools:
  - get_abstract_syntax_tree
  - get_supported_languages
  - semgrep_findings
  - semgrep_rule_schema
  - semgrep_scan
  - semgrep_scan_supply_chain
  - semgrep_scan_with_custom_rule
  Prompts:
  - setup_semgrep_mcp
  - write_custom_semgrep_rule


💡 Tips:
  - Use /mcp desc to show server and tool descriptions
  - Use /mcp schema to show tool parameter schemas
  - Use /mcp nodesc to hide descriptions
  - Use /mcp auth <server-name> to authenticate with OAuth-enabled servers
  - Press Ctrl+T to toggle tool descriptions on/off

Using: 1 MCP server (ctrl+t to view)
╭──────────────────────────────────────────────────────────────────────────────────╮
│ >   Type your message or @path/to/file                                           │
╰──────────────────────────────────────────────────────────────────────────────────╯
~/Desktop/semgrep-proprietary          no sandbox (see   gemini-2.5-pro (100%
(katrina/mcp-types*)                   /docs)           context left)
```

Also tested that Cursor was able to call `semgrep_scan` after the change with the GPT-5 model (and that it was not able to call the tool nicely before the change)

![image.png](https://app.graphite.dev/user-attachments/assets/dd7a3921-5c61-4f48-b262-12b893a037e7.png)

synced from Pro 6ee3493829fff70665a892703aef809bf8899094
yosefAlsuhaibani pushed a commit to semgrep/semgrep that referenced this pull request Oct 7, 2025
…-proprietary#4774)

In the past, Gemini CLI doesn't work with the Semgrep MCP server when we use our custom types. [Other MCP servers are also running into this error.](google-gemini/gemini-cli#6219) Gemini recently [released a fix ](google-gemini/gemini-cli#9574 this, so we should add the types back so models like GPT-5 can call our tools properly.

Fixes SAF-2262

## Test plan:

```

 ███            █████████  ██████████ ██████   ██████ █████ ██████   █████ █████
░░░███         ███░░░░░███░░███░░░░░█░░██████ ██████ ░░███ ░░██████ ░░███ ░░███
  ░░░███      ███     ░░░  ░███  █ ░  ░███░█████░███  ░███  ░███░███ ░███  ░███
    ░░░███   ░███          ░██████    ░███░░███ ░███  ░███  ░███░░███░███  ░███
     ███░    ░███    █████ ░███░░█    ░███ ░░░  ░███  ░███  ░███ ░░██████  ░███
   ███░      ░░███  ░░███  ░███ ░   █ ░███      ░███  ░███  ░███  ░░█████  ░███
 ███░         ░░█████████  ██████████ █████     █████ █████ █████  ░░█████ █████
░░░            ░░░░░░░░░  ░░░░░░░░░░ ░░░░░     ░░░░░ ░░░░░ ░░░░░    ░░░░░ ░░░░░

                                                v0.9.0-nightly.20251001.163dba7e
Tips for getting started:
1. Ask questions, edit files, or run commands.
2. Be specific for the best results.
3. Create GEMINI.md files to customize your interactions with Gemini.
4. /help for more information.

> /mcp

Configured MCP servers:

🟢 serverName - Ready (7 tools, 2 prompts)
  Tools:
  - get_abstract_syntax_tree
  - get_supported_languages
  - semgrep_findings
  - semgrep_rule_schema
  - semgrep_scan
  - semgrep_scan_supply_chain
  - semgrep_scan_with_custom_rule
  Prompts:
  - setup_semgrep_mcp
  - write_custom_semgrep_rule


💡 Tips:
  - Use /mcp desc to show server and tool descriptions
  - Use /mcp schema to show tool parameter schemas
  - Use /mcp nodesc to hide descriptions
  - Use /mcp auth <server-name> to authenticate with OAuth-enabled servers
  - Press Ctrl+T to toggle tool descriptions on/off

Using: 1 MCP server (ctrl+t to view)
╭──────────────────────────────────────────────────────────────────────────────────╮
│ >   Type your message or @path/to/file                                           │
╰──────────────────────────────────────────────────────────────────────────────────╯
~/Desktop/semgrep-proprietary          no sandbox (see   gemini-2.5-pro (100%
(katrina/mcp-types*)                   /docs)           context left)
```

Also tested that Cursor was able to call `semgrep_scan` after the change with the GPT-5 model (and that it was not able to call the tool nicely before the change)

![image.png](https://app.graphite.dev/user-attachments/assets/dd7a3921-5c61-4f48-b262-12b893a037e7.png)

synced from Pro 6ee3493829fff70665a892703aef809bf8899094
giraffe-tree pushed a commit to giraffe-tree/gemini-cli that referenced this pull request Oct 10, 2025
Co-authored-by: Gal Zahavi <38544478+galz10@users.noreply.github.com>
Co-authored-by: anthony bushong <agmsb@users.noreply.github.com>
Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
Co-authored-by: Sandy Tao <sandytao520@icloud.com>
Co-authored-by: Jacob MacDonald <jakemac@google.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: christine betts <chrstn@uw.edu>
Co-authored-by: Adam Weidman <65992621+adamfweidman@users.noreply.github.com>
Co-authored-by: matt korwel <matt.korwel@gmail.com>
Co-authored-by: Shreya Keshive <skeshive@gmail.com>
Co-authored-by: HugoMurillo <mhugorodrigo@google.com>
Co-authored-by: Shreya Keshive <shreyakeshive@google.com>
Co-authored-by: Miguel Solorio <miguelsolorio@google.com>
Co-authored-by: Christie Warwick (Wilson) <bobcatfish@gmail.com>
Co-authored-by: shrutip90 <shruti.p90@gmail.com>
cocosheng-g pushed a commit that referenced this pull request May 6, 2026
Co-authored-by: Gal Zahavi <38544478+galz10@users.noreply.github.com>
Co-authored-by: anthony bushong <agmsb@users.noreply.github.com>
Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
Co-authored-by: Sandy Tao <sandytao520@icloud.com>
Co-authored-by: Jacob MacDonald <jakemac@google.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: christine betts <chrstn@uw.edu>
Co-authored-by: Adam Weidman <65992621+adamfweidman@users.noreply.github.com>
Co-authored-by: matt korwel <matt.korwel@gmail.com>
Co-authored-by: Shreya Keshive <skeshive@gmail.com>
Co-authored-by: HugoMurillo <mhugorodrigo@google.com>
Co-authored-by: Shreya Keshive <shreyakeshive@google.com>
Co-authored-by: Miguel Solorio <miguelsolorio@google.com>
Co-authored-by: Christie Warwick (Wilson) <bobcatfish@gmail.com>
Co-authored-by: shrutip90 <shruti.p90@gmail.com>
@sripasg sripasg added the size/l A large sized PR label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/l A large sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

version >= 0.1.18 rejects MCP functions with ambiguous type info