Skip to content

Commit 6af8551

Browse files
committed
Display stashed server config when listing server
Refactor server config printing logic
1 parent 23fe449 commit 6af8551

File tree

3 files changed

+103
-48
lines changed

3 files changed

+103
-48
lines changed

src/mcpm/commands/edit.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from rich.prompt import Confirm
1313

1414
from mcpm.clients.client_registry import ClientRegistry
15+
from mcpm.utils.display import print_server_config
1516

1617
console = Console()
1718

@@ -110,27 +111,7 @@ def edit():
110111
if server_count > 0:
111112
console.print("\n[bold]MCP Server Details:[/]")
112113
for server_name, server_config in config_json.get("mcpServers", {}).items():
113-
console.print(f"\n[bold cyan]{server_name}[/]")
114-
console.print(f" Command: [green]{server_config.get('command', 'N/A')}[/]")
115-
116-
# Display arguments
117-
args = server_config.get("args", [])
118-
if args:
119-
console.print(" Arguments:")
120-
for i, arg in enumerate(args):
121-
console.print(f" {i}: [yellow]{arg}[/]")
122-
123-
# Display environment variables
124-
env_vars = server_config.get("env", {})
125-
if env_vars:
126-
console.print(" Environment Variables:")
127-
for key, value in env_vars.items():
128-
console.print(f' [bold blue]{key}[/] = [green]"{value}"[/]')
129-
else:
130-
console.print(" Environment Variables: [italic]None[/]")
131-
132-
# Add a separator line
133-
console.print(" " + "-" * 50)
114+
print_server_config(server_name, server_config)
134115

135116
except json.JSONDecodeError:
136117
console.print("[yellow]Warning: Config file contains invalid JSON[/]")

src/mcpm/commands/list.py

Lines changed: 56 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,49 @@
66
from rich.console import Console
77
from rich.markup import escape
88

9+
from mcpm.clients.client_config import ClientConfigManager
910
from mcpm.clients.client_registry import ClientRegistry
11+
from mcpm.utils.display import print_server_config
1012

1113
console = Console()
14+
client_config_manager = ClientConfigManager()
15+
16+
17+
def print_server_config(server_name, server_info, is_stashed=False):
18+
"""Print detailed information about a server configuration.
19+
20+
Args:
21+
server_name: Name of the server
22+
server_info: Server configuration information
23+
is_stashed: Whether the server is stashed (affects display style)
24+
"""
25+
# Server name and command
26+
if is_stashed:
27+
console.print(f"[bold yellow]{server_name}[/] [dim](stashed)[/]")
28+
else:
29+
console.print(f"[bold cyan]{server_name}[/]")
30+
31+
command = server_info.get("command", "N/A")
32+
console.print(f" Command: [green]{command}[/]")
33+
34+
# Display arguments
35+
args = server_info.get("args", [])
36+
if args:
37+
console.print(" Arguments:")
38+
for i, arg in enumerate(args):
39+
console.print(f" {i}: [yellow]{escape(arg)}[/]")
40+
41+
# Display environment variables
42+
env_vars = server_info.get("env", {})
43+
if env_vars:
44+
console.print(" Environment Variables:")
45+
for key, value in env_vars.items():
46+
console.print(f' [bold blue]{key}[/] = [green]"{value}"[/]')
47+
else:
48+
console.print(" Environment Variables: [italic]None[/]")
49+
50+
# Add a separator line between servers
51+
console.print(" " + "-" * 50)
1252

1353

1454
@click.command(name="list")
@@ -35,37 +75,26 @@ def list():
3575
# Get all servers from active client config
3676
servers = client_manager.get_servers()
3777

38-
if not servers:
78+
# Get stashed servers
79+
stashed_servers = client_config_manager.get_stashed_servers(client)
80+
81+
if not servers and not stashed_servers:
3982
console.print(f"[yellow]No MCP servers found in {client_name}.[/]")
4083
console.print("Use 'mcpm add <server>' to add a server.")
4184
return
4285

4386
# Count the configured servers
4487
server_count = len(servers)
45-
console.print(f"[bold]Configured servers:[/] {server_count}\n")
88+
stashed_count = len(stashed_servers)
4689

47-
# Display detailed information for each server
48-
for server_name, server_info in servers.items():
49-
# Server name and command
50-
console.print(f"[bold cyan]{server_name}[/]")
51-
command = server_info.get("command", "N/A")
52-
console.print(f" Command: [green]{command}[/]")
53-
54-
# Display arguments
55-
args = server_info.get("args", [])
56-
if args:
57-
console.print(" Arguments:")
58-
for i, arg in enumerate(args):
59-
console.print(f" {i}: [yellow]{escape(arg)}[/]")
60-
61-
# Display environment variables
62-
env_vars = server_info.get("env", {})
63-
if env_vars:
64-
console.print(" Environment Variables:")
65-
for key, value in env_vars.items():
66-
console.print(f' [bold blue]{key}[/] = [green]"{value}"[/]')
67-
else:
68-
console.print(" Environment Variables: [italic]None[/]")
69-
70-
# Add a separator line between servers
71-
console.print(" " + "-" * 50)
90+
# Print active servers
91+
if servers:
92+
console.print("\n[bold]Active Servers:[/]")
93+
for server_name, server_info in servers.items():
94+
print_server_config(server_name, server_info)
95+
96+
# Print stashed servers
97+
if stashed_servers:
98+
console.print("\n[bold]Stashed Servers:[/]")
99+
for server_name, server_info in stashed_servers.items():
100+
print_server_config(server_name, server_info, is_stashed=True)

src/mcpm/utils/display.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
Utility functions for displaying MCP server configurations
3+
"""
4+
5+
from rich.console import Console
6+
from rich.markup import escape
7+
8+
console = Console()
9+
10+
11+
def print_server_config(server_name, server_info, is_stashed=False):
12+
"""Print detailed information about a server configuration.
13+
14+
Args:
15+
server_name: Name of the server
16+
server_info: Server configuration information
17+
is_stashed: Whether the server is stashed (affects display style)
18+
"""
19+
# Server name and command
20+
if is_stashed:
21+
console.print(f"[bold yellow]{server_name}[/] [dim](stashed)[/]")
22+
else:
23+
console.print(f"[bold cyan]{server_name}[/]")
24+
25+
command = server_info.get("command", "N/A")
26+
console.print(f" Command: [green]{command}[/]")
27+
28+
# Display arguments
29+
args = server_info.get("args", [])
30+
if args:
31+
console.print(" Arguments:")
32+
for i, arg in enumerate(args):
33+
console.print(f" {i}: [yellow]{escape(arg)}[/]")
34+
35+
# Display environment variables
36+
env_vars = server_info.get("env", {})
37+
if env_vars:
38+
console.print(" Environment Variables:")
39+
for key, value in env_vars.items():
40+
console.print(f' [bold blue]{key}[/] = [green]"{value}"[/]')
41+
else:
42+
console.print(" Environment Variables: [italic]None[/]")
43+
44+
# Add a separator line between servers
45+
console.print(" " + "-" * 50)

0 commit comments

Comments
 (0)