55import logging
66from typing import Any , Dict , List , Optional
77
8+ from mcpm .profile .profile_config import ProfileConfigManager
89from mcpm .utils .config import ConfigManager
910
1011logger = logging .getLogger (__name__ )
@@ -22,7 +23,7 @@ def _refresh_config(self):
2223 """Refresh the local config cache from the config manager"""
2324 self ._config = self .config_manager .get_config ()
2425
25- def get_active_client (self ) -> str :
26+ def get_active_client (self ) -> str | None :
2627 """Get the name of the currently active client or None if not set"""
2728 self ._refresh_config ()
2829 return self ._config .get ("active_client" )
@@ -56,6 +57,37 @@ def set_active_client(self, client_name: Optional[str]) -> bool:
5657 self ._refresh_config ()
5758 return result
5859
60+ def get_active_profile (self ) -> str | None :
61+ """Get the name of the currently active profile or None if not set"""
62+ self ._refresh_config ()
63+ return self ._config .get ("active_profile" )
64+
65+ def set_active_profile (self , profile_name : Optional [str ]) -> bool :
66+ """Set the active profile
67+
68+ Args:
69+ profile_name: Name of profile to set as active, or None to clear
70+
71+ Returns:
72+ bool: Success or failure
73+ """
74+ # If None, remove the active profile
75+ if profile_name is None :
76+ result = self .config_manager .set_config ("active_profile" , None )
77+ self ._refresh_config ()
78+ return result
79+
80+ supported_profiles = ProfileConfigManager ().list_profiles ()
81+
82+ if profile_name not in supported_profiles :
83+ logger .error (f"Unknown profile: { profile_name } " )
84+ return False
85+
86+ # Set the active profile
87+ result = self .config_manager .set_config ("active_profile" , profile_name )
88+ self ._refresh_config ()
89+ return result
90+
5991 def get_supported_clients (self ) -> List [str ]:
6092 """Get a list of supported client names"""
6193 # Import here to avoid circular imports
@@ -77,11 +109,11 @@ def get_client_manager(self, client_name: str):
77109
78110 return ClientRegistry .get_client_manager (client_name )
79111
80- def stash_server (self , client_name : str , server_name : str , server_config : Any ) -> bool :
112+ def stash_server (self , scope_name : str , server_name : str , server_config : Any ) -> bool :
81113 """Store a disabled server configuration in the global config
82114
83115 Args:
84- client_name : Name of the client the server belongs to
116+ scope_name : Name of the scope the server belongs to
85117 server_name: Name of the server to stash
86118 server_config: Server configuration to stash (ServerConfig object or dict)
87119
@@ -96,8 +128,8 @@ def stash_server(self, client_name: str, server_name: str, server_config: Any) -
96128 self ._config ["stashed_servers" ] = {}
97129
98130 # Ensure client section exists
99- if client_name not in self ._config ["stashed_servers" ]:
100- self ._config ["stashed_servers" ][client_name ] = {}
131+ if scope_name not in self ._config ["stashed_servers" ]:
132+ self ._config ["stashed_servers" ][scope_name ] = {}
101133
102134 # Convert ServerConfig to dict if needed
103135 try :
@@ -110,9 +142,9 @@ def stash_server(self, client_name: str, server_name: str, server_config: Any) -
110142
111143 # Add the server configuration
112144 stashed_servers = self ._config .get ("stashed_servers" , {})
113- if client_name not in stashed_servers :
114- stashed_servers [client_name ] = {}
115- stashed_servers [client_name ][server_name ] = server_dict
145+ if scope_name not in stashed_servers :
146+ stashed_servers [scope_name ] = {}
147+ stashed_servers [scope_name ][server_name ] = server_dict
116148
117149 # Use set_config to save the updated stashed_servers
118150 result = self .config_manager .set_config ("stashed_servers" , stashed_servers )
@@ -122,11 +154,11 @@ def stash_server(self, client_name: str, server_name: str, server_config: Any) -
122154 logger .error (f"Failed to save stashed server: { e } " )
123155 return False
124156
125- def pop_server (self , client_name : str , server_name : str ) -> Optional [Dict [str , Any ]]:
157+ def pop_server (self , scope_name : str , server_name : str ) -> Optional [Dict [str , Any ]]:
126158 """Retrieve a stashed server configuration from the global config
127159
128160 Args:
129- client_name : Name of the client the server belongs to
161+ scope_name : Name of the scope the server belongs to
130162 server_name: Name of the server to retrieve
131163
132164 Returns:
@@ -140,23 +172,23 @@ def pop_server(self, client_name: str, server_name: str) -> Optional[Dict[str, A
140172 if not stashed_servers :
141173 return None
142174
143- # Check if client section exists
144- if client_name not in stashed_servers :
175+ # Check if scope section exists
176+ if scope_name not in stashed_servers :
145177 return None
146178
147179 # Check if server exists
148- if server_name not in stashed_servers [client_name ]:
180+ if server_name not in stashed_servers [scope_name ]:
149181 return None
150182
151183 # Get the server configuration
152- server_config = stashed_servers [client_name ][server_name ]
184+ server_config = stashed_servers [scope_name ][server_name ]
153185
154186 # Remove the server from stashed servers
155- del stashed_servers [client_name ][server_name ]
187+ del stashed_servers [scope_name ][server_name ]
156188
157- # Clean up empty client section if needed
158- if not stashed_servers [client_name ]:
159- del stashed_servers [client_name ]
189+ # Clean up empty scope section if needed
190+ if not stashed_servers [scope_name ]:
191+ del stashed_servers [scope_name ]
160192
161193 # Clean up empty stashed_servers section if needed
162194 if not stashed_servers :
@@ -171,11 +203,11 @@ def pop_server(self, client_name: str, server_name: str) -> Optional[Dict[str, A
171203
172204 return server_config
173205
174- def is_server_stashed (self , client_name : str , server_name : str ) -> bool :
206+ def is_server_stashed (self , scope_name : str , server_name : str ) -> bool :
175207 """Check if a server is stashed in the global config
176208
177209 Args:
178- client_name : Name of the client the server belongs to
210+ scope_name : Name of the scope the server belongs to
179211 server_name: Name of the server to check
180212
181213 Returns:
@@ -189,18 +221,18 @@ def is_server_stashed(self, client_name: str, server_name: str) -> bool:
189221 if not stashed_servers :
190222 return False
191223
192- # Check if client section exists
193- if client_name not in stashed_servers :
224+ # Check if scope section exists
225+ if scope_name not in stashed_servers :
194226 return False
195227
196228 # Check if server exists
197- return server_name in stashed_servers [client_name ]
229+ return server_name in stashed_servers [scope_name ]
198230
199- def get_stashed_servers (self , client_name : str ) -> Dict [str , Dict [str , Any ]]:
231+ def get_stashed_servers (self , scope_name : str ) -> Dict [str , Dict [str , Any ]]:
200232 """Get all stashed servers for a client
201233
202234 Args:
203- client_name : Name of the client to get stashed servers for
235+ scope_name : Name of the scope to get stashed servers for
204236
205237 Returns:
206238 Dict: Dictionary of server configurations by name
@@ -213,8 +245,8 @@ def get_stashed_servers(self, client_name: str) -> Dict[str, Dict[str, Any]]:
213245 if not stashed_servers :
214246 return {}
215247
216- # Check if client section exists
217- if client_name not in stashed_servers :
248+ # Check if scope section exists
249+ if scope_name not in stashed_servers :
218250 return {}
219251
220- return stashed_servers [client_name ]
252+ return stashed_servers [scope_name ]
0 commit comments