Skip to content

ListTools request handler fails to generate inputSchema (jsonSchema) #1028

Closed

Description

@juanlluva

Describe the bug

When a tool - either with or without an input schema - is registered onto the mcp server, it gets registered correctly with its input schema being a ZodObject ({type: 'object', shape: <accessor>}), the server starts and the MCP inspector is able to connect to it.
When a list tools request is sent from the mcp inspector, all toolDefinitions are generated, converting the existing tool inputSchema (Zod) into a jsonSchema. However, despite the shape and type of the zod input schema, the zodToJsonSchema function always returns {type: "string", $schema: "http://json-schema.org/draft-07/schema#"}. This turns into an error on the MCP inspector, being unable to list tools, thus unable to execute any of them.

To Reproduce
Steps to reproduce the behavior:

  1. Create an instance of McpServer:
server = new McpServer({...serverInfo}, {
      capabilities,
      instructions,
    });
  1. Register a tool with an inputSchema:
server.registerTool(
      name,
      {
        title: name,
        description: description,
        inputSchema: z.object({...schema}).shape,
      },
      handler,
    );
  1. Start MCP inspector
  2. Connect to MCP server from inspector
  3. Try to list tools
  4. Get the error:
Uncaught (in promise) ZodError: [
  {
    "received": "string",
    "code": "invalid_literal",
    "expected": "object",
    "path": [
      "tools",
      0,
      "inputSchema",
      "type"
    ],
    "message": "Invalid literal value, expected \"object\""
  }
]

Expected behavior
The input Schema of the tool should be converted into a valid, matching jsonSchema.

Additional Context
Debugging the application, I could see that the zodToJsonSchema function calls the parseDef function with the zod definition. When the jsonSchemaOrGetterconstant gets calculated through the selectParser function, it passes def, def.typeName and refs. The second argument is undefined. Then teh selectParser function switches typeName on all possible ZodFirstPartyTypeKind.<ZodType>. However, ZodFirstPartyTypeKind is {}, so the first one matches, which is the string matcher.

I have @modelcontextprotocol/sdk@1.20.0 dependency installed.

Activity

  1. juanlluvallord commented on Oct 16, 2025

    @juanlluvallord

    This seemed to be an incompatibility with the installed Zod version (zod4). Sorry for the inconvenience 😅

  2. timurguvenkaya commented on Oct 16, 2025

    @timurguvenkaya

    Same issue here. Also doesn't work with import { z } from 'zod/v3';

  3. felixweinberger commented on Oct 17, 2025

    @felixweinberger
    Contributor

    Related: #869

    Currently trying to figure out the path to supporting zod v4

  4. linked a pull request that will close this issuefeat: zod v4 #869on Oct 17, 2025
  5. added
    ready for workEnough information for someone to start working on
    P1Significant bug affecting many users, highly requested feature
    on Oct 17, 2025
  6. max-rousseau commented on Nov 24, 2025

    @max-rousseau

    Anyone seen any movement on this issue or is it tied to the 'v2' work now? As far as I can tell, this makes the tools, like filesystem, unusable.

  7. domdomegg commented on Nov 25, 2025

    @domdomegg
    Member

    I think underlying this is #555. I think the solution might be to use https://github.com/modelcontextprotocol/typescript-sdk/releases/tag/1.23.0-beta.0 which has backwards-compatible support for Zod 4.

  8. RahulLanjewar93 commented on Dec 2, 2025

    @RahulLanjewar93

    Same issue, in mcp insepctor i get the same error as mentioned in the issue description
    However i am also getting a typescript error when i use the code mentioned in example.
    Attaching image below, using zod@4.1.13 and @modelcontextprotocol/sdk@1.23.0

    Image

    The error mentioned in the issue is fixed by using the below code. But typescript error is still there.

    Image

    If anyone has insights on how to fix this, please let me know. Thanks in advance :)

  9. ghost added
    potentially closeBot recommends closing — needs maintainer review
    on Apr 16, 2026
  10. felixweinberger commented on Oct 5, 2026

    @felixweinberger
    Contributor

    Fixed by #1040, released in 1.23.0. v2 takes schemas through Standard Schema and needs zod 4.2 or newer. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Significant bug affecting many users, highly requested featurebugSomething isn't workingpotentially closeBot recommends closing — needs maintainer reviewready for workEnough information for someone to start working on

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions