From 2cfd6f78f31f38b9d2c37e66db41c3c52784e27e Mon Sep 17 00:00:00 2001 From: Aaron Paterson Date: Thu, 12 Mar 2026 22:19:09 +0000 Subject: [PATCH 1/2] fix: ensure tool inputSchema includes type: "object" for non-object Zod schemas z.toJSONSchema() on z.discriminatedUnion() produces { oneOf: [...] } without a top-level type field. The MCP protocol requires inputSchema.type === "object" (spec.types.ts), so clients that validate the tools/list response reject discriminated union schemas. Since discriminated unions are always unions of object types (each variant shares a discriminator key), type: "object" is semantically correct at the top level. Spreading it before the schema output is a no-op for z.object() (already has type) and adds the required field for unions, intersections, etc. Fixes: #1643 --- packages/server/src/server/mcp.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/server/mcp.ts b/packages/server/src/server/mcp.ts index 05136f5b6..67fbaafd5 100644 --- a/packages/server/src/server/mcp.ts +++ b/packages/server/src/server/mcp.ts @@ -147,7 +147,7 @@ export class McpServer { title: tool.title, description: tool.description, inputSchema: tool.inputSchema - ? (schemaToJson(tool.inputSchema, { io: 'input' }) as Tool['inputSchema']) + ? ({ type: 'object' as const, ...schemaToJson(tool.inputSchema, { io: 'input' }) } as Tool['inputSchema']) : EMPTY_OBJECT_JSON_SCHEMA, annotations: tool.annotations, execution: tool.execution, From c624fc70a704a451837709af30c3a90bdd285e39 Mon Sep 17 00:00:00 2001 From: Aaron Paterson Date: Thu, 12 Mar 2026 22:20:31 +0000 Subject: [PATCH 2/2] add changeset --- .changeset/fix-discriminated-union-schema.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fix-discriminated-union-schema.md diff --git a/.changeset/fix-discriminated-union-schema.md b/.changeset/fix-discriminated-union-schema.md new file mode 100644 index 000000000..06b0b3927 --- /dev/null +++ b/.changeset/fix-discriminated-union-schema.md @@ -0,0 +1,5 @@ +--- +"@modelcontextprotocol/server": patch +--- + +fix: ensure tool inputSchema includes type: object for discriminated unions