|
13 | 13 | from ruamel.yaml import YAML |
14 | 14 |
|
15 | 15 | from mcpm.schemas.server_config import ServerConfig, STDIOServerConfig |
| 16 | +from mcpm.utils.config import ROUTER_SERVER_NAME |
| 17 | +from mcpm.utils.router_server import format_server_url |
16 | 18 |
|
17 | 19 | logger = logging.getLogger(__name__) |
18 | 20 |
|
@@ -132,6 +134,30 @@ def is_client_installed(self) -> bool: |
132 | 134 | """ |
133 | 135 | pass |
134 | 136 |
|
| 137 | + @abc.abstractmethod |
| 138 | + def activate_profile(self, profile_name: str, router_config: Dict[str, Any]) -> bool: |
| 139 | + """ |
| 140 | + Activate a profile in the client config |
| 141 | +
|
| 142 | + Args: |
| 143 | + profile_name: Name of the profile |
| 144 | + router_config: Router configuration |
| 145 | +
|
| 146 | + Returns: |
| 147 | + bool: Success or failure |
| 148 | + """ |
| 149 | + pass |
| 150 | + |
| 151 | + @abc.abstractmethod |
| 152 | + def deactivate_profile(self) -> bool: |
| 153 | + """ |
| 154 | + Deactivate a profile in the client config |
| 155 | +
|
| 156 | + Returns: |
| 157 | + bool: Success or failure |
| 158 | + """ |
| 159 | + pass |
| 160 | + |
135 | 161 |
|
136 | 162 | class JSONClientManager(BaseClientManager): |
137 | 163 | """ |
@@ -350,6 +376,33 @@ def is_client_installed(self) -> bool: |
350 | 376 | # Can be overridden by subclasses |
351 | 377 | return os.path.isdir(os.path.dirname(self.config_path)) |
352 | 378 |
|
| 379 | + def activate_profile(self, profile_name: str, router_config: Dict[str, Any]) -> bool: |
| 380 | + """Activate a profile in the client config |
| 381 | +
|
| 382 | + Args: |
| 383 | + profile_name: Name of the profile |
| 384 | +
|
| 385 | + Returns: |
| 386 | + bool: Success or failure |
| 387 | + """ |
| 388 | + host = router_config["host"] |
| 389 | + port = router_config["port"] |
| 390 | + default_base_url = f"http://{host}:{port}/sse" |
| 391 | + |
| 392 | + server_config = self._format_router_server(profile_name, default_base_url) |
| 393 | + return self.add_server(server_config) |
| 394 | + |
| 395 | + def _format_router_server(self, profile_name, base_url) -> ServerConfig: |
| 396 | + return format_server_url(self.client_key, profile_name, base_url) |
| 397 | + |
| 398 | + def deactivate_profile(self) -> bool: |
| 399 | + """Deactivate a profile in the client config |
| 400 | +
|
| 401 | + Returns: |
| 402 | + bool: Success or failure |
| 403 | + """ |
| 404 | + return self.remove_server(ROUTER_SERVER_NAME) |
| 405 | + |
353 | 406 |
|
354 | 407 | class YAMLClientManager(BaseClientManager): |
355 | 408 | """ |
@@ -589,3 +642,30 @@ def is_client_installed(self) -> bool: |
589 | 642 | """ |
590 | 643 | # Check if the config directory exists |
591 | 644 | return os.path.isdir(os.path.dirname(self.config_path)) |
| 645 | + |
| 646 | + def activate_profile(self, profile_name: str, router_config: Dict[str, Any]) -> bool: |
| 647 | + """Activate a profile in the client config |
| 648 | +
|
| 649 | + Args: |
| 650 | + profile_name: Name of the profile |
| 651 | +
|
| 652 | + Returns: |
| 653 | + bool: Success or failure |
| 654 | + """ |
| 655 | + host = router_config["host"] |
| 656 | + port = router_config["port"] |
| 657 | + default_base_url = f"http://{host}:{port}/sse" |
| 658 | + |
| 659 | + server_config = self._format_router_server(profile_name, default_base_url) |
| 660 | + return self.add_server(server_config) |
| 661 | + |
| 662 | + def _format_router_server(self, profile_name, base_url) -> ServerConfig: |
| 663 | + return format_server_url(self.client_key, profile_name, base_url) |
| 664 | + |
| 665 | + def deactivate_profile(self) -> bool: |
| 666 | + """Deactivate a profile in the client config |
| 667 | +
|
| 668 | + Returns: |
| 669 | + bool: Success or failure |
| 670 | + """ |
| 671 | + return self.remove_server(ROUTER_SERVER_NAME) |
0 commit comments