#!/usr/bin/env python3 """ Test the standalone MCP Server """ import requests import json def test_mcp_server(base_url="http://localhost:8081"): """Test the MCP server endpoints""" print(f"๐Ÿงช Testing MCP Server at {base_url}") print("=" * 60) # Test health check print("\n1. Testing Health Check...") try: response = requests.get(f"{base_url}/health") print(f"โœ… Health Check: {response.status_code}") print(f" Response: {response.json()}") except Exception as e: print(f"โŒ Health Check Failed: {e}") return False # Test tools list print("\n2. Testing Tools List...") try: payload = { "jsonrpc": "2.0", "method": "tools/list", "id": "test-tools-list" } response = requests.post(f"{base_url}/", json=payload) print(f"โœ… Tools List: {response.status_code}") result = response.json() tools = result.get("result", {}).get("tools", []) print(f" Available tools: {len(tools)}") for tool in tools: print(f" - {tool['name']}: {tool['description']}") except Exception as e: print(f"โŒ Tools List Failed: {e}") return False # Test tool call print("\n3. Testing Tool Call...") try: payload = { "jsonrpc": "2.0", "method": "tools/call", "params": { "name": "get_product_details", "arguments": {"product_id": 123} }, "id": "test-tool-call" } response = requests.post(f"{base_url}/", json=payload) print(f"โœ… Tool Call: {response.status_code}") result = response.json() content = result.get("result", {}).get("content", [{}])[0].get("text", "No content") print(f" Response: {content[:200]}...") except Exception as e: print(f"โŒ Tool Call Failed: {e}") return False return True def test_huggingface_space(space_url): """Test a deployed Hugging Face Space""" print(f"\n๐Ÿš€ Testing Hugging Face Space") print(f"URL: {space_url}") return test_mcp_server(space_url) if __name__ == "__main__": print("๐Ÿ”ง Standalone MCP Server Tests") print("=" * 80) # Test local server success = test_mcp_server() print("\n" + "=" * 80) if success: print("โœ… All tests passed!") print("\n๐Ÿ“‹ MCP Server is ready for deployment") print("๐Ÿš€ Deploy to Hugging Face Spaces:") print(" 1. Create new Space with Docker SDK") print(" 2. Upload all files from mcp_server/ directory") print(" 3. Set app_port to 8081") print(" 4. Test with the URL above") else: print("โŒ Some tests failed!") print("๐Ÿ”ง Check server configuration and try again")