From 26d3403d5ae32f880506958dbbf45fa88f5248d6 Mon Sep 17 00:00:00 2001 From: saravanakumardb1 Date: Thu, 5 Mar 2026 12:09:38 -0800 Subject: [PATCH] fix(mcp-server): zodToJsonSchema emits correct JSON type for number/boolean/array fields (was always string) --- .../mcp-server/src/modules/tools/registry.ts | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/services/mcp-server/src/modules/tools/registry.ts b/services/mcp-server/src/modules/tools/registry.ts index ede169b0..9709f67e 100644 --- a/services/mcp-server/src/modules/tools/registry.ts +++ b/services/mcp-server/src/modules/tools/registry.ts @@ -33,14 +33,17 @@ function zodToJsonSchema(schema: ZodTypeAny): Record { for (const [key, field] of Object.entries(shape)) { const fieldDef = ( field as unknown as { - _def: { typeName: string; description?: string; innerType?: unknown }; + _def: { + typeName: string; + description?: string; + innerType?: { _def: { typeName: string } }; + }; } )._def; const isOptional = fieldDef.typeName === 'ZodOptional'; - properties[key] = { - type: 'string', - description: fieldDef.description ?? key, - }; + const innerTypeName = isOptional ? fieldDef.innerType?._def.typeName : fieldDef.typeName; + const jsonType = zodTypeNameToJsonType(innerTypeName ?? ''); + properties[key] = { type: jsonType, description: fieldDef.description ?? key }; if (!isOptional) required.push(key); } return { type: 'object', properties, required }; @@ -50,3 +53,10 @@ function zodToJsonSchema(schema: ZodTypeAny): Record { } return { type: 'object' }; } + +function zodTypeNameToJsonType(typeName: string): string { + if (typeName === 'ZodNumber' || typeName === 'ZodCoerce') return 'number'; + if (typeName === 'ZodBoolean') return 'boolean'; + if (typeName === 'ZodArray') return 'array'; + return 'string'; // ZodString, ZodEnum, ZodLiteral, unknown +}