File size: 2,882 Bytes
2be6245 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | #!/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")
|