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

Method handle

src/ToolHandler.ts:486–602  ·  view source on GitHub ↗

* Cancellation stops waiting for a result, but running work keeps its queue * until it settles, including response processing, to preserve serialization. * Operations without cancellation support can keep the queue indefinitely.

(
    rawArgs: Record<string, unknown> = {},
    options?: {viaMcp?: boolean; signal?: AbortSignal},
  )

Source from the content-addressed store, hash-verified

484 * Operations without cancellation support can keep the queue indefinitely.
485 */
486 async handle(
487 rawArgs: Record<string, unknown> = {},
488 options?: {viaMcp?: boolean; signal?: AbortSignal},
489 ): Promise<CallToolResult> {
490 const signal = options?.signal ?? new AbortController().signal;
491 signal.throwIfAborted();
492 const context = await raceWithSignal(this.getContext(), signal);
493 let queueGuard: Disposable | undefined;
494 try {
495 queueGuard = await this.#queueFor(context, rawArgs)?.scheduleTask(signal);
496 } catch (err) {
497 signal.throwIfAborted();
498 // The queue was disposed while the call waited, e.g. the page closed.
499 return errorResult(getErrorMessage(err));
500 }
501 using guard = new DisposableStack();
502 guard.use(queueGuard);
503 signal.throwIfAborted();
504 if (options?.viaMcp && this.#disabled) {
505 throw new ProtocolError(
506 ProtocolErrorCode.InvalidParams,
507 `Tool ${this.#tool.name} disabled`,
508 );
509 }
510
511 if (this.#disabledReason) {
512 return errorResult(this.#disabledReason);
513 }
514
515 const tool = this.#tool;
516 const parseResult = this.#registeredInputSchema.safeParse(rawArgs);
517 if (!parseResult.success) {
518 return errorResult(formatValidationError(tool.name, parseResult.error));
519 }
520 const params = parseResult.data;
521
522 const startTime = Date.now();
523 let success = false;
524 let devToolsData: DevToolsData | undefined;
525 let pageUrl: string | undefined;
526 try {
527 logger?.(`${tool.name} request: ${JSON.stringify(params, null, ' ')}`);
528 const response = isSlimTool(tool)
529 ? new SlimMcpResponse(this.#config)
530 : new McpResponse(this.#config);
531 // The execution owns the queue even when its caller stops waiting.
532 const execution = isBrowserlessTool(tool)
533 ? this.#runBrowserlessTool(tool, params, response, context, signal)
534 : this.#runBrowserTool(
535 tool,
536 params,
537 response,
538 context,
539 signal,
540 (data, url) => {
541 devToolsData = data;
542 pageUrl = url;
543 },

Callers 15

callToolMethod · 0.45
#registerToolMethod · 0.45
#runBrowserlessToolMethod · 0.45
#runBrowserToolMethod · 0.45
McpContext.test.tsFile · 0.45
input.test.tsFile · 0.45
configureFunction · 0.45

Calls 14

#queueForMethod · 0.95
#runBrowserlessToolMethod · 0.95
#runBrowserToolMethod · 0.95
raceWithSignalFunction · 0.85
errorResultFunction · 0.85
getErrorMessageFunction · 0.85
formatValidationErrorFunction · 0.85
loggerFunction · 0.85
isSlimToolFunction · 0.85
isBrowserlessToolFunction · 0.85
logToolInvocationMethod · 0.80
getMethod · 0.80

Tested by 2

configureFunction · 0.36