fix(opencode): sanitize MCP tool schemas for Anthropic root combinators by jelloeater-agent · Pull Request #47542 · anomalyco/opencode · GitHub
Skip to content

fix(opencode): sanitize MCP tool schemas for Anthropic root combinators - #47542

Open
jelloeater-agent wants to merge 1 commit into
anomalyco:devfrom
jelloeater-agent:anthropic-schema-sanitize
Open

fix(opencode): sanitize MCP tool schemas for Anthropic root combinators#47542
jelloeater-agent wants to merge 1 commit into
anomalyco:devfrom
jelloeater-agent:anthropic-schema-sanitize

Conversation

@jelloeater-agent

@jelloeater-agent jelloeater-agent commented Sep 5, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #47543

Type of change

  • Bug fix

What does this PR do?

Anthropic rejects a tool input_schema that uses anyOf/oneOf/allOf at the root level; these combinators are only accepted nested inside properties. MCP servers commonly emit "exactly one of these fields" patterns as root-level combinators, which then fail Anthropic validation with a 400 and take the whole tool down.

This adds a targeted sanitizeAnthropicSchema alongside the existing OpenAI sanitizer (#32489). It folds root-level combinators into the root object schema:

  • allOf (an intersection): member properties are merged and required are unioned into the root.
  • anyOf/oneOf (exclusive alternatives Anthropic can't represent): dropped so the root object stays valid without being over-constrained.
  • Everything else — including nested combinators inside properties — is preserved verbatim.

The Anthropic family is detected by the AI SDK adapter (@ai-sdk/anthropic, @ai-sdk/google-vertex/anthropic) plus GitHub Copilot only when it proxies a Claude model (Copilot also proxies GPT models, which must stay on the OpenAI path).

How did you verify your code works?

Added a focused test suite in packages/opencode/test/provider/transform.test.ts:

  • Root-level anyOf/oneOf/allOf are removed.
  • allOf branch content (properties.c) survives merged into the root.
  • Nested combinators inside properties survive unchanged.
  • Sibling keywords (pattern, etc.) and non-combinator content are preserved.

Checklist

  • I tested my changes locally
  • I did not include unrelated changes in this PR

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Sep 5, 2026
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

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

No duplicate PRs found

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

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.

Anthropic MCP tools fail when input schema uses root-level anyOf/oneOf/allOf

1 participant