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

Method handleToolsCall

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

Source from the content-addressed store, hash-verified

259 }
260
261 private async handleToolsCall(request: JsonRpcRequest): Promise<void> {
262 const params = request.params as {
263 name: string;
264 arguments?: Record<string, unknown>;
265 };
266
267 if (!params || !params.name) {
268 this.transport.sendError(request.id, ErrorCodes.InvalidParams, 'Missing tool name');
269 return;
270 }
271
272 const toolName = params.name;
273 const toolArgs = params.arguments || {};
274
275 const tool = tools.find((t) => t.name === toolName);
276 if (!tool) {
277 this.transport.sendError(
278 request.id,
279 ErrorCodes.InvalidParams,
280 `Unknown tool: ${toolName}`,
281 );
282 return;
283 }
284
285 if (process.env.CODEGRAPH_MCP_DEBUG) process.stderr.write(`[mcp-debug] toolsCall ${toolName} id=${String(request.id)} pre-init\n`);
286 await this.retryInitIfNeeded();
287
288 if (process.env.CODEGRAPH_MCP_DEBUG) process.stderr.write(`[mcp-debug] toolsCall ${toolName} id=${String(request.id)} dispatch\n`);
289 const result = await this.engine.getToolHandler().execute(toolName, toolArgs);
290 if (process.env.CODEGRAPH_MCP_DEBUG) process.stderr.write(`[mcp-debug] toolsCall ${toolName} id=${String(request.id)} done\n`);
291 this.transport.sendResult(request.id, result);
292 // After the reply is on the wire — telemetry must never delay a tool
293 // response (in-memory increment only; see src/telemetry).
294 getTelemetry().recordUsage('mcp_tool', toolName, !result.isError, this.clientInfo);
295 }
296
297 /**
298 * 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.45

Tested by

no test coverage detected