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