fix: handle nested array items for Gemini schema validation#11952
Merged
rekram1-node merged 1 commit intoanomalyco:devfrom Feb 3, 2026
Merged
fix: handle nested array items for Gemini schema validation#11952rekram1-node merged 1 commit intoanomalyco:devfrom
rekram1-node merged 1 commit intoanomalyco:devfrom
Conversation
This extends the existing fix from PR anomalyco#5846 to handle additional edge cases: - 2D arrays (array of arrays) where inner array is missing items - Arrays with empty items objects {} that lack a type - Deeply nested array structures The fix ensures all array items have at least a default type of 'string' when no type is specified, preventing Gemini API validation errors. Fixes anomalyco#5832
Contributor
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
Collaborator
|
/review |
Contributor
|
lgtm |
ishaksebsib
pushed a commit
to ishaksebsib/opencode
that referenced
this pull request
Feb 4, 2026
ishaksebsib
pushed a commit
to ishaksebsib/opencode
that referenced
this pull request
Feb 4, 2026
dmae97
pushed a commit
to dmae97/opencode
that referenced
this pull request
Feb 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5832
Summary
Fixes Gemini API rejection of MCP tools with nested array schemas (2D arrays like
z.array(z.array(z.any()))).Problem
Gemini API rejects tools with nested array schemas where inner items are missing the
typefield.Error
Root Cause
typefield - The existing fix only handledresult.items == null, but didn't catch whenitemswas an empty object{}without a typesanitizeGeminiand other provider-specific schema transformationsSolution
1. Fixed nested array handling in
sanitizeGeminiExtended the sanitization logic to assign default type
"string"whenitemsexists but has no type:Before:
After:
2. Extended MCP.tools() to apply schema transformations
MCP tools now accept a model parameter and go through the same schema transformation pipeline as built-in tools.
Files Changed
packages/opencode/src/provider/transform.tssanitizeGeminito handle nested arrays with missing typepackages/opencode/src/mcp/index.tsMCP.tools()for schema transformationspackages/opencode/src/session/prompt.tspackages/opencode/test/provider/transform.test.tsReproduction Steps
MCP causing the issue: google-docs-mcp
Command to trigger error:
opencode run "hi" --model google/gemini-3-flashProblematic tools in the MCP:
writeSpreadsheetvaluesz.array(z.array(z.any()))appendSpreadsheetRowsvaluesz.array(z.array(z.any()))createSpreadsheetinitialDataz.array(z.array(z.any()))JSON Schema sent to Gemini (before fix):
{ "values": { "type": "array", "items": { "type": "array", "items": {} } } }The inner
items: {}has no type, which Gemini rejects.Testing
Automated Tests
Manual Verification