|
6 | 6 | import shlex |
7 | 7 | import subprocess |
8 | 8 | import sys |
9 | | -from typing import Any, Dict, Optional |
| 9 | +from typing import Any, Dict, Optional, Union |
10 | 10 |
|
11 | 11 | from InquirerPy import inquirer |
12 | 12 | from rich.console import Console |
@@ -407,6 +407,7 @@ def _edit_server_non_interactive( |
407 | 407 | return 0 |
408 | 408 |
|
409 | 409 | # Create the updated server config object |
| 410 | + updated_server_config: Union[STDIOServerConfig, RemoteServerConfig] |
410 | 411 | if server_type == "stdio": |
411 | 412 | updated_server_config = STDIOServerConfig( |
412 | 413 | name=updated_config["name"], |
@@ -700,137 +701,3 @@ def _interactive_new_server_form() -> Optional[Dict[str, Any]]: |
700 | 701 | return None |
701 | 702 |
|
702 | 703 |
|
703 | | -def _edit_server_non_interactive( |
704 | | - server_name: str, |
705 | | - new_name: Optional[str] = None, |
706 | | - command: Optional[str] = None, |
707 | | - args: Optional[str] = None, |
708 | | - env: Optional[str] = None, |
709 | | - url: Optional[str] = None, |
710 | | - headers: Optional[str] = None, |
711 | | - force: bool = False, |
712 | | -) -> int: |
713 | | - """Edit a server configuration non-interactively.""" |
714 | | - try: |
715 | | - # Get the existing server |
716 | | - server_config = global_config_manager.get_server(server_name) |
717 | | - if not server_config: |
718 | | - print_error( |
719 | | - f"Server '{server_name}' not found", |
720 | | - "Run 'mcpm ls' to see available servers" |
721 | | - ) |
722 | | - return 1 |
723 | | - |
724 | | - # Convert server config to dict for easier manipulation |
725 | | - if isinstance(server_config, STDIOServerConfig): |
726 | | - current_config = { |
727 | | - "name": server_config.name, |
728 | | - "type": "stdio", |
729 | | - "command": server_config.command, |
730 | | - "args": server_config.args, |
731 | | - "env": server_config.env, |
732 | | - } |
733 | | - elif isinstance(server_config, RemoteServerConfig): |
734 | | - current_config = { |
735 | | - "name": server_config.name, |
736 | | - "type": "remote", |
737 | | - "url": server_config.url, |
738 | | - "headers": server_config.headers, |
739 | | - } |
740 | | - else: |
741 | | - print_error("Unknown server type", f"Server '{server_name}' has unknown type") |
742 | | - return 1 |
743 | | - |
744 | | - # Merge updates |
745 | | - updated_config = merge_server_config_updates( |
746 | | - current_config=current_config, |
747 | | - name=new_name, |
748 | | - command=command, |
749 | | - args=args, |
750 | | - env=env, |
751 | | - url=url, |
752 | | - headers=headers, |
753 | | - ) |
754 | | - |
755 | | - # Validate updates make sense for server type |
756 | | - server_type = updated_config["type"] |
757 | | - if server_type == "stdio": |
758 | | - if url or headers: |
759 | | - print_error( |
760 | | - "Invalid parameters for stdio server", |
761 | | - "--url and --headers are only valid for remote servers" |
762 | | - ) |
763 | | - return 1 |
764 | | - elif server_type == "remote": |
765 | | - if command or args: |
766 | | - print_error( |
767 | | - "Invalid parameters for remote server", |
768 | | - "--command and --args are only valid for stdio servers" |
769 | | - ) |
770 | | - return 1 |
771 | | - |
772 | | - # Display changes |
773 | | - console.print(f"\n[bold green]Updating server '{server_name}':[/]") |
774 | | - |
775 | | - # Show what's changing |
776 | | - changes_made = False |
777 | | - if new_name and new_name != current_config["name"]: |
778 | | - console.print(f"Name: [dim]{current_config['name']}[/] → [cyan]{new_name}[/]") |
779 | | - changes_made = True |
780 | | - |
781 | | - if command and command != current_config.get("command"): |
782 | | - console.print(f"Command: [dim]{current_config.get('command', 'None')}[/] → [cyan]{command}[/]") |
783 | | - changes_made = True |
784 | | - |
785 | | - if args and args != " ".join(current_config.get("args", [])): |
786 | | - current_args = " ".join(current_config.get("args", [])) |
787 | | - console.print(f"Arguments: [dim]{current_args or 'None'}[/] → [cyan]{args}[/]") |
788 | | - changes_made = True |
789 | | - |
790 | | - if env: |
791 | | - console.print("Environment: [cyan]Adding/updating variables[/]") |
792 | | - changes_made = True |
793 | | - |
794 | | - if url and url != current_config.get("url"): |
795 | | - console.print(f"URL: [dim]{current_config.get('url', 'None')}[/] → [cyan]{url}[/]") |
796 | | - changes_made = True |
797 | | - |
798 | | - if headers: |
799 | | - console.print("Headers: [cyan]Adding/updating headers[/]") |
800 | | - changes_made = True |
801 | | - |
802 | | - if not changes_made: |
803 | | - console.print("[yellow]No changes specified[/]") |
804 | | - return 0 |
805 | | - |
806 | | - # Create the updated server config object |
807 | | - if server_type == "stdio": |
808 | | - updated_server_config = STDIOServerConfig( |
809 | | - name=updated_config["name"], |
810 | | - command=updated_config["command"], |
811 | | - args=updated_config.get("args", []), |
812 | | - env=updated_config.get("env", {}), |
813 | | - profile_tags=server_config.profile_tags, |
814 | | - ) |
815 | | - else: # remote |
816 | | - updated_server_config = RemoteServerConfig( |
817 | | - name=updated_config["name"], |
818 | | - url=updated_config["url"], |
819 | | - headers=updated_config.get("headers", {}), |
820 | | - profile_tags=server_config.profile_tags, |
821 | | - ) |
822 | | - |
823 | | - # Save the updated server |
824 | | - global_config_manager.remove_server(server_name) |
825 | | - global_config_manager.add_server(updated_server_config) |
826 | | - |
827 | | - console.print(f"[green]✅ Successfully updated server '[cyan]{server_name}[/]'[/]") |
828 | | - |
829 | | - return 0 |
830 | | - |
831 | | - except ValueError as e: |
832 | | - print_error("Invalid parameter", str(e)) |
833 | | - return 1 |
834 | | - except Exception as e: |
835 | | - print_error("Failed to update server", str(e)) |
836 | | - return 1 |
0 commit comments