Execute the server command.
(self, **kwargs)
| 60 | """ |
| 61 | |
| 62 | async def execute(self, **kwargs) -> CommandResult: |
| 63 | """Execute the server command.""" |
| 64 | from mcp_cli.context import get_context |
| 65 | from chuk_term.ui import output, format_table |
| 66 | |
| 67 | # Get args - handle both string and list |
| 68 | args = kwargs.get("args", []) |
| 69 | if isinstance(args, str): |
| 70 | args = [args] |
| 71 | elif not args: |
| 72 | args = [] |
| 73 | |
| 74 | # Get context and tool manager |
| 75 | context = get_context() |
| 76 | if not context or not context.tool_manager: |
| 77 | return CommandResult( |
| 78 | success=False, |
| 79 | error="No tool manager available. Please connect to a server first.", |
| 80 | ) |
| 81 | |
| 82 | if not args: |
| 83 | # No args - show list of servers |
| 84 | try: |
| 85 | servers = await context.tool_manager.get_server_info() |
| 86 | |
| 87 | if not servers: |
| 88 | return CommandResult( |
| 89 | success=True, |
| 90 | output="No servers connected.", |
| 91 | ) |
| 92 | |
| 93 | # Build table data |
| 94 | table_data = [] |
| 95 | for server in servers: |
| 96 | table_data.append( |
| 97 | { |
| 98 | "Server": server.name, |
| 99 | "Status": "✓ Connected" |
| 100 | if server.connected |
| 101 | else "✗ Disconnected", |
| 102 | "Tools": str(server.tool_count), |
| 103 | } |
| 104 | ) |
| 105 | |
| 106 | # Display table |
| 107 | table = format_table( |
| 108 | table_data, |
| 109 | title=f"{len(servers)} Servers", |
| 110 | columns=["Server", "Status", "Tools"], |
| 111 | ) |
| 112 | output.print_table(table) |
| 113 | |
| 114 | return CommandResult(success=True) |
| 115 | except Exception as e: |
| 116 | return CommandResult( |
| 117 | success=False, error=f"Failed to list servers: {str(e)}" |
| 118 | ) |
| 119 |
nothing calls this directly
no test coverage detected