| 51 | } |
| 52 | |
| 53 | function schemaToCLIOptions(toolName: string, schema: JsonSchema): CliOption[] { |
| 54 | if (!schema || !schema.properties) { |
| 55 | return []; |
| 56 | } |
| 57 | const required = schema.required || []; |
| 58 | const properties = schema.properties; |
| 59 | return Object.entries(properties).map(([name, prop]) => { |
| 60 | const isRequired = required.includes(name); |
| 61 | const description = prop.description || ''; |
| 62 | if (typeof prop.type !== 'string') { |
| 63 | throw new Error( |
| 64 | `Property ${name} has a complex type not supported by CLI.`, |
| 65 | ); |
| 66 | } |
| 67 | return { |
| 68 | name, |
| 69 | type: prop.type, |
| 70 | description, |
| 71 | required: isRequired, |
| 72 | positional: |
| 73 | isRequired || OPTIONAL_POSITIONAL_ARGS.has(`${toolName}:${name}`), |
| 74 | minItems: prop.minItems, |
| 75 | default: prop.default, |
| 76 | enum: prop.enum, |
| 77 | }; |
| 78 | }); |
| 79 | } |
| 80 | |
| 81 | async function generateCli() { |
| 82 | const cliDefaults = ServerConfig.applyDefaults( |