Skip to content

fix(opencode): sanitize array schemas missing items for all providers#20775

Open
Krishnachaitanyakc wants to merge 1 commit intoanomalyco:devfrom
Krishnachaitanyakc:fix/array-schema-missing-items
Open

fix(opencode): sanitize array schemas missing items for all providers#20775
Krishnachaitanyakc wants to merge 1 commit intoanomalyco:devfrom
Krishnachaitanyakc:fix/array-schema-missing-items

Conversation

@Krishnachaitanyakc
Copy link
Copy Markdown

@Krishnachaitanyakc Krishnachaitanyakc commented Apr 3, 2026

Issue for this PR

Closes #20273

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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?

  • All 129 existing + new unit tests pass (bun test --timeout 30000 test/provider/transform.test.ts)
  • Added 8 new tests covering: OpenAI/Anthropic models, nested arrays, 3D arrays, arrays inside objects, combiner exclusion, and the exact schema from issue
    "Invalid schema for function" in google-docs-mcp #20273
  • Typecheck passes (bun typecheck — 13/13 tasks)
  • Prettier passes
  • Manual verification with the exact writeSpreadsheet schema from the issue against OpenAI, Anthropic, and Gemini models

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

  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.
@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Apr 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@Krishnachaitanyakc
Copy link
Copy Markdown
Author

@thdxr, @adamdotdevin can I have a review on this please?

@mharris717
Copy link
Copy Markdown
Contributor

Saw this bug IRL today

@Krishnachaitanyakc
Copy link
Copy Markdown
Author

@rekram1-node @simonklee @thdxr, @adamdotdevin - sorry to bug but can you please review this?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Invalid schema for function" in google-docs-mcp

2 participants