(parameters: ParameterConfig[] | undefined)
| 89 | * @returns JSON Schema object |
| 90 | */ |
| 91 | export function buildInputSchema(parameters: ParameterConfig[] | undefined): { |
| 92 | type: "object"; |
| 93 | properties: Record<string, any>; |
| 94 | required?: string[]; |
| 95 | } { |
| 96 | // Convert Zod schema to JSON Schema-like format for MCP |
| 97 | const properties: Record<string, any> = {}; |
| 98 | const required: string[] = []; |
| 99 | |
| 100 | if (parameters) { |
| 101 | for (const param of parameters) { |
| 102 | const propSchema: any = { |
| 103 | description: param.description, |
| 104 | }; |
| 105 | |
| 106 | // Map type to JSON Schema type |
| 107 | switch (param.type) { |
| 108 | case "string": |
| 109 | propSchema.type = "string"; |
| 110 | break; |
| 111 | case "integer": |
| 112 | propSchema.type = "integer"; |
| 113 | break; |
| 114 | case "float": |
| 115 | propSchema.type = "number"; |
| 116 | break; |
| 117 | case "boolean": |
| 118 | propSchema.type = "boolean"; |
| 119 | break; |
| 120 | case "array": |
| 121 | propSchema.type = "array"; |
| 122 | break; |
| 123 | } |
| 124 | |
| 125 | // Add enum if allowed_values specified |
| 126 | if (param.allowed_values && param.allowed_values.length > 0) { |
| 127 | propSchema.enum = param.allowed_values; |
| 128 | } |
| 129 | |
| 130 | properties[param.name] = propSchema; |
| 131 | |
| 132 | // Track required fields |
| 133 | if (param.required !== false && param.default === undefined) { |
| 134 | required.push(param.name); |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | const schema: any = { |
| 140 | type: "object", |
| 141 | properties, |
| 142 | }; |
| 143 | |
| 144 | if (required.length > 0) { |
| 145 | schema.required = required; |
| 146 | } |
| 147 | |
| 148 | return schema; |
no outgoing calls
no test coverage detected