-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathtest_mcp_client.py
More file actions
executable file
·107 lines (100 loc) · 3.09 KB
/
test_mcp_client.py
File metadata and controls
executable file
·107 lines (100 loc) · 3.09 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
#!/usr/bin/env python3
"""
Test MCP client simulator to diagnose validation errors
"""
import json
import subprocess
import sys
def send_request(request):
"""Send a request to the MCP server and return the response"""
try:
proc = subprocess.Popen(
['./odata-mcp'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
stdout, stderr = proc.communicate(json.dumps(request))
if stderr:
print(f"STDERR: {stderr}", file=sys.stderr)
return json.loads(stdout) if stdout else None
except Exception as e:
print(f"Error: {e}", file=sys.stderr)
return None
def test_edge_cases():
"""Test various edge cases that might cause validation errors"""
tests = [
# Test 1: Standard initialize
{
"name": "Standard initialize",
"request": {
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {"name": "test", "version": "1.0"}
}
}
},
# Test 2: Initialize with missing params
{
"name": "Initialize without params",
"request": {
"jsonrpc": "2.0",
"id": 2,
"method": "initialize"
}
},
# Test 3: Tools/list with extra params
{
"name": "Tools/list with cursor",
"request": {
"jsonrpc": "2.0",
"id": 3,
"method": "tools/list",
"params": {"cursor": None}
}
},
# Test 4: Tools/call with missing arguments
{
"name": "Tools/call without arguments",
"request": {
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "odata_service_info_for_Z001"
}
}
},
# Test 5: Tools/call with null arguments
{
"name": "Tools/call with null arguments",
"request": {
"jsonrpc": "2.0",
"id": 5,
"method": "tools/call",
"params": {
"name": "odata_service_info_for_Z001",
"arguments": None
}
}
}
]
for test in tests:
print(f"\n=== {test['name']} ===")
response = send_request(test['request'])
if response:
if 'error' in response:
print(f"ERROR: {response['error']}")
else:
print(f"SUCCESS: Got result with keys: {list(response.get('result', {}).keys())}")
else:
print("FAILED: No response")
if __name__ == "__main__":
print("MCP Server Edge Case Testing")
print("============================")
test_edge_cases()