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

Method handleToolsCall

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

Source from the content-addressed store, hash-verified

330 }
331
332 private async handleToolsCall(request: JsonRpcRequest): Promise<void> {
333 const params = request.params as {
334 name: string;
335 arguments?: Record<string, unknown>;
336 };
337
338 if (!params || !params.name) {
339 this.transport.sendError(request.id, ErrorCodes.InvalidParams, 'Missing tool name');
340 return;
341 }
342
343 const toolName = params.name;
344 const toolArgs = toolCallArguments(params);
345 if (!toolArgs) {
346 this.transport.sendError(request.id, ErrorCodes.InvalidParams, TOOL_ARGUMENTS_NOT_OBJECT);
347 return;
348 }
349
350 const tool = tools.find((t) => t.name === toolName);
351 if (!tool) {
352 this.transport.sendError(
353 request.id,
354 ErrorCodes.InvalidParams,
355 `Unknown tool: ${toolName}`,
356 );
357 return;
358 }
359
360 if (process.env.CODEGRAPH_MCP_DEBUG) process.stderr.write(`[mcp-debug] toolsCall ${toolName} id=${String(request.id)} pre-init\n`);
361 await this.retryInitIfNeeded();
362
363 if (process.env.CODEGRAPH_MCP_DEBUG) process.stderr.write(`[mcp-debug] toolsCall ${toolName} id=${String(request.id)} dispatch\n`);
364 const result = await this.engine.getToolHandler().execute(
365 toolName,
366 toolArgs,
367 this.exploreSession,
368 this.indexVersionWarnings,
369 );
370 if (process.env.CODEGRAPH_MCP_DEBUG) process.stderr.write(`[mcp-debug] toolsCall ${toolName} id=${String(request.id)} done\n`);
371 this.transport.sendResult(request.id, result);
372 // After the reply is on the wire — telemetry must never delay a tool
373 // response (in-memory increment only; see src/telemetry).
374 getTelemetry().recordUsage('mcp_tool', toolName, !result.isError, this.clientInfo);
375 }
376
377 /**
378 * Lazy default-project resolution. Three layers:

Callers 1

handleMessageMethod · 0.95

Calls 9

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

Tested by

no test coverage detected