-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_mcp.py
More file actions
97 lines (84 loc) · 2.82 KB
/
test_mcp.py
File metadata and controls
97 lines (84 loc) · 2.82 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
#!/usr/bin/env python3
"""
Test script for MCP server
"""
import subprocess
import json
import sys
import time
def test_mcp_server():
"""Test the MCP server functionality"""
print("Testing MCP server...")
# Start the server
process = subprocess.Popen(
[sys.executable, "server.py", "--mcp"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
try:
# Test initialize
init_request = {
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {"name": "test-client", "version": "1.0.0"}
}
}
print("Sending initialize request...")
process.stdin.write(json.dumps(init_request) + "\n")
process.stdin.flush()
# Read response
response_line = process.stdout.readline()
if response_line:
response = json.loads(response_line.strip())
print(f"Initialize response: {json.dumps(response, indent=2)}")
if response.get("result"):
print("✅ Initialize successful")
else:
print("❌ Initialize failed")
return False
else:
print("❌ No response received")
return False
# Test tools/list
tools_request = {
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list",
"params": {}
}
print("\nSending tools/list request...")
process.stdin.write(json.dumps(tools_request) + "\n")
process.stdin.flush()
# Read response
response_line = process.stdout.readline()
if response_line:
response = json.loads(response_line.strip())
print(f"Tools list response: {json.dumps(response, indent=2)}")
if response.get("result") and "tools" in response["result"]:
tools = response["result"]["tools"]
print(f"✅ Found {len(tools)} tools")
for tool in tools:
print(f" - {tool['name']}: {tool['description']}")
else:
print("❌ Tools list failed")
return False
else:
print("❌ No response received")
return False
print("\n✅ MCP server test completed successfully!")
return True
except Exception as e:
print(f"❌ Test failed with error: {e}")
return False
finally:
process.terminate()
process.wait()
if __name__ == "__main__":
success = test_mcp_server()
sys.exit(0 if success else 1)