Use Zod union/intersection as MCP tool paramsSchema in typescript-sdk?
In the modelcontextprotocol/typescript-sdk, registering an MCP tool types
paramsSchemaasArgs extends ZodRawShape(aRecord<string, ZodTypeAny>), which rejects a full Zod schema such asz.intersection(...)orz.union(...)as the input spec. How can I model polymorphic params, and has the SDK changed to accept aZodTypedirectly?Originally asked on GitHub: https://github.com/modelcontextprotocol/typescript-sdk/issues/588
3 answers
Fixed: the TypeScript SDK now accepts a full
ZodTypeas the tool params spec. A contributor opened PR #816 to change the typing, and confirmed in the thread that it was approved and merged (Nov 2025); the issue is closed as completed.Before that merge,
paramsSchemawas typed asArgs extends ZodRawShape(essentiallyRecord<string, ZodTypeAny>), so top-level Zod combinators likez.intersection(...)orz.union(...)could not be passed directly as the input schema.The workaround used while the issue was open: define the tool with every param optional inside the raw shape, then validate and reshape the received input inside the MCP server to the structured format you actually need. The issue author described this as the only workaround; the thread does not report anyone confirming it in production.
The issue author also pointed out that the
zod-to-json-schemadependency already accepts a fullZodSchema, which is why the typing change was expected to be straightforward. One commenter hoped the change would allow describing structured error responses field by field instead of relying on unstructured text blocks, but the thread does not confirm whether that specific use case works after the merge.Did this work for you?What @ksinder tried on GitHub (Outcome unclear)
The issue author's workaround was to define the tool with all params optional (since
ZodRawShaperequires a fixed record of fields) and then validate and reshape the input inside the MCP server to a more structured format.Source: https://github.com/modelcontextprotocol/typescript-sdk/issues/588 (opens external site)
Did this work for you?What @ksinder tried on GitHub (Worked)
A contributor opened PR #816 to allow the params spec to be a full
ZodTypeinstead ofZodRawShapeand invited feedback on the approach.Did this work for you?
Related questions
- MCP TypeScript SDK StreamableHttp without sticky sessions in multi-replica deployments?
- MCP stdio server: SyntaxError Unexpected token in deserializeMessage when using console.log
- MCP typescript-sdk: tool inputSchema/outputSchema reject JSON Schema type 'array'?
- MCP Inspector: "Invalid transport type: undefined" when connecting to an SSE server
- MCP TypeScript SDK with Zod v4 fails: `w._parse is not a function` — how to fix?