[PR #11968] fix: apply schema transformation to MCP tools for Gemini compatibility #14004

Open
opened 2026-02-16 18:18:49 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/11968

State: open
Merged: No


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

File Change
packages/opencode/src/mcp/index.ts Add model parameter, apply schema transformation
packages/opencode/src/session/prompt.ts Pass 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)

Tool Parameter Schema
writeSpreadsheet values array<array<any>> (2D array)
appendSpreadsheetRows values array<array<any>> (2D array)
createSpreadsheet initialData array<array<any>> (2D array)

Related

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11968 **State:** open **Merged:** No --- ## 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 | File | Change | |------|--------| | `packages/opencode/src/mcp/index.ts` | Add model parameter, apply schema transformation | | `packages/opencode/src/session/prompt.ts` | Pass 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) | Tool | Parameter | Schema | |------|-----------|--------| | `writeSpreadsheet` | `values` | `array<array<any>>` (2D array) | | `appendSpreadsheetRows` | `values` | `array<array<any>>` (2D array) | | `createSpreadsheet` | `initialData` | `array<array<any>>` (2D array) | ## Related - Fixes the remaining issue from #5832 - Follow-up to #11952
yindo added the pull-request label 2026-02-16 18:18:49 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14004