(request: JsonRpcRequest)
| 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: |
no test coverage detected