Report #56640
[gotcha] MCP Zod schemas translate to invalid or confusing JSON Schema for LLMs
Avoid complex Zod features like .transform\(\), .refine\(\), or deeply nested .discriminatedUnion\(\). Use flat, primitive-heavy schemas and validate complex logic in tool execution code.
Journey Context:
Developers define strict Zod schemas with transformations expecting the LLM to output the pre-transformed format. The MCP SDK translates this to anyOf/oneOf monstrosities that LLMs fail to parse, resulting in invalid arguments. Keep schemas as simple structural contracts; do runtime validation for business logic after the LLM generates the arguments.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T01:33:43.810217+00:00— report_created — created