Skip to content

Commit 4c45034

Browse files
committed
Improve client command
1 parent 30677b7 commit 4c45034

File tree

4 files changed

+70
-41
lines changed

4 files changed

+70
-41
lines changed

src/mcpm/cli.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ def main(ctx, help_flag):
3636
3737
A tool for managing MCP servers across various clients.
3838
"""
39+
# Check if a command is being executed (and it's not help, no command, or the client command)
40+
if ctx.invoked_subcommand and ctx.invoked_subcommand != 'client' and not help_flag:
41+
# Check if active client is set
42+
active_client = config_manager.get_active_client()
43+
if not active_client:
44+
console.print("[bold red]Error:[/] No active client set.")
45+
console.print("Please run 'mcpm client <client-name>' to set an active client.")
46+
console.print("Available clients:")
47+
48+
# Show available clients
49+
from mcpm.utils.client_registry import ClientRegistry
50+
for client in ClientRegistry.get_supported_clients():
51+
console.print(f" - {client}")
52+
53+
# Exit with error
54+
ctx.exit(1)
3955
# If no command was invoked or help is requested, show our custom help
4056
if ctx.invoked_subcommand is None or help_flag:
4157

@@ -77,15 +93,11 @@ def main(ctx, help_flag):
7793
installed_clients = ClientRegistry.detect_installed_clients()
7894

7995
# Display active client information and main help
80-
client_status = "[green]✓[/]" if installed_clients.get(active_client, False) else "[yellow]⚠[/]"
81-
console.print(f"[bold magenta]Active client:[/] [yellow]{active_client}[/] {client_status}")
82-
83-
# Display all supported clients with their installation status
84-
console.print("[bold]Supported clients:[/]")
85-
for client, installed in installed_clients.items():
86-
status = "[green]Installed[/]" if installed else "[gray]Not installed[/]"
87-
active_marker = "[bold cyan]➤[/] " if client == active_client else " "
88-
console.print(f"{active_marker}{client}: {status}")
96+
if active_client:
97+
client_status = "[green]✓[/]" if installed_clients.get(active_client, False) else "[yellow]⚠[/]"
98+
console.print(f"[bold magenta]Active client:[/] [yellow]{active_client}[/] {client_status}")
99+
else:
100+
console.print("[bold red]No active client set![/] Please run 'mcpm client <client-name>' to set one.")
89101
console.print("")
90102

91103
# Display usage info

src/mcpm/commands/client.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,37 @@ def client(client_name, list):
3434
if list:
3535
table = Table(title="Supported MCP Clients")
3636
table.add_column("Client Name", style="cyan")
37+
table.add_column("Installation", style="yellow")
3738
table.add_column("Status", style="green")
3839

3940
active_client = ClientRegistry.get_active_client()
41+
installed_clients = ClientRegistry.detect_installed_clients()
4042

4143
for client in sorted(supported_clients):
42-
status = "[bold green]ACTIVE[/]" if client == active_client else ""
43-
table.add_row(client, status)
44+
# Determine installation status
45+
installed = installed_clients.get(client, False)
46+
install_status = "[green]Installed[/]" if installed else "[gray]Not installed[/]"
47+
48+
# Determine active status
49+
active_status = "[bold green]ACTIVE[/]" if client == active_client else ""
50+
51+
# Get client info for more details
52+
client_info = ClientRegistry.get_client_info(client)
53+
display_name = client_info.get("name", client)
54+
55+
table.add_row(f"{display_name} ({client})", install_status, active_status)
4456

4557
console.print(table)
58+
59+
# Add helpful instructions for non-installed clients
60+
non_installed = [c for c, installed in installed_clients.items() if not installed]
61+
if non_installed:
62+
console.print("\n[italic]To use a non-installed client, you need to install it first.[/]")
63+
for client in non_installed:
64+
info = ClientRegistry.get_client_info(client)
65+
if "download_url" in info:
66+
console.print(f"[yellow]{info.get('name', client)}[/]: {info['download_url']}")
67+
4668
return
4769

4870
# If no client name specified, show the current active client

src/mcpm/utils/client_registry.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ def get_active_client_manager(cls) -> Optional[BaseClientManager]:
129129
BaseClientManager: Client manager instance for the active client, or None if not found
130130
"""
131131
active_client = cls.get_active_client()
132+
if not active_client:
133+
return None
134+
132135
return cls.get_client_manager(active_client)
133136

134137
@classmethod
@@ -146,8 +149,8 @@ def get_recommended_client(cls) -> str:
146149
if installed:
147150
return client
148151

149-
# Default to claude-desktop if nothing is installed
150-
return "claude-desktop"
152+
# Return None if no clients are installed
153+
return None
151154

152155
@classmethod
153156
def get_supported_clients(cls) -> List[str]:

src/mcpm/utils/config.py

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
import os
66
import json
77
import logging
8-
from typing import Dict, List, Any
8+
from typing import Dict, List, Any, Optional
99

1010
# Client detection will be handled by ClientRegistry
1111

1212
logger = logging.getLogger(__name__)
1313

1414
# Default configuration paths
15-
DEFAULT_CONFIG_DIR = os.path.expanduser("~/.config/mcp")
15+
DEFAULT_CONFIG_DIR = os.path.expanduser("~/.config/mcpm")
1616
DEFAULT_CONFIG_FILE = os.path.join(DEFAULT_CONFIG_DIR, "config.json")
1717

1818
class ConfigManager:
@@ -48,28 +48,9 @@ def _load_config(self) -> None:
4848

4949
def _default_config(self) -> Dict[str, Any]:
5050
"""Create default configuration"""
51-
# We'll import here to avoid circular imports
52-
from mcpm.utils.client_registry import ClientRegistry
53-
54-
# Get recommended client from registry
55-
recommended_client = ClientRegistry.get_recommended_client()
56-
installed_clients = ClientRegistry.detect_installed_clients()
57-
58-
return {
59-
"version": "0.2.0",
60-
"active_client": recommended_client,
61-
"clients": {
62-
"claude-desktop": {
63-
"installed": installed_clients.get("claude-desktop", False)
64-
},
65-
"cursor": {
66-
"installed": installed_clients.get("cursor", False)
67-
},
68-
"windsurf": {
69-
"installed": installed_clients.get("windsurf", False)
70-
}
71-
}
72-
}
51+
# Return empty config - don't set any defaults
52+
# User will be prompted to set a client when needed
53+
return {}
7354

7455
def _save_config(self) -> None:
7556
"""Save current configuration to file"""
@@ -98,12 +79,23 @@ def _get_client_manager(self, client_name: str):
9879

9980

10081
def get_active_client(self) -> str:
101-
"""Get the name of the currently active client"""
102-
return self._config.get("active_client", "claude-desktop")
82+
"""Get the name of the currently active client or None if not set"""
83+
return self._config.get("active_client")
10384

104-
def set_active_client(self, client_name: str) -> bool:
85+
def set_active_client(self, client_name: Optional[str]) -> bool:
10586
"""Set the active client"""
106-
if client_name not in self._config.get("clients", {}):
87+
# Allow setting to None to clear the active client
88+
if client_name is None:
89+
if "active_client" in self._config:
90+
del self._config["active_client"]
91+
self._save_config()
92+
return True
93+
94+
# Get supported clients
95+
from mcpm.utils.client_registry import ClientRegistry
96+
supported_clients = ClientRegistry.get_supported_clients()
97+
98+
if client_name not in supported_clients:
10799
logger.error(f"Unknown client: {client_name}")
108100
return False
109101

0 commit comments

Comments
 (0)