Skip to content

Commit 166cdb0

Browse files
committed
Clean up client logic from commands
1 parent 61a4b66 commit 166cdb0

File tree

4 files changed

+75
-58
lines changed

4 files changed

+75
-58
lines changed

src/mcpm/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from mcpm.commands import (
1313
search,
1414
remove,
15-
list_servers,
15+
list,
1616
edit,
1717
toggle,
1818
server,
@@ -124,7 +124,7 @@ def main(ctx, help_flag):
124124
main.add_command(search.search)
125125
main.add_command(remove.remove)
126126
main.add_command(add.add)
127-
main.add_command(list_servers.list)
127+
main.add_command(list.list)
128128
main.add_command(edit.edit)
129129

130130
main.add_command(toggle.toggle)

src/mcpm/commands/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
11
"""
22
MCPM commands package
33
"""
4+
5+
__all__ = [
6+
"add",
7+
"client",
8+
"edit",
9+
"inspector",
10+
"list",
11+
"remove",
12+
"search",
13+
"server",
14+
"toggle"
15+
]
16+
17+
# All command modules
18+
from . import add
19+
from . import client
20+
from . import edit
21+
from . import inspector
22+
from . import list
23+
from . import remove
24+
from . import search
25+
from . import server
26+
from . import toggle

src/mcpm/commands/list_servers.py renamed to src/mcpm/commands/list.py

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,9 @@
77
from rich.table import Table
88
from rich.markup import escape
99

10-
from mcpm.clients.claude_desktop import ClaudeDesktopManager
11-
from mcpm.clients.windsurf import WindsurfManager
12-
from mcpm.clients.cursor import CursorManager
13-
from mcpm.utils.config import ConfigManager
10+
from mcpm.utils.client_manager import get_active_client_info
1411

1512
console = Console()
16-
config_manager = ConfigManager()
17-
claude_manager = ClaudeDesktopManager()
18-
windsurf_manager = WindsurfManager()
19-
cursor_manager = CursorManager()
2013

2114
@click.command(name="list")
2215
@click.option("--available", is_flag=True, help="List all available MCP servers")
@@ -54,21 +47,12 @@ def list(available, outdated):
5447
elif outdated:
5548
console.print("[bold yellow]Checking for outdated MCP servers...[/]")
5649

57-
# Get the active client and its corresponding manager
58-
active_client = config_manager.get_active_client()
59-
60-
# Select appropriate client manager based on active client
61-
if active_client == "claude-desktop":
62-
client_manager = claude_manager
63-
client_name = "Claude Desktop"
64-
elif active_client == "windsurf":
65-
client_manager = windsurf_manager
66-
client_name = "Windsurf"
67-
elif active_client == "cursor":
68-
client_manager = cursor_manager
69-
client_name = "Cursor"
70-
else:
71-
console.print(f"[bold red]Error:[/] Unsupported active client: {active_client}")
50+
# Get the active client manager and information
51+
client_manager, client_name, _ = get_active_client_info()
52+
53+
# Check if client is supported
54+
if client_manager is None:
55+
console.print("[bold red]Error:[/] Unsupported active client")
7256
console.print("Please switch to a supported client using 'mcpm client <client-name>'")
7357
return
7458

@@ -120,21 +104,12 @@ def list(available, outdated):
120104
console.print("[green]All MCP servers are up to date.[/]")
121105

122106
else:
123-
# Get the active client and its corresponding manager
124-
active_client = config_manager.get_active_client()
125-
126-
# Select appropriate client manager based on active client
127-
if active_client == "claude-desktop":
128-
client_manager = claude_manager
129-
client_name = "Claude Desktop"
130-
elif active_client == "windsurf":
131-
client_manager = windsurf_manager
132-
client_name = "Windsurf"
133-
elif active_client == "cursor":
134-
client_manager = cursor_manager
135-
client_name = "Cursor"
136-
else:
137-
console.print(f"[bold red]Error:[/] Unsupported active client: {active_client}")
107+
# Get the active client manager and information
108+
client_manager, client_name, _ = get_active_client_info()
109+
110+
# Check if client is supported
111+
if client_manager is None:
112+
console.print("[bold red]Error:[/] Unsupported active client")
138113
console.print("Please switch to a supported client using 'mcpm client <client-name>'")
139114
return
140115

src/mcpm/commands/remove.py

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55
import click
66
from rich.console import Console
77
from rich.prompt import Confirm
8+
from rich.markup import escape
89

9-
from mcpm.clients.claude_desktop import ClaudeDesktopManager
10-
from mcpm.clients.windsurf import WindsurfManager
11-
from mcpm.utils.config import ConfigManager
10+
from mcpm.utils.client_manager import get_active_client_info
1211

1312
console = Console()
14-
config_manager = ConfigManager()
15-
claude_manager = ClaudeDesktopManager()
16-
windsurf_manager = WindsurfManager()
1713

1814
@click.command()
1915
@click.argument("server_name")
@@ -25,18 +21,12 @@ def remove(server_name, force):
2521
mcpm remove filesystem
2622
mcpm remove filesystem --force
2723
"""
28-
# Get the active client and its corresponding manager
29-
active_client = config_manager.get_active_client()
24+
# Get the active client manager and related information
25+
client_manager, client_name, _ = get_active_client_info()
3026

31-
# Select appropriate client manager based on active client
32-
if active_client == "claude-desktop":
33-
client_manager = claude_manager
34-
client_name = "Claude Desktop"
35-
elif active_client == "windsurf":
36-
client_manager = windsurf_manager
37-
client_name = "Windsurf"
38-
else:
39-
console.print(f"[bold red]Error:[/] Unsupported active client: {active_client}")
27+
# Check if client is supported
28+
if client_manager is None:
29+
console.print("[bold red]Error:[/] Unsupported active client")
4030
console.print("Please switch to a supported client using 'mcpm client <client-name>'")
4131
return
4232

@@ -46,9 +36,38 @@ def remove(server_name, force):
4636
console.print(f"[bold red]Error:[/] Server '{server_name}' not found in {client_name}.")
4737
return
4838

39+
# Display server information before removal
40+
console.print(f"\n[bold cyan]Server information for:[/] {server_name}")
41+
42+
# Server command
43+
command = getattr(server_info, "command", "N/A")
44+
console.print(f" Command: [green]{command}[/]")
45+
46+
# Display arguments
47+
args = getattr(server_info, "args", [])
48+
if args:
49+
console.print(" Arguments:")
50+
for i, arg in enumerate(args):
51+
console.print(f" {i}: [yellow]{escape(arg)}[/]")
52+
53+
# Get package name (usually the second argument)
54+
if len(args) > 1:
55+
console.print(f" Package: [magenta]{args[1]}[/]")
56+
57+
# Display environment variables
58+
env_vars = getattr(server_info, "env", {})
59+
if env_vars and len(env_vars) > 0:
60+
console.print(" Environment Variables:")
61+
for key, value in env_vars.items():
62+
console.print(f" [bold blue]{key}[/] = [green]\"{value}\"[/]")
63+
else:
64+
console.print(" Environment Variables: [italic]None[/]")
65+
66+
console.print(" " + "-" * 50)
67+
4968
# Get confirmation if --force is not used
5069
if not force:
51-
console.print(f"[bold yellow]Are you sure you want to remove:[/] {server_name}")
70+
console.print(f"\n[bold yellow]Are you sure you want to remove:[/] {server_name}")
5271
console.print("[italic]To bypass this confirmation, use --force[/]")
5372
# Use Rich's Confirm for a better user experience
5473
confirmed = Confirm.ask("Proceed with removal?")

0 commit comments

Comments
 (0)