( toolName: string, args: Record<string, unknown>, context: ToolContext, mcp?: McpManager, )
| 91 | } |
| 92 | |
| 93 | export async function executeTool( |
| 94 | toolName: string, |
| 95 | args: Record<string, unknown>, |
| 96 | context: ToolContext, |
| 97 | mcp?: McpManager, |
| 98 | ): Promise<ToolResult> { |
| 99 | // MCP tools are namespaced as mcp__<server>__<tool> and routed to the manager. |
| 100 | if (mcp && mcp.hasTool(toolName)) { |
| 101 | const result = await mcp.callTool(toolName, args) |
| 102 | return { text: result.text, isError: result.isError } |
| 103 | } |
| 104 | const executor = executors[toolName] |
| 105 | if (!executor) { |
| 106 | return { text: `Tool "${toolName}" is not available in OrbCode CLI.`, isError: true } |
| 107 | } |
| 108 | try { |
| 109 | return await executor(args, context) |
| 110 | } catch (error) { |
| 111 | return { text: `Tool ${toolName} failed: ${(error as Error).message}`, isError: true } |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | /** Native tools plus any MCP tools from connected servers. */ |
| 116 | export function getActiveTools(mcp?: McpManager): OpenAI.Chat.ChatCompletionTool[] { |
no test coverage detected