Skip to main content
Glama

workflows-mcp

by FiveOhhWon
zod-to-json-schema.tsโ€ข1.75 kB
import { z } from 'zod'; /** * Convert a Zod schema to JSON Schema format for MCP SDK */ export function zodToJsonSchema(schema: z.ZodType<any>): any { if (schema instanceof z.ZodObject) { const shape = schema.shape; const properties: Record<string, any> = {}; const required: string[] = []; for (const [key, value] of Object.entries(shape)) { properties[key] = zodToJsonSchema(value as z.ZodType<any>); // Check if field is required (not optional) if (!(value instanceof z.ZodOptional)) { required.push(key); } } return { type: 'object', properties, ...(required.length > 0 ? { required } : {}), }; } if (schema instanceof z.ZodArray) { return { type: 'array', items: zodToJsonSchema(schema.element), }; } if (schema instanceof z.ZodString) { return { type: 'string' }; } if (schema instanceof z.ZodNumber) { return { type: 'number' }; } if (schema instanceof z.ZodBoolean) { return { type: 'boolean' }; } if (schema instanceof z.ZodEnum) { return { type: 'string', enum: schema.options, }; } if (schema instanceof z.ZodOptional) { return zodToJsonSchema(schema.unwrap()); } if (schema instanceof z.ZodDefault) { const innerSchema = zodToJsonSchema(schema._def.innerType); return { ...innerSchema, default: schema._def.defaultValue(), }; } if (schema instanceof z.ZodRecord) { return { type: 'object', additionalProperties: zodToJsonSchema((schema as any)._def.valueType), }; } if (schema instanceof z.ZodAny) { return {}; // Any type - no schema validation } // Fallback for unknown types return {}; }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/FiveOhhWon/workflows-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server