| 205 | } |
| 206 | |
| 207 | function toToolInputSchema(schema: unknown): Partial<Tool['inputSchema']> { |
| 208 | if (!schema || typeof schema !== 'object' || Array.isArray(schema)) return {} |
| 209 | |
| 210 | const candidate = schema as Record<string, unknown> |
| 211 | const properties = |
| 212 | candidate.properties && |
| 213 | typeof candidate.properties === 'object' && |
| 214 | !Array.isArray(candidate.properties) |
| 215 | ? (candidate.properties as Tool['inputSchema']['properties']) |
| 216 | : {} |
| 217 | const required = Array.isArray(candidate.required) |
| 218 | ? candidate.required.filter((entry): entry is string => typeof entry === 'string') |
| 219 | : undefined |
| 220 | |
| 221 | return { |
| 222 | properties, |
| 223 | ...(required && required.length > 0 && { required }), |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | function isJsonObject(value: unknown): value is Record<string, unknown> { |
| 228 | return value !== null && typeof value === 'object' && !Array.isArray(value) |