(inputFormat: InputFormatField[])
| 137 | * that MCP clients can use to understand tool parameters. |
| 138 | */ |
| 139 | export function generateToolInputSchema(inputFormat: InputFormatField[]): McpToolInputSchema { |
| 140 | const properties: Record<string, McpToolProperty> = {} |
| 141 | const required: string[] = [] |
| 142 | |
| 143 | for (const field of inputFormat) { |
| 144 | if (!field.name) continue |
| 145 | |
| 146 | const fieldName = field.name |
| 147 | const fieldType = mapFieldTypeToJsonSchemaType(field.type) |
| 148 | |
| 149 | const property: McpToolProperty = { |
| 150 | type: fieldType, |
| 151 | // Use custom description if provided, otherwise use field name |
| 152 | description: field.description?.trim() || fieldName, |
| 153 | } |
| 154 | |
| 155 | // Handle array types |
| 156 | if (fieldType === 'array') { |
| 157 | if (field.type === 'file[]') { |
| 158 | property.items = { |
| 159 | type: 'object', |
| 160 | properties: { |
| 161 | name: { type: 'string', description: 'File name' }, |
| 162 | url: { type: 'string', description: 'File URL' }, |
| 163 | type: { type: 'string', description: 'MIME type' }, |
| 164 | size: { type: 'number', description: 'File size in bytes' }, |
| 165 | }, |
| 166 | } |
| 167 | // Use custom description if provided, otherwise use default |
| 168 | if (!field.description?.trim()) { |
| 169 | property.description = 'Array of file objects' |
| 170 | } |
| 171 | } else { |
| 172 | property.items = { type: 'string' } |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | properties[fieldName] = property |
| 177 | |
| 178 | // All fields are considered required by default |
| 179 | // (in the future, we could add an optional flag to InputFormatField) |
| 180 | required.push(fieldName) |
| 181 | } |
| 182 | |
| 183 | return { |
| 184 | type: 'object', |
| 185 | properties, |
| 186 | required: required.length > 0 ? required : undefined, |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Overlay sparse per-parameter description overrides onto a base schema produced by |
no test coverage detected