5
5
import logging
6
6
from typing import Any , Dict , List , Optional
7
7
8
+ from mcpm .profile .profile_config import ProfileConfigManager
8
9
from mcpm .utils .config import ConfigManager
9
10
10
11
logger = logging .getLogger (__name__ )
@@ -22,7 +23,7 @@ def _refresh_config(self):
22
23
"""Refresh the local config cache from the config manager"""
23
24
self ._config = self .config_manager .get_config ()
24
25
25
- def get_active_client (self ) -> str :
26
+ def get_active_client (self ) -> str | None :
26
27
"""Get the name of the currently active client or None if not set"""
27
28
self ._refresh_config ()
28
29
return self ._config .get ("active_client" )
@@ -56,6 +57,37 @@ def set_active_client(self, client_name: Optional[str]) -> bool:
56
57
self ._refresh_config ()
57
58
return result
58
59
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
+
59
91
def get_supported_clients (self ) -> List [str ]:
60
92
"""Get a list of supported client names"""
61
93
# Import here to avoid circular imports
@@ -77,11 +109,11 @@ def get_client_manager(self, client_name: str):
77
109
78
110
return ClientRegistry .get_client_manager (client_name )
79
111
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 :
81
113
"""Store a disabled server configuration in the global config
82
114
83
115
Args:
84
- client_name : Name of the client the server belongs to
116
+ scope_name : Name of the scope the server belongs to
85
117
server_name: Name of the server to stash
86
118
server_config: Server configuration to stash (ServerConfig object or dict)
87
119
@@ -96,8 +128,8 @@ def stash_server(self, client_name: str, server_name: str, server_config: Any) -
96
128
self ._config ["stashed_servers" ] = {}
97
129
98
130
# 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 ] = {}
101
133
102
134
# Convert ServerConfig to dict if needed
103
135
try :
@@ -110,9 +142,9 @@ def stash_server(self, client_name: str, server_name: str, server_config: Any) -
110
142
111
143
# Add the server configuration
112
144
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
116
148
117
149
# Use set_config to save the updated stashed_servers
118
150
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) -
122
154
logger .error (f"Failed to save stashed server: { e } " )
123
155
return False
124
156
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 ]]:
126
158
"""Retrieve a stashed server configuration from the global config
127
159
128
160
Args:
129
- client_name : Name of the client the server belongs to
161
+ scope_name : Name of the scope the server belongs to
130
162
server_name: Name of the server to retrieve
131
163
132
164
Returns:
@@ -140,23 +172,23 @@ def pop_server(self, client_name: str, server_name: str) -> Optional[Dict[str, A
140
172
if not stashed_servers :
141
173
return None
142
174
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 :
145
177
return None
146
178
147
179
# Check if server exists
148
- if server_name not in stashed_servers [client_name ]:
180
+ if server_name not in stashed_servers [scope_name ]:
149
181
return None
150
182
151
183
# Get the server configuration
152
- server_config = stashed_servers [client_name ][server_name ]
184
+ server_config = stashed_servers [scope_name ][server_name ]
153
185
154
186
# Remove the server from stashed servers
155
- del stashed_servers [client_name ][server_name ]
187
+ del stashed_servers [scope_name ][server_name ]
156
188
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 ]
160
192
161
193
# Clean up empty stashed_servers section if needed
162
194
if not stashed_servers :
@@ -171,11 +203,11 @@ def pop_server(self, client_name: str, server_name: str) -> Optional[Dict[str, A
171
203
172
204
return server_config
173
205
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 :
175
207
"""Check if a server is stashed in the global config
176
208
177
209
Args:
178
- client_name : Name of the client the server belongs to
210
+ scope_name : Name of the scope the server belongs to
179
211
server_name: Name of the server to check
180
212
181
213
Returns:
@@ -189,18 +221,18 @@ def is_server_stashed(self, client_name: str, server_name: str) -> bool:
189
221
if not stashed_servers :
190
222
return False
191
223
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 :
194
226
return False
195
227
196
228
# Check if server exists
197
- return server_name in stashed_servers [client_name ]
229
+ return server_name in stashed_servers [scope_name ]
198
230
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 ]]:
200
232
"""Get all stashed servers for a client
201
233
202
234
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
204
236
205
237
Returns:
206
238
Dict: Dictionary of server configurations by name
@@ -213,8 +245,8 @@ def get_stashed_servers(self, client_name: str) -> Dict[str, Dict[str, Any]]:
213
245
if not stashed_servers :
214
246
return {}
215
247
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 :
218
250
return {}
219
251
220
- return stashed_servers [client_name ]
252
+ return stashed_servers [scope_name ]
0 commit comments