Execute the servers command.
(self, **kwargs)
| 85 | ] |
| 86 | |
| 87 | async def execute(self, **kwargs) -> CommandResult: |
| 88 | """Execute the servers command.""" |
| 89 | import json |
| 90 | |
| 91 | from mcp_cli.context import get_context |
| 92 | from chuk_term.ui import output, format_table |
| 93 | |
| 94 | # Extract parameters |
| 95 | _ = kwargs.get("detailed", False) # Reserved for future use |
| 96 | ping_servers = kwargs.get("ping", False) |
| 97 | output_format = kwargs.get("format", "table") |
| 98 | |
| 99 | # Get context and tool manager |
| 100 | context = get_context() |
| 101 | if not context or not context.tool_manager: |
| 102 | return CommandResult( |
| 103 | success=False, |
| 104 | error="No tool manager available. Please connect to a server first.", |
| 105 | ) |
| 106 | |
| 107 | try: |
| 108 | # Get server information (Pydantic ServerInfo models) |
| 109 | servers = await context.tool_manager.get_server_info() |
| 110 | |
| 111 | if not servers: |
| 112 | return CommandResult( |
| 113 | success=True, |
| 114 | output="No servers connected.", |
| 115 | ) |
| 116 | |
| 117 | # Output as JSON if requested |
| 118 | if output_format == OutputFormat.JSON: |
| 119 | server_data = [s.model_dump() for s in servers] |
| 120 | output.print(json.dumps(server_data, indent=2, default=str)) |
| 121 | return CommandResult(success=True, data=server_data) |
| 122 | |
| 123 | # Build table rows from Pydantic models |
| 124 | table_data = [] |
| 125 | for server in servers: |
| 126 | status = self._get_server_status(server) |
| 127 | |
| 128 | # Get connection info based on transport type |
| 129 | connection = self._get_connection_info(server) |
| 130 | |
| 131 | row = { |
| 132 | "Server": server.name, |
| 133 | "Type": server.transport.value.upper(), |
| 134 | "Status": f"{status.icon} {status.status}", |
| 135 | "Tools": str(server.tool_count), |
| 136 | "Connection": connection, |
| 137 | } |
| 138 | |
| 139 | table_data.append(row) |
| 140 | |
| 141 | # Display table with all columns |
| 142 | columns = ["Server", "Type", "Status", "Tools", "Connection"] |
| 143 | |
| 144 | table = format_table( |
nothing calls this directly
no test coverage detected