import asyncio import json from mcp_server import list_servers, run_speedtest async def main(): print("--- 1. Testing Discovery: list_servers('Singapore') ---") servers_json = await list_servers("Singapore") servers = json.loads(servers_json) print(f"Found {len(servers)} servers.") if not servers: print("No servers found!") return # Print found servers for s in servers: print(f"ID: {s['id']} | Name: {s['name']} | Sponsor: {s['sponsor']}") # Pick the Singtel server (ID 13623) if available, otherwise the first one target_server = next((s for s in servers if str(s['id']) == "13623"), servers[0]) target_id = target_server['id'] target_name = target_server['sponsor'] print(f"\n--- 2. Testing Execution: run_speedtest({target_id}) [{target_name}] ---") print("Running speedtest... (Please wait ~30 seconds)...") # Run the speedtest result_json = run_speedtest(int(target_id)) try: data = json.loads(result_json) if "error" in data: print(f"Error from speedtest: {data['error']}") else: # Convert bytes/sec to Mbps (1 Mbps = 125,000 bytes/sec) dl_mbps = data['download']['bandwidth'] / 125000 ul_mbps = data['upload']['bandwidth'] / 125000 ping = data['ping']['latency'] print(f"\nSUCCESS! Results for {target_name}:") print(f"Ping: {ping} ms") print(f"Download: {dl_mbps:.2f} Mbps") print(f"Upload: {ul_mbps:.2f} Mbps") print(f"Link: {data['result']['url']}") except Exception as e: print(f"Failed to parse results: {e}") print(f"Raw Output: {result_json}") if __name__ == "__main__": asyncio.run(main())