MCPcopy Create free account
hub / github.com/ChromeDevTools/chrome-devtools-mcp / validateToolFiles

Function validateToolFiles

src/ToolHandler.ts:192–226  ·  view source on GitHub ↗

* `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,
)

Source from the content-addressed store, hash-verified

190 * which is always the case for browserless tools.
191 */
192async 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
228function toInputJsonSchema(schema: zod.ZodType): unknown {
229 return zod.toJSONSchema(schema, {io: 'input', unrepresentable: 'any'});

Callers 2

#runBrowserlessToolMethod · 0.85
#runBrowserToolMethod · 0.85

Calls 2

shouldValidateFileFunction · 0.85

Tested by

no test coverage detected