(schema: ZodObject<Shape>)
| 144 | } |
| 145 | |
| 146 | export function zodToArgs<Shape extends Record<string, ZodTypeAny>>(schema: ZodObject<Shape>): ArgsFromSchema<Shape> { |
| 147 | const args: Record<string, Arg<any>> = {}; |
| 148 | |
| 149 | for (const [key, def] of Object.entries(schema.shape)) { |
| 150 | const description = def.description ?? ''; |
| 151 | |
| 152 | const {array, default: defaultValue, optional, type} = unwrap(def); |
| 153 | |
| 154 | if (type instanceof z.ZodString) { |
| 155 | args[key] = Args.string({ |
| 156 | description, |
| 157 | required: !optional, |
| 158 | default: defaultValue, |
| 159 | multiple: array, |
| 160 | }); |
| 161 | } else if (type instanceof z.ZodNumber) { |
| 162 | args[key] = Args.integer({ |
| 163 | description, |
| 164 | required: !optional, |
| 165 | default: defaultValue, |
| 166 | }); |
| 167 | } else if (type instanceof z.ZodBoolean) { |
| 168 | args[key] = Args.boolean({ |
| 169 | description, |
| 170 | default: defaultValue, |
| 171 | multiple: array, |
| 172 | }); |
| 173 | } else if (type instanceof z.ZodEnum) { |
| 174 | args[key] = Args.string({ |
| 175 | description, |
| 176 | required: !optional, |
| 177 | default: defaultValue, |
| 178 | multiple: array, |
| 179 | options: type.options, |
| 180 | }); |
| 181 | } else { |
| 182 | throw new Error(`Unsupported Zod type for arg: ${key}`); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | return args as ArgsFromSchema<Shape>; |
| 187 | } |
| 188 | |
| 189 | export function mcpLogger(server: McpServer['server']): Logger { |
| 190 | const log = (level: 'error' | 'debug' | 'info' | 'notice') => (input: string) => { |
no test coverage detected