McpError -32603: keyValidator._parse is not a function with MCP TypeScript SDK and zod v4
When I run a small MCP server built with @modelcontextprotocol/sdk and call a tool through a Node.js client, node ./client.js fails with "Tool call error: McpError: MCP error -32603: keyValidator._parse is not a function". My project uses zod v4. How should the schema be passed to server.tool(), or which zod version should I install?
Originally asked on GitHub: https://github.com/modelcontextprotocol/typescript-sdk/issues/291
4 answers
The issue is closed; the fixes that worked for users are to pass the tool schema as a raw shape or to pin zod to the 3.x line. The error appears when server.tool() receives a z.object({ ... }) wrapper instead of the raw shape. Users reported hitting it with zod v4.
Fix 1: pass the schema as a plain shape:
jsserver.tool( "search_local_database", { query: z.string() }, async ({ query }) => { ... } );Fix 2: downgrade zod:
bashnpm install zod@^3.21.4Both changes were reported to resolve the
keyValidator._parse is not a functionerror. One user said downgrading did not fix it for them, so the downgrade is not a guaranteed workaround in every setup.A contributor noted that the SDK itself needs to be updated to a current Zod version. When the SDK is used alongside another package that depends on newer zod, such as Vercel's AI SDK, the mismatch can cause memory leaks and crashes. In that contributor's testing, importing from zod/v3 avoided leaks and crashes but broke tool registration, while importing from zod/v4 caused a TypeScript "instantiation is excessively deep" error. Related issue #925 and pull request #869 were still open as of September 2025.
Did this work for you?What @mmdctjj tried on GitHub (Worked)
Changed the server.tool() input schema from z.object({ query: z.string() }) to the raw shape { query: z.string() }; this removed the keyValidator._parse error.
Did this work for you?What @aarontravass tried on GitHub (Worked)
Downgraded zod to ^3.21.4 and the tool call error disappeared.
Did this work for you?What @ChenKuan1110 tried on GitHub (Didn't work)
Downgraded the zod version as suggested but still got the same error, so the downgrade did not resolve it in that case.
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'?
- Use Zod union/intersection as MCP tool paramsSchema in typescript-sdk?
- MCP Inspector: "Invalid transport type: undefined" when connecting to an SSE server