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)
Bug: MCP tool schemas with top-level oneOf/anyOf/allOf are rejected by the Anthropic API (400)
Summary
When using an anthropic-type provider (Claude models), any MCP server that exposes a tool whose inputSchema has a top-level oneOf/anyOf/allOf combinator makes every request fail with a 400 from the Anthropic API — even the first "hello" of a fresh session, because the full tool list is sent on every call. Kimi models tolerate these schemas; the Anthropic Messages API does not.
Error
provider.api_error: 400 {"type":"error","error":{"type":"invalid_request_error",
"message":"tools.92.custom.input_schema: input_schema does not support oneOf, allOf, or anyOf at the top level"},
"request_id":"req_011CdUrw2Nqi8JkRad2CvumV"}
Steps to reproduce
- Configure an
anthropicprovider + model alias inconfig.toml(e.g.claude-sonnet-5). - Add an MCP server whose tools include a top-level combinator in
inputSchema. In my case the Higgsfield MCP server (https://mcp.higgsfield.ai/mcp) — itsvideo_analysis_createtool declares:
at the root of{ "oneOf": [ { "required": ["video_input_id"] }, { "required": ["youtube_url"] } ] }inputSchema(verified via raw JSON-RPCtools/list; it is the only one of the server's 86 tools with a root-level combinator). - Run
kimi -m claude-sonnet-5 -p "coucou"→ 400 on the very first request. The same session works fine with a Kimi model.
Expected
The CLI sanitizes/wraps tool schemas before sending them to the Anthropic API (e.g. hoisting a root-level oneOf into a plain object schema with optional properties, or dropping/replacing the offending tool with a warning), so one non-conforming MCP tool cannot brick the entire session.
Workarounds found
disabledTools: ["video_analysis_create"]on the server entry inmcp.json→ session works. ✅ (only fix that works)[tools].disabled = ["mcp__higgsfield__*"]inconfig.tomldoes not help: MCP tools are still sent on the wire despite the global tool switch. This looks like a second, related bug — the global[tools]filter does not apply to MCP tools (at least for request shaping).
Environment
- kimi-code 0.29.2
- Linux (WSL2, Ubuntu 24.04)
- Provider:
anthropic(official API, modelclaude-sonnet-5)
Happy to email a debug ZIP (kimi export) or the raw tools/list dump if useful — not attaching here since they may contain session data.
Confirmed the wire path on current main: packages/kosong/src/providers/anthropic.ts convertTool passes tool.parameters straight into input_schema with a cast, so an MCP tool whose JSON Schema opens with oneOf/anyOf/allOf (no top-level type: "object") goes to the Anthropic API as-is and gets the 400. Nothing upstream in the MCP ingestion normalizes it either.
The fix probably belongs at this provider boundary rather than in MCP ingestion, since the top-level combinator restriction is Anthropic-specific. Two shapes that keep validation semantics:
- Hoist to an object envelope: when the schema has no top-level
type, emit{type: "object", ...rest}and keep the combinator as-is underneath, which Anthropic accepts inside an object schema. - Single-member collapse only when the combinator has exactly one branch (common for MCP servers that wrap everything in a one-member
anyOf), falling back to (1) otherwise.
I can put together a PR with unit tests around convertTool for the combinator cases if that direction sounds right. The [tools].disabled half of the report reads as a separate bug (filtering happens before provider conversion but MCP tools are merged in after), so I would keep it out of that PR.
Thanks for digging into this @he-yufeng — the analysis matches what I observed on the wire.
The direction sounds right to me: fixing at the Anthropic provider boundary in convertTool, with the object-envelope hoist (option 1) as the general shape and the single-member collapse as a special case, keeps validation semantics intact and doesn't touch MCP ingestion. Happy for you to go ahead with the PR + unit tests around convertTool.
Agreed on keeping the [tools].disabled filtering issue out of that PR — I'll open a separate issue for it when I get a moment so it can be tracked on its own.
Ran the proposed fix against the two Anthropic SDK helpers before it lands, since the condition is about to become a general rule. The direction holds, and there's one shape where it trades the 400 for a silent narrowing.
The hoist works, and your motivating schema is safe. Applying {type: "object", ...rest} to video_analysis_create's schema makes betaTool() accept it, and the accept set is unchanged — every instance legal before is legal after. Same for a single-member allOf. So option 1 is the right general shape and option 2 isn't needed to preserve semantics; option 1 already covers the one-branch case.
Where it isn't lossless: a union with a branch that admits a non-object.
{ "anyOf": [ { "type": "object", "properties": { "a": { "type": "string" } } },
{ "type": "string" } ] }
Before the hoist "hello" is a legal input; after {type: "object", anyOf: [...]} it is not — the string branch is still in the document, but nothing can ever match it. betaTool() accepts both forms, so this converts a loud, precise 400 into a 200 with a tool input that quietly stopped accepting one of its two shapes. MCP servers do publish these (a tool that takes either an id string or an options object is the common one).
The condition that makes the hoist provably safe is: every branch is type: "object" — then "must be an object" is already implied by each branch and stating it changes nothing. If any branch admits a non-object, wrapping preserves it where hoisting deletes it:
{ "type": "object", "properties": { "input": <the original schema> }, "required": ["input"] }
That costs a nesting level, so it may be worth doing only for the branch-check failure and hoisting otherwise.
Two notes on the tests:
-
A test built on
video_analysis_createpasses either way. Its branches arerequired-only with no non-object member, so its accept set is identical before and after — the case that motivated the issue cannot fail on the narrowing. The regression case needs a union with an explicit non-object branch. -
This is checkable offline, no API key.
@anthropic-ai/sdk'sbetaTool({name, description, inputSchema, run})throwsJSON schema for tool "x" must be an object, but got undefinedon exactly the roots the API 400s on, soconvertTool's output can be asserted directly in a unit test. Pair it with anajv/dist/2020accept-set diff (compile before and after, run the same instances through both) — that's what surfaced the row above, and it's the assertion that catches a semantics change, since accept/reject can't: acceptance is precisely what goes right here.
One more shape hits the same !type condition: a root $ref ({"$ref": "#/$defs/T", "$defs": {...}}), which Pydantic's RootModel and zod-to-json-schema both emit by default. betaTool() rejects it for the same "no top-level type" reason, and your !type guard will catch it — worth an explicit test, and note that inlining the referenced definition is the alternative if you'd rather the model see the resolved shape.
I'm checking a small local MCP compatibility preflight against the Higgsfield/Anthropic case, alongside the provider-boundary discussion here.
On the version you use now, does video_analysis_create still block the first request? Which Kimi Code version and provider path is that, and does it affect local development, CI, or production? Is server-specific disabledTools still your workaround, and roughly how much engineering time or operational disruption does it cost currently?
Still reproducible on 2.3.2 (Kimi Code Desktop 1.1.4, Windows NT 10.0.26300.0 x64, 2026-11-03) through a custom anthropic-protocol provider — opencode.ai inference gateway, model claude-sonnet-5-5:
[provider.api_error] 400 {"type":"error","error":{"type":"invalid_request_error","message":"Upstream request failed: [invalid_request_error] tools.96.custom.input_schema: input_schema does not support oneOf, allOf, or anyOf at the top level"}}
Another affected MCP source besides the one in the OP: the managed kimi-cu-win plugin (Computer Use for Windows). Its session tools snapshot holds 121 tools, and four of them declare top-level oneOf: activate_window (#96), click (#97), get_app_state (#99), scroll (#104). The error index matches the snapshot index exactly. Example schema (activate_window):
{"type":"object","properties":{"app":{},"pid":{},"window_id":{}},"additionalProperties":false,"oneOf":[{"required":["pid"]},{"required":["app"]},{"required":["window_id"]}]}
Workaround that confirms the diagnosis: disabling the whole plugin makes the same model work (the remaining 117 tools pass validation). Per #2421, [tools].disabled can't filter these out selectively yet, so the plugin-level toggle is the only option.
One note on PR #2338: it filters incompatible tools only for the official Anthropic endpoint and leaves custom endpoints untouched. That covers the OP's case, but not custom anthropic-protocol endpoints like the opencode.ai gateway above — there the request still goes out in Anthropic Messages format and still 400s. If the filter can't be extended to those endpoints, a sanitize-at-conversion fallback (the object-envelope hoist analyzed upthread) would still be needed for that path.