Added add command for /mcp on tui.

This commit is contained in:
famez
2026-02-08 19:43:23 +01:00
parent 86f437b0f6
commit 6cd91830b6
2 changed files with 46 additions and 3 deletions

View File

@@ -2453,6 +2453,42 @@ Be concise. Use the actual data from notes."""
await self.push_screen(MCPScreen(mcp_manager=self.mcp_manager))
except Exception:
pass
elif action.startswith("add"):
from ..tools import get_all_tools, register_tool_instance
args = rest[len("add"):].strip()
# Parse the args string into individual components
parts = args.split()
if len(parts) < 2:
self._add_system("Usage: /mcp add <name> <command> [args...]")
return
name = parts[0]
command = parts[1]
mcp_args = parts[2:] if len(parts) > 2 else []
self.mcp_manager.add_server(
name=name,
command=command,
args=mcp_args,
)
server = await self.mcp_manager.connect_server(name)
self.mcp_server_count = len(self.mcp_manager.list_configured_servers())
tools = self.mcp_manager.create_mcp_tools_from_server(server)
self.agent.add_tools(tools)
for tool in tools:
register_tool_instance(tool)
self.all_tools = get_all_tools()
self._update_header()
if not action:
self._add_system("Error: No action provided. Usage: /mcp <command>")

View File

@@ -158,6 +158,14 @@ class MCPManager:
}
for n, s in servers.items()
]
def create_mcp_tools_from_server(self, server: MCPServer) -> List["Tool"]:
all_tools = []
for tool_def in server.tools:
tool = create_mcp_tool(tool_def, server, self)
all_tools.append(tool)
return all_tools
async def connect_all(self) -> List["Tool"]:
servers_config = self._load_config()
@@ -168,9 +176,8 @@ class MCPManager:
server = await self._connect_server(config)
if server:
self.servers[name] = server
for tool_def in server.tools:
tool = create_mcp_tool(tool_def, server, self)
all_tools.append(tool)
tools = self.create_mcp_tools_from_server(server)
all_tools.extend(tools)
print(f"[MCP] Connected to {name} with {len(server.tools)} tools")
return all_tools