* `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, )
| 165 | * which is always the case for browserless tools. |
| 166 | */ |
| 167 | async function validateToolFiles( |
| 168 | tool: AnyToolDefinition, |
| 169 | params: Record<string, unknown>, |
| 170 | context: McpContext, |
| 171 | isLocal: boolean, |
| 172 | ): Promise<void> { |
| 173 | for (const [key, option] of Object.entries(tool.verifyFilesSchema)) { |
| 174 | if (shouldValidateFile(option, isLocal)) { |
| 175 | const allowUrl = option !== true && option.allowUrl === true; |
| 176 | const val = params[key]; |
| 177 | if (typeof val === 'string') { |
| 178 | params[key] = await validateAndResolvePathOrUrl(val, context, allowUrl); |
| 179 | } else if (Array.isArray(val)) { |
| 180 | const updated: unknown[] = []; |
| 181 | for (const item of val) { |
| 182 | if (typeof item === 'string') { |
| 183 | const resolved = await validateAndResolvePathOrUrl( |
| 184 | item, |
| 185 | context, |
| 186 | allowUrl, |
| 187 | ); |
| 188 | if (resolved !== undefined) { |
| 189 | updated.push(resolved); |
| 190 | } |
| 191 | } else { |
| 192 | throw new Error( |
| 193 | 'Unexpected non-string value as a file path or URL', |
| 194 | ); |
| 195 | } |
| 196 | } |
| 197 | params[key] = updated; |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | function toInputJsonSchema(schema: zod.ZodType): unknown { |
| 204 | return zod.toJSONSchema(schema, {io: 'input', unrepresentable: 'any'}); |
no test coverage detected