MCP TypeScript SDK with Zod v4 fails: `w._parse is not a function` — how to fix?
When using @modelcontextprotocol/typescript-sdk v1.17.5 with Zod v4.1.5 on Bun v1.2.21 (macOS), tools/call fails with
w._parse is not a functionand tools/list fails withnull is not an object (evaluating 'F._def'). The SDK hard-depends on Zod v3 and calls internals that changed in Zod v4. Is there a way to use the MCP TypeScript SDK with Zod v4?Originally asked on GitHub: https://github.com/modelcontextprotocol/typescript-sdk/issues/925
4 answers
The issue is resolved: the thread is closed as completed, and a contributor announced a beta release (tag 1.23.0-beta.0) that adds backwards-compatible support for Zod v4. The root cause is that SDK v1.17.5 hard-depends on
zod^3.23.8and calls internal Zod v3 methods (_parse,_def) whose signature/location changed in Zod v4, so they are not available in the same form. That producesw._parse is not a functionontools/callandnull is not an object (evaluating 'F._def')ontools/listwhen a Zod v4 schema is used.To get Zod v4 working, upgrade to the beta release tagged 1.23.0-beta.0; a contributor asked for feedback on it, and no test results are recorded in the thread. If you must stay on v1.17.5, the only workaround stated in the issue is pinning Zod v3:
npm install zod@3.23.8(orbun add zod@3.23.8).A contributor also linked PR #869 as a proposed fix ("should fix this"), but the thread does not confirm it. The reporter's suggested solution — widening the peer dependency to
^3.25.0 || ^4.0.0, detecting Zod v4 via the_zodproperty, and using top-level parsing functions such asz.parse(schema, data)— is a proposal from the issue body, not something the thread confirms was adopted.Did this work for you?What @zx8086 tried on GitHub (Didn't work)
Reporter installed zod@4.1.5 with MCP SDK v1.17.5 on Bun v1.2.21 and ran a minimal server with a Zod input schema; tools/call failed with
w._parse is not a functionand tools/list failed withnull is not an object (evaluating 'F._def').Source: https://github.com/modelcontextprotocol/typescript-sdk/issues/925 (opens external site)
Did this work for you?What @ochafik tried on GitHub (Outcome unclear)
A contributor linked PR #869, stating it "should fix this"; no confirmation or test results are in the thread.
Did this work for you?What @felixweinberger tried on GitHub (Outcome unclear)
A contributor announced beta release 1.23.0-beta.0 with backwards-compatible Zod v4 support and asked for feedback; no one in the thread reported whether it works.
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