forked from nlweb-ai/NLWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_mcp.py
More file actions
executable file
·90 lines (77 loc) · 1.91 KB
/
test_mcp.py
File metadata and controls
executable file
·90 lines (77 loc) · 1.91 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
#!/usr/bin/env python3
"""
Test script for MCP endpoint with JSON-RPC format
"""
import json
import requests
# Test server URL
url = "http://localhost:8000/mcp"
# Test 1: Initialize
print("Test 1: Initialize")
init_request = {
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05"
}
}
try:
response = requests.post(url, json=init_request)
print(f"Status: {response.status_code}")
print(f"Response: {json.dumps(response.json(), indent=2)}")
except Exception as e:
print(f"Error: {e}")
print("\n" + "-"*50 + "\n")
# Test 2: List tools
print("Test 2: List tools")
list_tools_request = {
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list",
"params": {}
}
try:
response = requests.post(url, json=list_tools_request)
print(f"Status: {response.status_code}")
print(f"Response: {json.dumps(response.json(), indent=2)}")
except Exception as e:
print(f"Error: {e}")
print("\n" + "-"*50 + "\n")
# Test 3: Call the ask tool
print("Test 3: Call ask tool")
ask_request = {
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "ask",
"arguments": {
"query": "test query"
}
}
}
try:
response = requests.post(url, json=ask_request)
print(f"Status: {response.status_code}")
print(f"Response: {json.dumps(response.json(), indent=2)}")
except Exception as e:
print(f"Error: {e}")
print("\n" + "-"*50 + "\n")
# Test 4: Call the get_sites tool
print("Test 4: Call get_sites tool")
get_sites_request = {
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "get_sites",
"arguments": {}
}
}
try:
response = requests.post(url, json=get_sites_request)
print(f"Status: {response.status_code}")
print(f"Response: {json.dumps(response.json(), indent=2)}")
except Exception as e:
print(f"Error: {e}")