API Error 400: input_schema does not support oneOf/allOf/anyOf at top level

Back to board
Environment @weppy/roblox-mcp version: 2.6.2 Claude Code version: latest (v2.0.21+) OS: Windows 11 Pro Error API Error: 400 { "type": "error", "error": { "type": "invalid_request_error", "message": "tools.11.custom.input_schema: input_schema does not support oneOf, allOf, or anyOf at the top level" }, "request_id": "req_011CaGxtvAUQiBi6MR8jFBWU" } Root Cause Claude Code v2.0.21 introduced strict MCP schema validation that mirrors an Anthropic API restriction: oneOf, allOf, and anyOf are not allowed at the top level of a tool's inputSchema. Weppy uses Zod to define tool parameters. Zod's z.union() and z.intersection() types are serialized by zod-to-json-schema as top-level oneOf or allOf. When Claude Code sends these schemas to the Anthropic API, the entire request is rejected with a 400 error — meaning no weppy tools are available at all. Inspection of the bundled dist/index.js shows 17 occurrences of "oneOf"/"allOf"/"anyOf", confirming multiple tools are affected. The error message tools.11 (0-indexed) identifies the 12th tool as the first to fail. Related Claude Code issue: https://github.com/anthropics/claude-code/issues/40075 Steps to Reproduce Configure @weppy/roblox-mcp in Claude Code's mcp.json Start any Claude Code session — the error fires immediately during tool schema registration, before any tool is called Expected Behavior All weppy MCP tools register successfully without API errors. Current Workaround A stdio proxy shim that intercepts tools/list responses and flattens top-level oneOf/allOf/anyOf into a merged { type: "object", properties: { ...merged } }: function flattenTopLevel(schema) { for (const kw of ["oneOf", "allOf", "anyOf"]) { if (kw in schema) { const variants = schema[kw]; const rest = Object.fromEntries(Object.entries(schema).filter(([k]) => k !== kw)); if (Array.isArray(variants) && Object.keys(rest).length === 0) { const merged = { type: "object", properties: {}, required: [] }; for (const v of variants) { if (v.properties) Object.assign(merged.properties, v.properties); if (v.required) merged.required.push(...v.required); } if (merged.required.length === 0) delete merged.required; return merged; } delete schema[kw]; if (!schema.type) schema.type = "object"; } } return schema; } Suggested Fix For any Zod schema that produces a top-level oneOf/allOf/anyOf, either: Refactor to flat object schemas — replace z.union([z.object({...}), z.object({...})]) with z.object({ ...mergedFields }) using optional fields where needed Post-process generated JSON Schema — after calling zodToJsonSchema(), walk the output and lift nested schemas when the top level is purely oneOf/allOf/anyOf Option 2 can be applied in one central place before registering tools with the MCP SDK.