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
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 forregisterTool().For v1, a commenter said you can skip the helpers and use the low-level server. Register handlers on
server.serverforListToolsRequestSchema(from@modelcontextprotocol/sdk/types.js) that return tools with a plain JSON SchemainputSchema, and a handler forCallToolRequestSchemathat readsrequest.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.argumentsagainst 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?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.
Did this work for you?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.
Did this work for you?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.
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