-
Notifications
You must be signed in to change notification settings - Fork 809
Expand file tree
/
Copy pathtest_mcp_tools.py
More file actions
68 lines (62 loc) · 1.73 KB
/
Copy pathtest_mcp_tools.py
File metadata and controls
68 lines (62 loc) · 1.73 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
"""Quick test to list MCP tools on /hr/mcp."""
import json
import sys
import httpx
BASE = "http://127.0.0.1:9000/hr/mcp"
HEADERS = {
"Content-Type": "application/json",
"Accept": "application/json, text/event-stream",
}
# 1. Initialize
r = httpx.post(
BASE,
json={
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-03-26",
"capabilities": {},
"clientInfo": {"name": "test", "version": "1.0"},
},
},
headers=HEADERS,
)
print("Init status:", r.status_code)
print("Init body:", r.text[:500])
sid = r.headers.get("mcp-session-id", "")
print("Session ID:", sid[:40] if sid else "NONE")
if not sid:
print("No session ID, aborting")
sys.exit(1)
# 2. List tools
HEADERS["mcp-session-id"] = sid
r2 = httpx.post(
BASE,
json={"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": {}},
headers=HEADERS,
)
print("\nTools status:", r2.status_code)
body = r2.text
print("Raw response (first 300):", body[:300])
# Try to parse SSE or JSON
for line in body.splitlines():
if line.startswith("data:"):
payload = line[len("data:"):].strip()
if payload:
data = json.loads(payload)
tools = data.get("result", {}).get("tools", [])
print(f"\n{len(tools)} tools found:")
for t in tools:
print(f" - {t['name']}")
break
else:
# Maybe it's plain JSON
try:
data = json.loads(body)
tools = data.get("result", {}).get("tools", [])
print(f"\n{len(tools)} tools found:")
for t in tools:
print(f" - {t['name']}")
except json.JSONDecodeError:
print("Could not parse response")