@@ -31,9 +31,9 @@ def edit(server_name, new, editor):
3131 - Change the server name with real-time validation
3232 - Modify server-specific properties (command, args, env for STDIO; URL, headers for remote)
3333 - Step through each field, press Enter to confirm, ESC to cancel
34-
34+
3535 Examples:
36-
36+
3737 mcpm edit time # Edit existing server
3838 mcpm edit agentkit # Edit agentkit server
3939 mcpm edit -N # Create new server
@@ -43,46 +43,61 @@ def edit(server_name, new, editor):
4343 if editor :
4444 _open_global_config_in_editor ()
4545 return 0
46-
46+
4747 # Handle new server mode
4848 if new :
4949 if server_name :
50- print_error ("Cannot specify both server name and --new flag" , "Use either 'mcpm edit <server>' or 'mcpm edit --new'" )
50+ print_error (
51+ "Cannot specify both server name and --new flag" , "Use either 'mcpm edit <server>' or 'mcpm edit --new'"
52+ )
5153 raise click .ClickException ("Cannot specify both server name and --new flag" )
5254 _create_new_server ()
5355 return 0
54-
56+
5557 # Require server name for editing existing servers
5658 if not server_name :
5759 print_error ("Server name is required" , "Use 'mcpm edit <server>', 'mcpm edit --new', or 'mcpm edit --editor'" )
5860 raise click .ClickException ("Server name is required" )
59-
61+
6062 # Get the existing server
6163 server_config = global_config_manager .get_server (server_name )
6264 if not server_config :
63- print_error (f"Server '{ server_name } ' not found" , "Run 'mcpm ls' to see available servers or use 'mcpm edit --new' to create one" )
65+ print_error (
66+ f"Server '{ server_name } ' not found" ,
67+ "Run 'mcpm ls' to see available servers or use 'mcpm edit --new' to create one" ,
68+ )
6469 raise click .ClickException (f"Server '{ server_name } ' not found" )
6570
6671 # Display current configuration
6772 console .print (f"\n [bold green]Current Configuration for '{ server_name } ':[/]" )
68-
73+
6974 table = Table (show_header = True , header_style = "bold cyan" )
7075 table .add_column ("Property" , style = "yellow" )
7176 table .add_column ("Current Value" , style = "white" )
72-
77+
7378 table .add_row ("Name" , server_config .name )
7479 table .add_row ("Type" , type (server_config ).__name__ )
75-
80+
7681 if isinstance (server_config , STDIOServerConfig ):
7782 table .add_row ("Command" , server_config .command )
7883 table .add_row ("Arguments" , ", " .join (server_config .args ) if server_config .args else "[dim]None[/]" )
79- table .add_row ("Environment" , ", " .join (f"{ k } ={ v } " for k , v in server_config .env .items ()) if server_config .env else "[dim]None[/]" )
84+ table .add_row (
85+ "Environment" ,
86+ ", " .join (f"{ k } ={ v } " for k , v in server_config .env .items ()) if server_config .env else "[dim]None[/]" ,
87+ )
8088 elif isinstance (server_config , RemoteServerConfig ):
8189 table .add_row ("URL" , server_config .url )
82- table .add_row ("Headers" , ", " .join (f"{ k } ={ v } " for k , v in server_config .headers .items ()) if server_config .headers else "[dim]None[/]" )
83-
84- table .add_row ("Profile Tags" , ", " .join (server_config .profile_tags ) if server_config .profile_tags else "[dim]None[/]" )
85-
90+ table .add_row (
91+ "Headers" ,
92+ ", " .join (f"{ k } ={ v } " for k , v in server_config .headers .items ())
93+ if server_config .headers
94+ else "[dim]None[/]" ,
95+ )
96+
97+ table .add_row (
98+ "Profile Tags" , ", " .join (server_config .profile_tags ) if server_config .profile_tags else "[dim]None[/]"
99+ )
100+
86101 console .print (table )
87102 console .print ()
88103
@@ -150,7 +165,7 @@ def interactive_server_edit(server_config) -> Optional[Dict[str, Any]]:
150165
151166 try :
152167 answers = {}
153-
168+
154169 # Server name - always editable
155170 answers ["name" ] = inquirer .text (
156171 message = "Server name:" ,
@@ -163,7 +178,7 @@ def interactive_server_edit(server_config) -> Optional[Dict[str, Any]]:
163178 if isinstance (server_config , STDIOServerConfig ):
164179 # STDIO Server configuration
165180 console .print ("\n [cyan]STDIO Server Configuration[/]" )
166-
181+
167182 answers ["command" ] = inquirer .text (
168183 message = "Command to execute:" ,
169184 default = server_config .command ,
@@ -193,7 +208,7 @@ def interactive_server_edit(server_config) -> Optional[Dict[str, Any]]:
193208 elif isinstance (server_config , RemoteServerConfig ):
194209 # Remote Server configuration
195210 console .print ("\n [cyan]Remote Server Configuration[/]" )
196-
211+
197212 answers ["url" ] = inquirer .text (
198213 message = "Server URL:" ,
199214 default = server_config .url ,
@@ -203,7 +218,9 @@ def interactive_server_edit(server_config) -> Optional[Dict[str, Any]]:
203218 ).execute ()
204219
205220 # Headers
206- current_headers = ", " .join (f"{ k } ={ v } " for k , v in server_config .headers .items ()) if server_config .headers else ""
221+ current_headers = (
222+ ", " .join (f"{ k } ={ v } " for k , v in server_config .headers .items ()) if server_config .headers else ""
223+ )
207224 answers ["headers" ] = inquirer .text (
208225 message = "HTTP headers (KEY=value,KEY2=value2):" ,
209226 default = current_headers ,
@@ -217,26 +234,26 @@ def interactive_server_edit(server_config) -> Optional[Dict[str, Any]]:
217234 # Confirmation
218235 console .print ("\n [bold]Summary of changes:[/]" )
219236 console .print (f"Name: [cyan]{ server_config .name } [/] → [cyan]{ answers ['name' ]} [/]" )
220-
237+
221238 if isinstance (server_config , STDIOServerConfig ):
222239 console .print (f"Command: [cyan]{ server_config .command } [/] → [cyan]{ answers ['command' ]} [/]" )
223- new_args = [arg .strip () for arg in answers [' args' ].split ("," ) if arg .strip ()] if answers [' args' ] else []
240+ new_args = [arg .strip () for arg in answers [" args" ].split ("," ) if arg .strip ()] if answers [" args" ] else []
224241 console .print (f"Arguments: [cyan]{ server_config .args } [/] → [cyan]{ new_args } [/]" )
225-
242+
226243 new_env = {}
227- if answers [' env' ]:
228- for env_pair in answers [' env' ].split ("," ):
244+ if answers [" env" ]:
245+ for env_pair in answers [" env" ].split ("," ):
229246 if "=" in env_pair :
230247 key , value = env_pair .split ("=" , 1 )
231248 new_env [key .strip ()] = value .strip ()
232249 console .print (f"Environment: [cyan]{ server_config .env } [/] → [cyan]{ new_env } [/]" )
233-
250+
234251 elif isinstance (server_config , RemoteServerConfig ):
235252 console .print (f"URL: [cyan]{ server_config .url } [/] → [cyan]{ answers ['url' ]} [/]" )
236-
253+
237254 new_headers = {}
238- if answers [' headers' ]:
239- for header_pair in answers [' headers' ].split ("," ):
255+ if answers [" headers" ]:
256+ for header_pair in answers [" headers" ].split ("," ):
240257 if "=" in header_pair :
241258 key , value = header_pair .split ("=" , 1 )
242259 new_headers [key .strip ()] = value .strip ()
@@ -255,11 +272,7 @@ def interactive_server_edit(server_config) -> Optional[Dict[str, Any]]:
255272 # Restore original argv
256273 sys .argv = original_argv
257274
258- return {
259- "cancelled" : False ,
260- "answers" : answers ,
261- "server_type" : type (server_config ).__name__
262- }
275+ return {"cancelled" : False , "answers" : answers , "server_type" : type (server_config ).__name__ }
263276
264277 except (KeyboardInterrupt , EOFError ):
265278 console .print ("\n [yellow]Operation cancelled[/]" )
@@ -273,42 +286,42 @@ def apply_interactive_changes(server_config, interactive_result):
273286 """Apply the changes from interactive editing to the server config."""
274287 if interactive_result .get ("cancelled" , True ):
275288 return False
276-
289+
277290 answers = interactive_result ["answers" ]
278-
291+
279292 # Update name
280293 server_config .name = answers ["name" ].strip ()
281-
294+
282295 if isinstance (server_config , STDIOServerConfig ):
283296 # Update STDIO-specific fields
284297 server_config .command = answers ["command" ].strip ()
285-
298+
286299 # Parse arguments
287300 if answers ["args" ].strip ():
288301 server_config .args = [arg .strip () for arg in answers ["args" ].split ("," ) if arg .strip ()]
289302 else :
290303 server_config .args = []
291-
304+
292305 # Parse environment variables
293306 server_config .env = {}
294307 if answers ["env" ].strip ():
295308 for env_pair in answers ["env" ].split ("," ):
296309 if "=" in env_pair :
297310 key , value = env_pair .split ("=" , 1 )
298311 server_config .env [key .strip ()] = value .strip ()
299-
312+
300313 elif isinstance (server_config , RemoteServerConfig ):
301314 # Update remote-specific fields
302315 server_config .url = answers ["url" ].strip ()
303-
316+
304317 # Parse headers
305318 server_config .headers = {}
306319 if answers ["headers" ].strip ():
307320 for header_pair in answers ["headers" ].split ("," ):
308321 if "=" in header_pair :
309322 key , value = header_pair .split ("=" , 1 )
310323 server_config .headers [key .strip ()] = value .strip ()
311-
324+
312325 return True
313326
314327
@@ -317,12 +330,12 @@ def _open_global_config_in_editor():
317330 try :
318331 # Get the global config file path
319332 config_path = global_config_manager .config_path
320-
333+
321334 if not os .path .exists (config_path ):
322335 console .print ("[yellow]No global configuration file found.[/]" )
323336 console .print ("[dim]Install a server first with 'mcpm install <server>' to create the config file.[/]" )
324337 return
325-
338+
326339 console .print ("[bold green]Opening global MCPM configuration in your default editor...[/]" )
327340
328341 # Use appropriate command based on platform
@@ -368,23 +381,21 @@ def _create_new_server():
368381 server_config = STDIOServerConfig (
369382 name = server_name ,
370383 command = result ["answers" ]["command" ],
371- args = [arg .strip () for arg in result ["answers" ]["args" ].split ("," ) if arg .strip ()] if result ["answers" ]["args" ] else [],
372- env = {}
384+ args = [arg .strip () for arg in result ["answers" ]["args" ].split ("," ) if arg .strip ()]
385+ if result ["answers" ]["args" ]
386+ else [],
387+ env = {},
373388 )
374-
389+
375390 # Parse environment variables
376391 if result ["answers" ]["env" ]:
377392 for env_pair in result ["answers" ]["env" ].split ("," ):
378393 if "=" in env_pair :
379394 key , value = env_pair .split ("=" , 1 )
380395 server_config .env [key .strip ()] = value .strip ()
381396 else : # remote
382- server_config = RemoteServerConfig (
383- name = server_name ,
384- url = result ["answers" ]["url" ],
385- headers = {}
386- )
387-
397+ server_config = RemoteServerConfig (name = server_name , url = result ["answers" ]["url" ], headers = {})
398+
388399 # Parse headers
389400 if result ["answers" ]["headers" ]:
390401 for header_pair in result ["answers" ]["headers" ].split ("," ):
@@ -420,7 +431,7 @@ def _interactive_new_server_form() -> Optional[Dict[str, Any]]:
420431
421432 try :
422433 answers = {}
423-
434+
424435 # Server name - required
425436 answers ["name" ] = inquirer .text (
426437 message = "Server name:" ,
@@ -442,7 +453,7 @@ def _interactive_new_server_form() -> Optional[Dict[str, Any]]:
442453 if answers ["type" ] == "stdio" :
443454 # STDIO Server configuration
444455 console .print ("\n [cyan]STDIO Server Configuration[/]" )
445-
456+
446457 answers ["command" ] = inquirer .text (
447458 message = "Command to execute:" ,
448459 validate = lambda text : len (text .strip ()) > 0 ,
@@ -465,7 +476,7 @@ def _interactive_new_server_form() -> Optional[Dict[str, Any]]:
465476 else : # remote
466477 # Remote Server configuration
467478 console .print ("\n [cyan]Remote Server Configuration[/]" )
468-
479+
469480 answers ["url" ] = inquirer .text (
470481 message = "Server URL:" ,
471482 validate = lambda text : text .strip ().startswith (("http://" , "https://" )) if text .strip () else False ,
@@ -483,26 +494,26 @@ def _interactive_new_server_form() -> Optional[Dict[str, Any]]:
483494 console .print ("\n [bold]Summary of new server:[/]" )
484495 console .print (f"Name: [cyan]{ answers ['name' ]} [/]" )
485496 console .print (f"Type: [cyan]{ answers ['type' ].upper ()} [/]" )
486-
497+
487498 if answers ["type" ] == "stdio" :
488499 console .print (f"Command: [cyan]{ answers ['command' ]} [/]" )
489- new_args = [arg .strip () for arg in answers [' args' ].split ("," ) if arg .strip ()] if answers [' args' ] else []
500+ new_args = [arg .strip () for arg in answers [" args" ].split ("," ) if arg .strip ()] if answers [" args" ] else []
490501 console .print (f"Arguments: [cyan]{ new_args } [/]" )
491-
502+
492503 new_env = {}
493- if answers [' env' ]:
494- for env_pair in answers [' env' ].split ("," ):
504+ if answers [" env" ]:
505+ for env_pair in answers [" env" ].split ("," ):
495506 if "=" in env_pair :
496507 key , value = env_pair .split ("=" , 1 )
497508 new_env [key .strip ()] = value .strip ()
498509 console .print (f"Environment: [cyan]{ new_env } [/]" )
499-
510+
500511 else : # remote
501512 console .print (f"URL: [cyan]{ answers ['url' ]} [/]" )
502-
513+
503514 new_headers = {}
504- if answers [' headers' ]:
505- for header_pair in answers [' headers' ].split ("," ):
515+ if answers [" headers" ]:
516+ for header_pair in answers [" headers" ].split ("," ):
506517 if "=" in header_pair :
507518 key , value = header_pair .split ("=" , 1 )
508519 new_headers [key .strip ()] = value .strip ()
@@ -531,4 +542,4 @@ def _interactive_new_server_form() -> Optional[Dict[str, Any]]:
531542 return {"cancelled" : True }
532543 except Exception as e :
533544 console .print (f"[red]Error running interactive form: { e } [/]" )
534- return None
545+ return None
0 commit comments