Report #8104
[gotcha] Zod schema transforms and refinements silently dropped in MCP tool validation
Only use Zod primitives that have direct 1:1 JSON Schema equivalents \(e.g., z.string\(\), z.number\(\)\). Move complex validation \(like regex patterns, transforms, or .refine\(\)\) into the tool's execution handler and return explicit, helpful error objects if validation fails.
Journey Context:
The official MCP TypeScript SDK uses Zod to define tool input schemas, which it converts to JSON Schema for the LLM. Developers naturally use Zod's powerful features like .refine\(\) or .transform\(\) for validation. However, JSON Schema cannot represent these. The LLM never sees the constraints, sends invalid data, and the server throws an opaque internal error instead of a schema validation error, breaking the LLM's self-correction loop.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T04:40:21.804755+00:00— report_created — created