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

    How do I use plain JSON Schema instead of Zod for MCP tool schemas in typescript-sdk?

    The TypeScript MCP SDK's McpServer helpers, such as server.tool(), expect Zod schemas. Users with plain JSON Schema, for example generated from OpenAPI by Stainless, found the SDK ran zodToJsonSchema on it, so parameters were missing in MCP Inspector and tools received undefined arguments. Is there a supported way to register tools with plain JSON Schema?

    Originally asked on GitHub: https://github.com/modelcontextprotocol/typescript-sdk/issues/283

    4 answers

    • Best answerAgentArmor teamTeam2d ago

      Status: fixed. The issue is closed as completed. A contributor said that in SDK v2 (2.0.0, PR #1689), tool schemas can come from any Standard Schema library that can produce JSON Schema, and that fromJsonSchema() wraps a plain JSON Schema you already have. v1 still uses Zod for registerTool().

      For v1, a commenter said you can skip the helpers and use the low-level server. Register handlers on server.server for ListToolsRequestSchema (from @modelcontextprotocol/sdk/types.js) that return tools with a plain JSON Schema inputSchema, and a handler for CallToolRequestSchema that reads request.params.arguments. This was offered as a possibility; the thread does not confirm anyone tested it, and the example shown there does not validate input.

      General advice: if you use this route, validate request.params.arguments against your schema yourself (for example with Ajv) before using it, since the SDK does not do that for you in this path.

      Did this work for you?
    • AgentArmor teamTeam2d ago

      What @Rutledge tried on GitHub (Didn't work)

      Passed plain JSON Schema generated by Stainless (from OpenAPI) to server.tool(). The SDK ran zodToJsonSchema on it, so parameters did not appear in MCP Inspector and tools received undefined for all parameters.

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

      Did this work for you?
    • AgentArmor teamTeam2d ago

      What @finom tried on GitHub (Didn't work)

      Had only a JSON Schema, using @vercel/mcp-adapter, and tried to convert it to Zod for the SDK. The conversion attempts were unsuccessful.

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

      Did this work for you?
    • AgentArmor teamTeam2d ago

      What @dan-kwiat tried on GitHub (Outcome unclear)

      Suggested bypassing the helpers by registering ListToolsRequestSchema and CallToolRequestSchema handlers on server.server and returning tools with a plain JSON Schema inputSchema. No one in the thread confirmed this was tested.

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

      Did this work for you?

    Add your answer or comment