|
12 | 12 | from rich.prompt import Confirm |
13 | 13 |
|
14 | 14 | from mcpm.utils.repository import RepositoryManager |
15 | | -from mcpm.clients.windsurf import WindsurfManager |
16 | | -from mcpm.clients.claude_desktop import ClaudeDesktopManager |
17 | | -from mcpm.clients.cursor import CursorManager |
18 | 15 | from mcpm.utils.server_config import ServerConfig |
19 | | -from mcpm.utils.config import ConfigManager |
| 16 | +from mcpm.utils.client_manager import get_active_client, get_active_client_manager, get_active_client_info |
20 | 17 |
|
21 | 18 | console = Console() |
22 | 19 | repo_manager = RepositoryManager() |
23 | | -config_manager = ConfigManager() |
24 | | - |
25 | | -# Map of client names to their manager classes |
26 | | -CLIENT_MANAGERS = { |
27 | | - "windsurf": WindsurfManager, |
28 | | - "claude-desktop": ClaudeDesktopManager, |
29 | | - "cursor": CursorManager |
30 | | -} |
31 | 20 |
|
32 | 21 | @click.command() |
33 | 22 | @click.argument("server_name") |
34 | | -@click.option("--client", "-c", help="Client to add the server to (windsurf, claude-desktop, cursor)") |
35 | 23 | @click.option("--force", is_flag=True, help="Force reinstall if server is already installed") |
36 | | -def add(server_name, client=None, force=False): |
| 24 | +def add(server_name, force=False): |
37 | 25 | """Add an MCP server to a client configuration. |
38 | 26 | |
39 | 27 | Examples: |
40 | 28 | mcpm add time |
41 | | - mcpm add github --client windsurf |
42 | 29 | mcpm add everything --force |
43 | 30 | """ |
44 | | - # If no client is specified, use the active client |
| 31 | + # Get the active client info |
| 32 | + client = get_active_client() |
45 | 33 | if not client: |
46 | | - client = config_manager.get_active_client() |
47 | | - if not client: |
48 | | - console.print("[bold red]Error:[/] No active client found.") |
49 | | - console.print("Please specify a client with --client option or set an active client with 'mcpm client set <client>'.") |
50 | | - return |
51 | | - console.print(f"[yellow]Using active client: {client}[/]") |
| 34 | + console.print("[bold red]Error:[/] No active client found.") |
| 35 | + console.print("Please set an active client with 'mcpm client set <client>'.") |
| 36 | + return |
| 37 | + console.print(f"[yellow]Using active client: {client}[/]") |
52 | 38 |
|
53 | | - # Verify client is valid |
54 | | - if client not in CLIENT_MANAGERS: |
| 39 | + # Get client manager |
| 40 | + client_manager = get_active_client_manager() |
| 41 | + if client_manager is None: |
55 | 42 | console.print(f"[bold red]Error:[/] Unsupported client '{client}'.") |
56 | | - console.print(f"Supported clients: {', '.join(CLIENT_MANAGERS.keys())}") |
57 | 43 | return |
58 | 44 |
|
59 | | - # Initialize client manager |
60 | | - client_manager = CLIENT_MANAGERS[client]() |
61 | | - |
62 | 45 | # Check if server already exists in client config |
63 | 46 | existing_server = client_manager.get_server(server_name) |
64 | 47 | if existing_server and not force: |
@@ -87,8 +70,11 @@ def add(server_name, client=None, force=False): |
87 | 70 | author_url = author_info.get("url", "") |
88 | 71 | console.print(f"[dim]Author: {author_name} {author_url}[/]") |
89 | 72 |
|
| 73 | + # Get client display name from the utility |
| 74 | + _, client_display_name, _ = get_active_client_info() |
| 75 | + |
90 | 76 | # Confirm addition |
91 | | - if not force and not Confirm.ask(f"Add this server to {client}?"): |
| 77 | + if not force and not Confirm.ask(f"Add this server to {client_display_name}?"): |
92 | 78 | console.print("[yellow]Operation cancelled.[/]") |
93 | 79 | return |
94 | 80 |
|
@@ -343,9 +329,8 @@ def add(server_name, client=None, force=False): |
343 | 329 | success = client_manager.add_server(server_config) |
344 | 330 |
|
345 | 331 | if success: |
346 | | - # Update the central tracking of enabled servers for this client |
347 | | - config_manager.enable_server_for_client(server_name, client) |
348 | | - console.print(f"[bold green]Successfully added {display_name} v{version} to {client}![/]") |
| 332 | + # Server has been successfully added to the client configuration |
| 333 | + console.print(f"[bold green]Successfully added {display_name} v{version} to {client_display_name}![/]") |
349 | 334 |
|
350 | 335 | # Display usage examples if available |
351 | 336 | examples = server_metadata.get("examples", []) |
|
0 commit comments