Skip to content

fix: apply schema transformation to MCP tools for Gemini compatibility - #11968

Closed
mugnimaestra wants to merge 1 commit into
anomalyco:devfrom
mugnimaestra:fix/mcp-tools-schema-transform
Closed

fix: apply schema transformation to MCP tools for Gemini compatibility#11968
mugnimaestra wants to merge 1 commit into
anomalyco:devfrom
mugnimaestra:fix/mcp-tools-schema-transform

Conversation

@mugnimaestra

@mugnimaestramugnimaestra commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up fix to #11952 - MCP tools were bypassing the schema transformation pipeline entirely, so the nested array fix wasn't being applied to them.

Problem

PR #11952 added nested array handling to sanitizeGemini, but MCP tools still failed with Gemini because:

  1. MCP tools are created via convertMcpTool() in mcp/index.ts
  2. They were added directly to the tools object without going through ProviderTransform.schema()
  3. The nested array fix in sanitizeGemini was never applied to MCP tool schemas

Error (still occurring without this fix)

GenerateContentRequest.tools[0].function_declarations[49].parameters.properties[values].items.items: missing field.
GenerateContentRequest.tools[0].function_declarations[50].parameters.properties[values].items.items: missing field.
GenerateContentRequest.tools[0].function_declarations[54].parameters.properties[initialData].items.items: missing field.

Solution

  • Add optional model parameter to MCP.tools() and convertMcpTool() functions
  • Apply ProviderTransform.schema() to MCP tool schemas before registration
  • Pass input.model from prompt.ts to MCP.tools() call

Files Changed

FileChange
packages/opencode/src/mcp/index.tsAdd model parameter, apply schema transformation
packages/opencode/src/session/prompt.tsPass model to MCP.tools()

Testing

Verified with google-docs-mcp + Gemini 3 Flash on VPS:

Before (with only #11952 merged):

0.0.0-fix/gemini-nested-array-items-202602031444
Error: * GenerateContentRequest.tools[0].function_declarations[49].parameters.properties[values].items.items: missing field.

After (with this PR):

0.0.0-fix/mcp-tools-schema-transform-202602031607
> build · gemini-3-flash
Hello! How can I help you today?

Problematic MCP Tools (now fixed)

ToolParameterSchema
writeSpreadsheetvaluesarray<array<any>> (2D array)
appendSpreadsheetRowsvaluesarray<array<any>> (2D array)
createSpreadsheetinitialDataarray<array<any>> (2D array)

Related

MCP tools were bypassing provider-specific schema transformations,
causing Gemini API to reject tools with nested array schemas.
Changes:
- Added model parameter to MCP.tools() and convertMcpTool() functions
- Apply ProviderTransform.schema() to MCP tool schemas before registration
- Pass model context from prompt.ts to MCP.tools() call
This ensures MCP tools with 2D arrays (like google-docs-mcp spreadsheet
tools) work correctly with Gemini 3 Flash and other Gemini models.
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

@rekram1-node

Copy link
Copy Markdown
Collaborator

On your last pr you claimed u tested it manually? Now ur saying it didn't fix it...

?

@mugnimaestra

Copy link
Copy Markdown
ContributorAuthor

On your last pr you claimed u tested it manually? Now ur saying it didn't fix it...

?

I am truly sorry that was my mistake before, it was not tested enough, here I put the recording

Screen.Recording.2026-02-03.at.23.39.46.mov

hope this can help 🙇

@rekram1-node

Copy link
Copy Markdown
Collaborator

/review

@github-actions

Copy link
Copy Markdown
Contributor

lgtm

@rekram1-node

Copy link
Copy Markdown
Collaborator

@mugnimaestra can u test this:
#11984

It's a bit more minimal, keeps sanitization in the same place we sanitize the other tools

@github-actions

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@mugnimaestra@rekram1-node