mcp / test_standalone.py
jdewitte's picture
Initial commit
2be6245
Raw
History Blame Contribute Delete
2.88 kB
#!/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")