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

Method handleToolsCall

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

Source from the content-addressed store, hash-verified

283 }
284
285 private async handleToolsCall(request: JsonRpcRequest): Promise<void> {
286 const params = request.params as {
287 name: string;
288 arguments?: Record<string, unknown>;
289 };
290
291 if (!params || !params.name) {
292 this.transport.sendError(request.id, ErrorCodes.InvalidParams, 'Missing tool name');
293 return;
294 }
295
296 const toolName = params.name;
297 const toolArgs = params.arguments || {};
298
299 const tool = tools.find((t) => t.name === toolName);
300 if (!tool) {
301 this.transport.sendError(
302 request.id,
303 ErrorCodes.InvalidParams,
304 `Unknown tool: ${toolName}`,
305 );
306 return;
307 }
308
309 if (process.env.CODEGRAPH_MCP_DEBUG) process.stderr.write(`[mcp-debug] toolsCall ${toolName} id=${String(request.id)} pre-init\n`);
310 await this.retryInitIfNeeded();
311
312 if (process.env.CODEGRAPH_MCP_DEBUG) process.stderr.write(`[mcp-debug] toolsCall ${toolName} id=${String(request.id)} dispatch\n`);
313 const result = await this.engine.getToolHandler().execute(toolName, toolArgs, this.exploreSession);
314 if (process.env.CODEGRAPH_MCP_DEBUG) process.stderr.write(`[mcp-debug] toolsCall ${toolName} id=${String(request.id)} done\n`);
315 this.transport.sendResult(request.id, result);
316 // After the reply is on the wire — telemetry must never delay a tool
317 // response (in-memory increment only; see src/telemetry).
318 getTelemetry().recordUsage('mcp_tool', toolName, !result.isError, this.clientInfo);
319 }
320
321 /**
322 * Lazy default-project resolution. Three layers:

Callers 1

handleMessageMethod · 0.95

Calls 8

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

Tested by

no test coverage detected