-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_hf_space.py
More file actions
108 lines (89 loc) · 2.97 KB
/
test_hf_space.py
File metadata and controls
108 lines (89 loc) · 2.97 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python3
"""
Test script for HuggingFace Space MCP Server.
Usage:
python test_hf_mcp.py
"""
import urllib.request
import urllib.error
import json
import sys
def make_request(url, data=None, follow_redirects=False):
"""Make HTTP request."""
req = urllib.request.Request(url)
req.add_header("Content-Type", "application/json")
req.add_header("Accept", "application/json, text/event-stream")
if data:
req.data = json.dumps(data).encode("utf-8")
try:
# Use a redirect handler that doesn't follow automatically
import http.cookiejar
cj = http.cookiejar.CookieJar()
if follow_redirects:
# Use default opener that follows redirects
opener = urllib.request.build_opener()
else:
# Use opener that doesn't follow redirects
opener = urllib.request.build_opener(urllib.request.HTTPRedirectHandler())
with opener.open(req) as response:
return response.status, response.read().decode("utf-8")
except urllib.error.HTTPError as e:
return e.code, e.read().decode("utf-8")
except urllib.error.URLError as e:
return 0, str(e)
def test_hf_space():
"""Test the HF Space MCP server."""
base_url = "https://alexliberzon-openpiv-mcp.hf.space"
print("=" * 60)
print("Testing HF Space MCP Server")
print("=" * 60)
# Test health
print("\n1. Testing health endpoint...")
status, body = make_request(f"{base_url}/health")
print(f" Status: {status}")
print(f" Body: {body}")
# Test root
print("\n2. Testing root endpoint...")
status, body = make_request(f"{base_url}/")
print(f" Status: {status}")
print(f" Body: {body}")
# Test MCP initialize without redirect following
print("\n3. Testing MCP /mcp (no redirect follow)...")
status, body = make_request(
f"{base_url}/mcp",
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {"name": "test", "version": "1.0"},
},
},
)
print(f" Status: {status}")
print(f" Body: {body[:200] if body else 'empty'}...")
# Test MCP with redirect following
print("\n4. Testing MCP /mcp/ (with redirect follow)...")
status, body = make_request(
f"{base_url}/mcp/",
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {"name": "test", "version": "1.0"},
},
},
follow_redirects=True,
)
print(f" Status: {status}")
print(f" Body: {body[:200] if body else 'empty'}...")
print("\n" + "=" * 60)
print("Test complete")
print("=" * 60)
if __name__ == "__main__":
test_hf_space()