Skip to main content
Glama

Integration App MCP Server

Official
by membranehq
json-schema-to-zod.ts1.35 kB
import { z, ZodRawShape, ZodTypeAny } from 'zod'; export function zodFromJsonSchema(schema: any): ZodRawShape { const shape: Record<string, ZodTypeAny> = {}; if (schema?.type === 'object') { const props = schema.properties || {}; const required = new Set(schema.required || []); for (const key in props) { const field = zodTypeFromJsonSchema(props[key]); shape[key] = required.has(key) ? field : field.optional(); } } return shape; } function zodTypeFromJsonSchema(schema: any): ZodTypeAny { switch (schema?.type) { case 'string': return z.string(); case 'number': return z.number(); case 'integer': return z.number().int(); case 'boolean': return z.boolean(); case 'array': return z.array( // membrane may not have an items field on array types, let's default to string schema.items ? zodTypeFromJsonSchema(schema.items) : z.string() ); case 'object': { const shape: ZodRawShape = {}; const props = schema.properties || {}; const required = new Set(schema.required || []); for (const key in props) { const field = zodTypeFromJsonSchema(props[key]); shape[key] = required.has(key) ? field : field.optional(); } return z.object(shape); } default: return z.any(); } }

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/membranehq/mcp-server'

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