Skip to main content
Glama

Browser MCP Server

by sac916
test_final_mcp.pyโ€ข6.1 kB
#!/usr/bin/env python3 """ Final comprehensive test of the fixed MCP server. """ import subprocess import sys import json def test_final_mcp(): """Comprehensive test of the fixed MCP server""" print("๐Ÿงช Final comprehensive MCP server test...") # Test 1: Basic functionality print("\n๐Ÿ” Test 1: Basic initialization and tools listing") input_sequence = [ { "jsonrpc": "2.0", "id": 1, "method": "initialize", "params": { "protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test-client", "version": "1.0.0"} } }, { "jsonrpc": "2.0", "method": "notifications/initialized" }, { "jsonrpc": "2.0", "id": 2, "method": "tools/list" } ] input_text = "\n".join([json.dumps(msg) for msg in input_sequence]) + "\n" try: result = subprocess.run([ sys.executable, "-m", "src.server" ], input=input_text, capture_output=True, text=True, timeout=10) # Parse responses responses = [] for line in result.stdout.strip().split('\n'): if line.strip(): try: responses.append(json.loads(line)) except json.JSONDecodeError: print(f"โŒ Invalid JSON: {line}") # Validate basic functionality if len(responses) >= 2: init_resp = responses[0] tools_resp = responses[1] # Check initialization if (init_resp.get("jsonrpc") == "2.0" and "result" in init_resp and "capabilities" in init_resp["result"]): print("โœ… Initialization response valid") else: print("โŒ Initialization response invalid") return False # Check tools list if (tools_resp.get("jsonrpc") == "2.0" and "result" in tools_resp and "tools" in tools_resp["result"]): tools = tools_resp["result"]["tools"] print(f"โœ… Tools list valid: {len(tools)} tools found") # Check tool structure for tool in tools: if all(key in tool for key in ["name", "description", "inputSchema"]): print(f" โœ… Tool '{tool['name']}' has valid structure") else: print(f" โŒ Tool '{tool.get('name', 'unknown')}' missing required fields") else: print("โŒ Tools list response invalid") return False else: print(f"โŒ Expected 2+ responses, got {len(responses)}") return False except Exception as e: print(f"โŒ Test 1 failed: {e}") return False # Test 2: Error handling print("\n๐Ÿ” Test 2: Error handling") error_test_sequence = [ { "jsonrpc": "2.0", "id": 1, "method": "initialize", "params": { "protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test-client", "version": "1.0.0"} } }, { "jsonrpc": "2.0", "method": "notifications/initialized" }, { "jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": { "name": "navigate_to", "arguments": {} # Missing required 'url' } } ] input_text = "\n".join([json.dumps(msg) for msg in error_test_sequence]) + "\n" try: result = subprocess.run([ sys.executable, "-m", "src.server" ], input=input_text, capture_output=True, text=True, timeout=10) # Parse responses responses = [] for line in result.stdout.strip().split('\n'): if line.strip(): try: responses.append(json.loads(line)) except json.JSONDecodeError: pass # Look for error response error_found = False for resp in responses: if (resp.get("jsonrpc") == "2.0" and "result" in resp and resp["result"].get("isError") == True): print("โœ… Error properly handled and formatted") error_found = True break if not error_found: print("โŒ Error not properly handled") return False except Exception as e: print(f"โŒ Test 2 failed: {e}") return False # Test 3: Protocol compliance print("\n๐Ÿ” Test 3: Protocol compliance checks") # Check stdout only contains JSON-RPC if result.stderr and not result.stdout.strip().startswith('{"jsonrpc"'): print("โŒ stdout contains non-JSON content") return False else: print("โœ… stdout only contains JSON-RPC messages") # Check stderr contains logs if "INFO" in result.stderr or "ERROR" in result.stderr: print("โœ… Logs properly directed to stderr") else: print("โš ๏ธ No logs found in stderr (may be normal)") print("\n๐ŸŽ‰ All tests passed! MCP server is working correctly.") print("\n๐Ÿ“‹ Summary of fixes applied:") print(" โœ… Fixed logging to stderr only") print(" โœ… Implemented proper MCP initialization handshake") print(" โœ… Fixed tools/list response format") print(" โœ… Added proper error handling for JSON-RPC methods") print(" โœ… Ensured MCP-compliant response formats") return True if __name__ == "__main__": success = test_final_mcp() sys.exit(0 if success else 1)

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sac916/claude-browser-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server