* 处理工具调用
(clientId: string, message: MCPMessage)
| 302 | * 处理工具调用 |
| 303 | */ |
| 304 | private async handleCallTool(clientId: string, message: MCPMessage): Promise<void> { |
| 305 | const toolName = message.params?.name as string; |
| 306 | const toolArgs = message.params?.arguments as Record<string, any>; |
| 307 | |
| 308 | try { |
| 309 | const response = await this.toolManager.callTool({ |
| 310 | toolName, |
| 311 | parameters: toolArgs, |
| 312 | context: { |
| 313 | executionId: `mcp-${Date.now()}`, |
| 314 | timestamp: Date.now(), |
| 315 | }, |
| 316 | }); |
| 317 | |
| 318 | const mcpResponse: MCPToolResult = { |
| 319 | content: [ |
| 320 | { |
| 321 | type: 'text', |
| 322 | text: |
| 323 | typeof response.result.data === 'string' |
| 324 | ? response.result.data |
| 325 | : JSON.stringify(response.result.data, null, 2), |
| 326 | }, |
| 327 | ], |
| 328 | isError: !response.result.success, |
| 329 | }; |
| 330 | |
| 331 | this.sendResponse(clientId, message.id, mcpResponse); |
| 332 | } catch (error) { |
| 333 | const response: MCPToolResult = { |
| 334 | content: [ |
| 335 | { |
| 336 | type: 'text', |
| 337 | text: error instanceof Error ? error.message : String(error), |
| 338 | }, |
| 339 | ], |
| 340 | isError: true, |
| 341 | }; |
| 342 | |
| 343 | this.sendResponse(clientId, message.id, response); |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | /** |
| 348 | * 处理列出提示 |
no test coverage detected