* `isLocal` tells whether files are accessed on the machine the server runs on, * which is always the case for browserless tools.
( tool: AnyToolDefinition, params: Record<string, unknown>, context: McpContext, isLocal: boolean, )
| 190 | * which is always the case for browserless tools. |
| 191 | */ |
| 192 | async function validateToolFiles( |
| 193 | tool: AnyToolDefinition, |
| 194 | params: Record<string, unknown>, |
| 195 | context: McpContext, |
| 196 | isLocal: boolean, |
| 197 | ): Promise<void> { |
| 198 | for (const [key, option] of Object.entries(tool.verifyFilesSchema)) { |
| 199 | if (shouldValidateFile(option, isLocal)) { |
| 200 | const allowUrl = option !== true && option.allowUrl === true; |
| 201 | const val = params[key]; |
| 202 | if (typeof val === 'string') { |
| 203 | params[key] = await validateAndResolvePathOrUrl(val, context, allowUrl); |
| 204 | } else if (Array.isArray(val)) { |
| 205 | const updated: unknown[] = []; |
| 206 | for (const item of val) { |
| 207 | if (typeof item === 'string') { |
| 208 | const resolved = await validateAndResolvePathOrUrl( |
| 209 | item, |
| 210 | context, |
| 211 | allowUrl, |
| 212 | ); |
| 213 | if (resolved !== undefined) { |
| 214 | updated.push(resolved); |
| 215 | } |
| 216 | } else { |
| 217 | throw new Error( |
| 218 | 'Unexpected non-string value as a file path or URL', |
| 219 | ); |
| 220 | } |
| 221 | } |
| 222 | params[key] = updated; |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | function toInputJsonSchema(schema: zod.ZodType): unknown { |
| 229 | return zod.toJSONSchema(schema, {io: 'input', unrepresentable: 'any'}); |
no test coverage detected