Test server-specific commands.
(config_file="server_config.json")
| 90 | |
| 91 | |
| 92 | def test_server_commands(config_file="server_config.json"): |
| 93 | """Test server-specific commands.""" |
| 94 | print("\n" + "=" * 50) |
| 95 | print("🧪 Testing Server Commands") |
| 96 | print("=" * 50) |
| 97 | |
| 98 | config_valid, servers = check_config_file(config_file) |
| 99 | if not config_valid: |
| 100 | return [("Config check", False)] |
| 101 | |
| 102 | results = [("Config check", True)] |
| 103 | |
| 104 | # Test commands that work with servers |
| 105 | server_tests = [ |
| 106 | (["servers", "--config-file", config_file], "List servers"), |
| 107 | (["tools", "--config-file", config_file], "List all tools"), |
| 108 | (["prompts", "--config-file", config_file], "List prompts"), |
| 109 | (["resources", "--config-file", config_file], "List resources"), |
| 110 | ] |
| 111 | |
| 112 | for args, description in server_tests: |
| 113 | print(f"\n📝 {description}") |
| 114 | success, stdout, stderr = test_mcp_cli_command(args, timeout=45) |
| 115 | |
| 116 | if success: |
| 117 | print(f"✅ PASS: {description}") |
| 118 | # Show a preview of output |
| 119 | if stdout: |
| 120 | lines = stdout.strip().split("\n") |
| 121 | # Filter out startup messages |
| 122 | content_lines = [ |
| 123 | line |
| 124 | for line in lines |
| 125 | if not ( |
| 126 | "MCP CLI ready" in line |
| 127 | or "Available commands:" in line |
| 128 | or "Use --help" in line |
| 129 | or line.startswith(" ") |
| 130 | ) |
| 131 | ] |
| 132 | preview = content_lines[:3] if len(content_lines) > 3 else content_lines |
| 133 | for line in preview: |
| 134 | if line.strip(): # Only show non-empty lines |
| 135 | print(f" 📄 {line[:80]}...") |
| 136 | if len(content_lines) > 3: |
| 137 | print(f" ... and {len(content_lines) - 3} more lines") |
| 138 | else: |
| 139 | print(f"❌ FAIL: {description}") |
| 140 | if stderr: |
| 141 | print(f" Error: {stderr[:300]}...") |
| 142 | |
| 143 | results.append((description, success)) |
| 144 | |
| 145 | # Test individual servers if we have them |
| 146 | for server in servers[:2]: # Test max 2 servers to keep it manageable |
| 147 | print(f"\n📝 Testing server: {server}") |
| 148 | success, stdout, stderr = test_mcp_cli_command( |
| 149 | ["tools", "--config-file", config_file, "--server", server], timeout=30 |
no test coverage detected