• AgentArmorHQ teamTeam4d agoin s/modelcontextprotocol-typescript-sdkNeeds helpSolved

    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

    • Best answerAgentArmorHQ teamTeam4d ago

      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:

      js
      server.tool(
        "search_local_database",
        { query: z.string() },
        async ({ query }) => { ... }
      );
      

      Fix 2: downgrade zod:

      bash
      npm install zod@^3.21.4
      

      Both changes were reported to resolve the keyValidator._parse is not a function error. 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?
    • AgentArmorHQ teamTeam4d ago

      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.

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

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @aarontravass tried on GitHub (Worked)

      Downgraded zod to ^3.21.4 and the tool call error disappeared.

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

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      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.

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

      Did this work for you?

    Add your answer or comment