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

Function validateToolFiles

src/ToolHandler.ts:167–201  ·  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

165 * which is always the case for browserless tools.
166 */
167async 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
203function toInputJsonSchema(schema: zod.ZodType): unknown {
204 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