Skip to content

Commit 05208ff

Browse files
feat: remove default profile server name and use profile name directly
1 parent ab3b0b9 commit 05208ff

File tree

8 files changed

+50
-50
lines changed

8 files changed

+50
-50
lines changed

src/mcpm/clients/base.py

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from ruamel.yaml import YAML
1515

1616
from mcpm.core.schema import ServerConfig, STDIOServerConfig
17-
from mcpm.utils.config import ROUTER_SERVER_NAME
1817
from mcpm.utils.router_server import format_server_url
1918

2019
logger = logging.getLogger(__name__)
@@ -151,43 +150,42 @@ def activate_profile(self, profile_name: str, router_config: Dict[str, Any], ali
151150
pass
152151

153152
@abc.abstractmethod
154-
def deactivate_profile(self) -> bool:
153+
def deactivate_profile(self, profile_name: str) -> bool:
155154
"""
156155
Deactivate a profile in the client config
157156
157+
Args:
158+
profile_name: Name of the profile
159+
158160
Returns:
159161
bool: Success or failure
160162
"""
161163
pass
162164

163-
def get_associated_profile(self) -> Optional[str]:
165+
def get_associated_profiles(self) -> List[str]:
164166
"""
165167
Get the associated profile for this client
166168
167169
Returns:
168-
Optional[str]: Name of the associated profile, or None if no profile is associated
170+
List[str]: List of associated profile names
169171
"""
170-
router_service = self.get_server(ROUTER_SERVER_NAME)
171-
if not router_service:
172-
# No associated profile
173-
return None
174-
175-
# Extract profile name from router service
176-
if isinstance(router_service, STDIOServerConfig):
177-
if hasattr(router_service, "args") and "--headers" in router_service.args:
178-
try:
179-
idx = router_service.args.index("profile")
180-
if idx < len(router_service.args) - 1:
181-
return router_service.args[idx + 1]
182-
except ValueError:
183-
pass
184-
else:
185-
if hasattr(router_service, "url") and "profile=" in router_service.url:
186-
matched = re.search(r"profile=([^&]+)", router_service.url)
187-
if matched:
188-
return matched.group(1)
172+
profiles = []
173+
for server_name, server_config in self.get_servers().items():
174+
if isinstance(server_config, STDIOServerConfig):
175+
if hasattr(server_config, "args") and "--headers" in server_config.args:
176+
try:
177+
idx = server_config.args.index("profile")
178+
if idx < len(server_config.args) - 1:
179+
profiles.append(server_config.args[idx + 1])
180+
except ValueError:
181+
pass
182+
else:
183+
if hasattr(server_config, "url") and "profile=" in server_config.url:
184+
matched = re.search(r"profile=([^&]+)", server_config.url)
185+
if matched:
186+
profiles.append(matched.group(1))
189187

190-
return None
188+
return profiles
191189

192190

193191
class JSONClientManager(BaseClientManager):
@@ -428,13 +426,16 @@ def activate_profile(self, profile_name: str, router_config: Dict[str, Any], ali
428426
def _format_router_server(self, profile_name, base_url, alias_name: str | None = None) -> ServerConfig:
429427
return format_server_url(self.client_key, profile_name, base_url, alias_name)
430428

431-
def deactivate_profile(self) -> bool:
429+
def deactivate_profile(self, profile_name: str) -> bool:
432430
"""Deactivate a profile in the client config
433431
432+
Args:
433+
profile_name: Name of the profile
434+
434435
Returns:
435436
bool: Success or failure
436437
"""
437-
return self.remove_server(ROUTER_SERVER_NAME)
438+
return self.remove_server(profile_name)
438439

439440

440441
class YAMLClientManager(BaseClientManager):
@@ -695,10 +696,13 @@ def activate_profile(self, profile_name: str, router_config: Dict[str, Any], ali
695696
def _format_router_server(self, profile_name, base_url, server_name: str | None = None) -> ServerConfig:
696697
return format_server_url(self.client_key, profile_name, base_url, server_name)
697698

698-
def deactivate_profile(self) -> bool:
699+
def deactivate_profile(self, profile_name: str) -> bool:
699700
"""Deactivate a profile in the client config
700701
702+
Args:
703+
profile_name: Name of the profile
704+
701705
Returns:
702706
bool: Success or failure
703707
"""
704-
return self.remove_server(ROUTER_SERVER_NAME)
708+
return self.remove_server(profile_name)

src/mcpm/commands/client.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def list_clients():
4545
table.add_column("Client Name", style="cyan")
4646
table.add_column("Installation", style="yellow")
4747
table.add_column("Status", style="green")
48-
table.add_column("Profile", style="magenta")
4948

5049
active_client = ClientRegistry.get_active_client()
5150
installed_clients = ClientRegistry.detect_installed_clients()
@@ -61,12 +60,8 @@ def list_clients():
6160
# Get client info for more details
6261
client_info = ClientRegistry.get_client_info(client)
6362
display_name = client_info.get("name", client)
64-
# Get Profile activated
65-
client_manager = ClientRegistry.get_client_manager(client)
66-
profile = client_manager.get_associated_profile() if client_manager else None
67-
active_profile = f"[bold magenta]{profile}[/]" if profile else ""
6863

69-
table.add_row(f"{display_name} ({client})", install_status, active_status, active_profile)
64+
table.add_row(f"{display_name} ({client})", install_status, active_status)
7065

7166
console.print(table)
7267

src/mcpm/commands/profile.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ def remove(profile_name):
8181
for client in clients:
8282
client_manager = ClientRegistry.get_client_manager(client)
8383
if client_manager:
84-
profile_this_client_associated = client_manager.get_associated_profile()
85-
if profile_this_client_associated == profile_name:
84+
profile_server = client_manager.get_server(profile_name)
85+
if profile_server:
8686
# Deactivate the profile in this client
87-
client_manager.deactivate_profile()
87+
client_manager.deactivate_profile(profile_name)
8888
console.print(f"\n[green]Profile '{profile_name}' removed successfully from client '{client}'.[/]\n")
8989

9090
# fresh the active_profile
@@ -113,10 +113,10 @@ def rename(profile_name):
113113
for client in clients:
114114
client_manager = ClientRegistry.get_client_manager(client)
115115
if client_manager:
116-
profile_this_client_associated = client_manager.get_associated_profile()
117-
if profile_this_client_associated == profile_name:
116+
profile_server = client_manager.get_server(profile_name)
117+
if profile_server:
118118
# fresh the config
119-
client_manager.deactivate_profile()
119+
client_manager.deactivate_profile(profile_name)
120120
client_manager.activate_profile(new_profile_name, config_manager.get_router_config())
121121
console.print(f"\n[green]Profile '{profile_name}' replaced successfully in client '{client}'.[/]\n")
122122

src/mcpm/commands/router.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from mcpm.clients.client_registry import ClientRegistry
1919
from mcpm.router.share import Tunnel
20-
from mcpm.utils.config import ROUTER_SERVER_NAME, ConfigManager
20+
from mcpm.utils.config import ConfigManager
2121
from mcpm.utils.platform import get_log_directory, get_pid_directory
2222

2323
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
@@ -292,9 +292,9 @@ def set_router_config(host, port, address, auth, secret: str | None = None):
292292
if client_manager is None:
293293
console.print(f"[yellow]Client '{client}' not found.[/] Skipping...")
294294
continue
295-
if client_manager.get_server(ROUTER_SERVER_NAME):
295+
if client_manager.get_server(active_profile):
296296
console.print(f"[cyan]Updating profile router for {client}...[/]")
297-
client_manager.deactivate_profile()
297+
client_manager.deactivate_profile(active_profile)
298298
client_manager.activate_profile(active_profile, config_manager.get_router_config())
299299
console.print(f"[green]Profile router updated for {client}[/]")
300300
console.print("[bold green]Success: Profile router updated for all clients[/]")

src/mcpm/commands/target_operations/add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def add(server_name, force=False, alias=None, target: str | None = None):
144144
else:
145145
client = scope
146146
if is_adding_profile:
147-
add_profile_to_client(server_name, client, alias, force)
147+
add_profile_to_client(server_name.lstrip(PROFILE_PREFIX), client, alias, force)
148148
return
149149
# Get client
150150
console.print(f"[yellow]Adding server to client: {client}[/]")

src/mcpm/utils/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# default router config
1616
DEFAULT_HOST = "localhost"
1717
DEFAULT_PORT = 6276 # 6276 represents MCPM on a T9 keypad (6=M, 2=C, 7=P, 6=M)
18-
ROUTER_SERVER_NAME = "mcpm_router"
1918
# default splitor pattern
2019
TOOL_SPLITOR = "_t_"
2120
RESOURCE_SPLITOR = ":"

src/mcpm/utils/router_server.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
from mcpm.clients.base import ROUTER_SERVER_NAME
21
from mcpm.core.schema import ServerConfig, SSEServerConfig, STDIOServerConfig
32

43

54
def format_server_url(client: str, profile: str, router_url: str, server_name: str | None = None) -> ServerConfig:
65
return SSEServerConfig(
7-
name=server_name if server_name else ROUTER_SERVER_NAME,
6+
name=server_name if server_name else profile,
87
url=f"{router_url}?/client={client}&profile={profile}",
98
)
109

@@ -13,7 +12,7 @@ def format_server_url_with_proxy_param(
1312
client: str, profile: str, router_url: str, server_name: str | None = None
1413
) -> ServerConfig:
1514
result = STDIOServerConfig(
16-
name=server_name if server_name else ROUTER_SERVER_NAME,
15+
name=server_name if server_name else profile,
1716
command="uvx",
1817
args=["mcp-proxy", f"{router_url}?/client={client}&profile={profile}"],
1918
)
@@ -24,7 +23,7 @@ def format_server_url_with_proxy_headers(
2423
client: str, profile: str, router_url: str, server_name: str | None = None
2524
) -> ServerConfig:
2625
result = STDIOServerConfig(
27-
name=server_name if server_name else ROUTER_SERVER_NAME,
26+
name=server_name if server_name else profile,
2827
command="uvx",
2928
args=["mcp-proxy", router_url, "--headers", "profile", profile],
3029
)

tests/test_add.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,7 @@ def test_add_profile_to_client(windsurf_manager, monkeypatch):
222222
runner = CliRunner()
223223
result = runner.invoke(add, ["%" + profile_name, "--force", "--alias", "work"])
224224
assert result.exit_code == 0
225-
assert "Successfully added profile %work to windsurf!" in result.output
225+
assert "Successfully added profile work to windsurf!" in result.output
226+
227+
profile_server = windsurf_manager.get_server("work")
228+
assert profile_server is not None

0 commit comments

Comments
 (0)