|
14 | 14 | from ruamel.yaml import YAML |
15 | 15 |
|
16 | 16 | from mcpm.core.schema import ServerConfig, STDIOServerConfig |
17 | | -from mcpm.utils.config import ROUTER_SERVER_NAME |
18 | 17 | from mcpm.utils.router_server import format_server_url |
19 | 18 |
|
20 | 19 | logger = logging.getLogger(__name__) |
@@ -151,43 +150,42 @@ def activate_profile(self, profile_name: str, router_config: Dict[str, Any], ali |
151 | 150 | pass |
152 | 151 |
|
153 | 152 | @abc.abstractmethod |
154 | | - def deactivate_profile(self) -> bool: |
| 153 | + def deactivate_profile(self, profile_name: str) -> bool: |
155 | 154 | """ |
156 | 155 | Deactivate a profile in the client config |
157 | 156 |
|
| 157 | + Args: |
| 158 | + profile_name: Name of the profile |
| 159 | +
|
158 | 160 | Returns: |
159 | 161 | bool: Success or failure |
160 | 162 | """ |
161 | 163 | pass |
162 | 164 |
|
163 | | - def get_associated_profile(self) -> Optional[str]: |
| 165 | + def get_associated_profiles(self) -> List[str]: |
164 | 166 | """ |
165 | 167 | Get the associated profile for this client |
166 | 168 |
|
167 | 169 | Returns: |
168 | | - Optional[str]: Name of the associated profile, or None if no profile is associated |
| 170 | + List[str]: List of associated profile names |
169 | 171 | """ |
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)) |
189 | 187 |
|
190 | | - return None |
| 188 | + return profiles |
191 | 189 |
|
192 | 190 |
|
193 | 191 | class JSONClientManager(BaseClientManager): |
@@ -428,13 +426,16 @@ def activate_profile(self, profile_name: str, router_config: Dict[str, Any], ali |
428 | 426 | def _format_router_server(self, profile_name, base_url, alias_name: str | None = None) -> ServerConfig: |
429 | 427 | return format_server_url(self.client_key, profile_name, base_url, alias_name) |
430 | 428 |
|
431 | | - def deactivate_profile(self) -> bool: |
| 429 | + def deactivate_profile(self, profile_name: str) -> bool: |
432 | 430 | """Deactivate a profile in the client config |
433 | 431 |
|
| 432 | + Args: |
| 433 | + profile_name: Name of the profile |
| 434 | +
|
434 | 435 | Returns: |
435 | 436 | bool: Success or failure |
436 | 437 | """ |
437 | | - return self.remove_server(ROUTER_SERVER_NAME) |
| 438 | + return self.remove_server(profile_name) |
438 | 439 |
|
439 | 440 |
|
440 | 441 | class YAMLClientManager(BaseClientManager): |
@@ -695,10 +696,13 @@ def activate_profile(self, profile_name: str, router_config: Dict[str, Any], ali |
695 | 696 | def _format_router_server(self, profile_name, base_url, server_name: str | None = None) -> ServerConfig: |
696 | 697 | return format_server_url(self.client_key, profile_name, base_url, server_name) |
697 | 698 |
|
698 | | - def deactivate_profile(self) -> bool: |
| 699 | + def deactivate_profile(self, profile_name: str) -> bool: |
699 | 700 | """Deactivate a profile in the client config |
700 | 701 |
|
| 702 | + Args: |
| 703 | + profile_name: Name of the profile |
| 704 | +
|
701 | 705 | Returns: |
702 | 706 | bool: Success or failure |
703 | 707 | """ |
704 | | - return self.remove_server(ROUTER_SERVER_NAME) |
| 708 | + return self.remove_server(profile_name) |
0 commit comments