Download test_standalone.py from jdewitte/mcp: direct link, hf CLI and curl.
- Browser
- Download file 2.88 kB
-
https://huggingface.co/spaces/jdewitte/mcp/resolve/main/test_standalone.py
- Command line
-
hf download hf://spaces/jdewitte/mcp/test_standalone.py
-
curl -L -o test_standalone.py https://huggingface.co/spaces/jdewitte/mcp/resolve/main/test_standalone.py
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") | |