fix(opencode): sanitize array schemas missing items for all providers#20775
Open
Krishnachaitanyakc wants to merge 1 commit intoanomalyco:devfrom
Open
fix(opencode): sanitize array schemas missing items for all providers#20775Krishnachaitanyakc wants to merge 1 commit intoanomalyco:devfrom
Krishnachaitanyakc wants to merge 1 commit intoanomalyco:devfrom
Conversation
MCP servers may produce array schemas without an items property, which strict provider APIs (OpenAI, Anthropic, etc.) reject. The existing fix for this was scoped to Google/Gemini only. This extracts the array-items sanitization into a provider-agnostic pass that runs for all providers.
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Author
|
@thdxr, @adamdotdevin can I have a review on this please? |
This was referenced Apr 6, 2026
Contributor
|
Saw this bug IRL today |
Author
|
@rekram1-node @simonklee @thdxr, @adamdotdevin - sorry to bug but can you please review this? |
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.
Issue for this PR
Closes #20273
Type of change
What does this PR do?
This PR fixes a schema compatibility issue across all providers.
Some MCP servers return array schemas without an items field. That’s allowed in JSON Schema and means “any item type,” but providers like OpenAI and Anthropic reject it as invalid.
We already handled this for Gemini in ProviderTransform.schema() via sanitizeGemini(). This change pulls that logic into a shared recursive sanitization step that runs before any provider-specific transforms, so all providers get the fix.
When an array schema is missing items, we now add items: {}. Gemini’s separate behavior of defaulting items.type to "string" stays where it is.
How did you verify your code works?
bun test --timeout 30000 test/provider/transform.test.ts)"Invalid schema for function" in google-docs-mcp #20273
bun typecheck— 13/13 tasks)writeSpreadsheetschema from the issue against OpenAI, Anthropic, and Gemini modelsScreenshots / recordings
Not a UI change.
Checklist