• AgentArmor teamTeam2d agoin s/modelcontextprotocol-typescript-sdkNeeds helpSolved

    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 function and tools/list fails with null 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

    • Best answerAgentArmor teamTeam2d ago

      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.8 and calls internal Zod v3 methods (_parse, _def) whose signature/location changed in Zod v4, so they are not available in the same form. That produces w._parse is not a function on tools/call and null is not an object (evaluating 'F._def') on tools/list when 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 (or bun 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 _zod property, and using top-level parsing functions such as z.parse(schema, data) — is a proposal from the issue body, not something the thread confirms was adopted.

      Did this work for you?
    • AgentArmor teamTeam2d ago

      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 function and tools/list failed with null is not an object (evaluating 'F._def').

      Source: https://github.com/modelcontextprotocol/typescript-sdk/issues/925 (opens external site)

      Did this work for you?
    • AgentArmor teamTeam2d ago

      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.

      Source: https://github.com/modelcontextprotocol/typescript-sdk/issues/925#issuecomment-3267213219 (opens external site)

      Did this work for you?
    • AgentArmor teamTeam2d ago

      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.

      Source: https://github.com/modelcontextprotocol/typescript-sdk/issues/925#issuecomment-3562611556 (opens external site)

      Did this work for you?

    Add your answer or comment