Skip to content

fix(anthropic): omit incompatible tool schemas - #2338

Open
ousamabenyounes wants to merge 1 commit into
MoonshotAI:mainfrom
ousamabenyounes:fix/issue-2328
Open

fix(anthropic): omit incompatible tool schemas#2338
ousamabenyounes wants to merge 1 commit into
MoonshotAI:mainfrom
ousamabenyounes:fix/issue-2328

Conversation

@ousamabenyounes

Copy link
Copy Markdown

Related Issue

Resolve #2328

Problem

Anthropic rejects a request when any MCP tool has oneOf, anyOf, or allOf
at the root of its input schema. Because the complete tool list is sent with
each request, one such tool prevents even an unrelated prompt from running.

What changed

  • Detect Anthropic tool schemas with an unsupported root combinator in both
    the current and legacy provider paths.
  • Omit only incompatible tools from official Anthropic request shaping instead
    of rewriting their JSON Schema; compatible tools remain available, while
    Kimi compositions and custom compatible endpoints are unchanged.
  • Cover both provider paths, all three root combinators, compatible-tool
    retention, Kimi/custom endpoint scoping, and input immutability.

Test verification (RED → GREEN)

Real upstream provider-boundary RED; the issue also confirms that omitting the
offending tool makes the same Anthropic session work:

APIStatusError: 400 {"type":"error","error":{"type":"invalid_request_error","message":"tools.0.custom.input_schema: input_schema does not support oneOf, allOf, or anyOf at the top level"}}

Full affected suite on exact origin/main, with both new tests applied
but no production changes:

pnpm exec vitest run \
  packages/agent-core-v2/test/kosong/provider/composition.test.ts \
  packages/kosong/test/anthropic.test.ts
|kosong| test/anthropic.test.ts (291 tests | 3 failed)
|agent-core-v2| test/kosong/provider/composition.test.ts (69 tests | 3 failed)
Test Files  2 failed (2)
Tests  6 failed | 354 passed (360)

Expected: ["compatible_tool"]
Received: ["one_of_tool", "any_of_tool", "all_of_tool", "compatible_tool"]

For both explicit official URL forms, the same files received:
["incompatible_tool", "compatible_tool"].

Patched GREEN:

pnpm exec vitest run \
  packages/agent-core-v2/test/kosong/provider/composition.test.ts \
  packages/kosong/test/anthropic.test.ts
Test Files  2 passed (2)
Tests  360 passed (360)

Also passed:

  • pnpm --filter @moonshot-ai/agent-core-v2 lint:domain
  • pnpm --filter @moonshot-ai/agent-core-v2 typecheck
  • pnpm --filter @moonshot-ai/kosong typecheck

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4e9ffbb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4e9ffbb74e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

? undefined
: { ...config.providerOptions.metadata },
hooks: composeAnthropicHooks(traits),
filterUnsupportedRootSchemas: traits.length === 0 ? undefined : false,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Enable filtering for registry-created Anthropic providers

In the v2 path this option is forced to false for every provider created through ProtocolAdapterRegistry, including plain Anthropic, because resolveAdapterIdentity always appends the synthetic CONFIG_DEFAULT_HEADERS_TRAIT to traits before the contrib factory sees it. As a result, the production v2 Anthropic provider still sends root oneOf/anyOf/allOf MCP schemas to api.anthropic.com and hits the same 400 this change is meant to prevent; base the opt-out on real vendor traits/provider identity rather than traits.length.

Useful? React with 👍 / 👎.

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 provider: 400 on MCP tools with top-level oneOf/anyOf/allOf in input_schema (and [tools].disabled doesn't filter MCP tools from the wire)

1 participant