Test a single runtime server configuration.
(
pref_manager, server_name: str, test_tool_info: Dict[str, Any]
)
| 910 | |
| 911 | |
| 912 | async def test_single_runtime_server( |
| 913 | pref_manager, server_name: str, test_tool_info: Dict[str, Any] |
| 914 | ) -> bool: |
| 915 | """Test a single runtime server configuration.""" |
| 916 | try: |
| 917 | from mcp_cli.tools.manager import ToolManager |
| 918 | import tempfile |
| 919 | import json |
| 920 | import asyncio |
| 921 | |
| 922 | # Create a temporary server config with ONLY this server |
| 923 | temp_config = {"mcpServers": {}} |
| 924 | |
| 925 | # Get ONLY the specific server we're testing |
| 926 | server_config = pref_manager.get_runtime_server(server_name) |
| 927 | if not server_config: |
| 928 | print(f" ❌ Server '{server_name}' not found in preferences") |
| 929 | return False |
| 930 | |
| 931 | # Add only this server to the config |
| 932 | if server_config.get("transport") == "stdio": |
| 933 | temp_config["mcpServers"][server_name] = { |
| 934 | "command": server_config.get("command"), |
| 935 | "args": server_config.get("args", []), |
| 936 | } |
| 937 | if server_config.get("env"): |
| 938 | temp_config["mcpServers"][server_name]["env"] = server_config.get("env") |
| 939 | elif server_config.get("transport") in ["http", "sse"]: |
| 940 | temp_config["mcpServers"][server_name] = {"url": server_config.get("url")} |
| 941 | |
| 942 | if not temp_config["mcpServers"]: |
| 943 | return False |
| 944 | |
| 945 | # Save temp config to test |
| 946 | with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as f: |
| 947 | json.dump(temp_config, f) |
| 948 | temp_config_file = f.name |
| 949 | |
| 950 | try: |
| 951 | # Try to initialize with the runtime server (with timeout) |
| 952 | print(" Attempting connection...") |
| 953 | tm = ToolManager(temp_config_file, [server_name]) |
| 954 | |
| 955 | # Use a longer timeout for uvx servers (they need to download first time) |
| 956 | try: |
| 957 | success = await asyncio.wait_for(tm.initialize(), timeout=15.0) |
| 958 | except asyncio.TimeoutError: |
| 959 | print(" ⏱️ Connection timed out (server may not be installed)") |
| 960 | return False |
| 961 | except asyncio.CancelledError: |
| 962 | print( |
| 963 | " ⚠️ Connection timeout (uvx servers work but may need manual testing)" |
| 964 | ) |
| 965 | print( |
| 966 | " 💡 To test manually: mcp-cli tools --server time-test --config-file <config>" |
| 967 | ) |
| 968 | return False |
| 969 | except Exception as e: |
no test coverage detected