Route an `mcp__ __ ` call to the right connection.
(toolName: string, args: Record<string, unknown>)
| 227 | |
| 228 | /** Route an `mcp__<server>__<tool>` call to the right connection. */ |
| 229 | async callTool(toolName: string, args: Record<string, unknown>): Promise<{ text: string; isError?: boolean }> { |
| 230 | const match = /^mcp__([^_]+)__(.+)$/.exec(toolName) |
| 231 | if (!match) { |
| 232 | return { text: `Invalid MCP tool name: ${toolName}`, isError: true } |
| 233 | } |
| 234 | const [, server, originalName] = match |
| 235 | const connection = this.connections.get(server) |
| 236 | if (!connection) { |
| 237 | return { text: `MCP server "${server}" is not connected.`, isError: true } |
| 238 | } |
| 239 | try { |
| 240 | return await callMcpTool(connection, originalName, args) |
| 241 | } catch (error) { |
| 242 | return { text: `MCP tool ${toolName} failed: ${(error as Error).message}`, isError: true } |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | /** True if `toolName` is an MCP tool managed by this manager. */ |
| 247 | hasTool(toolName: string): boolean { |
no test coverage detected