MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / handleToolsCall

Method handleToolsCall

src/mcp/session.ts:377–424  ·  view source on GitHub ↗
(request: JsonRpcRequest)

Source from the content-addressed store, hash-verified

375 }
376
377 private async handleToolsCall(request: JsonRpcRequest): Promise<void> {
378 const params = request.params as {
379 name: string;
380 arguments?: Record<string, unknown>;
381 };
382
383 if (!params || !params.name) {
384 this.transport.sendError(request.id, ErrorCodes.InvalidParams, 'Missing tool name');
385 return;
386 }
387
388 const toolName = params.name;
389 const toolArgs = toolCallArguments(params);
390 if (!toolArgs) {
391 this.transport.sendError(request.id, ErrorCodes.InvalidParams, TOOL_ARGUMENTS_NOT_OBJECT);
392 return;
393 }
394
395 const tool = tools.find((t) => t.name === toolName);
396 if (!tool) {
397 this.transport.sendError(
398 request.id,
399 ErrorCodes.InvalidParams,
400 `Unknown tool: ${toolName}`,
401 );
402 return;
403 }
404
405 if (process.env.CODEGRAPH_MCP_DEBUG) process.stderr.write(`[mcp-debug] toolsCall ${toolName} id=${String(request.id)} pre-init\n`);
406 // Before any init or dispatch, so a direct session's liveness watchdog
407 // covers this call from its start (#3250). Optional: an engine stand-in
408 // that predates the hook still serves calls.
409 this.engine.noteToolCall?.();
410 await this.retryInitIfNeeded();
411
412 if (process.env.CODEGRAPH_MCP_DEBUG) process.stderr.write(`[mcp-debug] toolsCall ${toolName} id=${String(request.id)} dispatch\n`);
413 const result = await this.engine.getToolHandler().execute(
414 toolName,
415 toolArgs,
416 this.exploreSession,
417 this.indexVersionWarnings,
418 );
419 if (process.env.CODEGRAPH_MCP_DEBUG) process.stderr.write(`[mcp-debug] toolsCall ${toolName} id=${String(request.id)} done\n`);
420 this.transport.sendResult(request.id, result);
421 // After the reply is on the wire — telemetry must never delay a tool
422 // response (in-memory increment only; see src/telemetry).
423 getTelemetry().recordUsage('mcp_tool', toolName, !result.isError, this.clientInfo);
424 }
425
426 private async handlePromptExplore(request: JsonRpcRequest): Promise<void> {
427 const query = (request.params as { query?: unknown } | undefined)?.query;

Callers 1

handleMessageMethod · 0.95

Calls 10

retryInitIfNeededMethod · 0.95
getTelemetryFunction · 0.90
toolCallArgumentsFunction · 0.85
sendErrorMethod · 0.80
noteToolCallMethod · 0.80
getToolHandlerMethod · 0.80
sendResultMethod · 0.80
recordUsageMethod · 0.80
writeMethod · 0.65
executeMethod · 0.45

Tested by

no test coverage detected