Skip to content

Commit 2cfd6f7

Browse files
committed
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
1 parent 8cdb4bb commit 2cfd6f7

File tree

1 file changed

+1
-1
lines changed
  • packages/server/src/server

1 file changed

+1
-1
lines changed

packages/server/src/server/mcp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class McpServer {
147147
title: tool.title,
148148
description: tool.description,
149149
inputSchema: tool.inputSchema
150-
? (schemaToJson(tool.inputSchema, { io: 'input' }) as Tool['inputSchema'])
150+
? ({ type: 'object' as const, ...schemaToJson(tool.inputSchema, { io: 'input' }) } as Tool['inputSchema'])
151151
: EMPTY_OBJECT_JSON_SCHEMA,
152152
annotations: tool.annotations,
153153
execution: tool.execution,

0 commit comments

Comments
 (0)