-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
83 lines (68 loc) · 2.38 KB
/
Copy pathtest_api.py
File metadata and controls
83 lines (68 loc) · 2.38 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
#!/usr/bin/env python3
"""
Test script for the Games MCP API
Run this after deploying to verify everything works correctly
"""
import requests
import json
import sys
from typing import Optional
def test_endpoint(url: str, endpoint: str, params: Optional[dict] = None) -> bool:
"""Test a single endpoint and return success status"""
try:
full_url = f"{url}{endpoint}"
print(f"Testing: {full_url}")
if params:
print(f" Params: {params}")
response = requests.get(full_url, params=params, timeout=10)
if response.status_code == 200:
print(f" ✅ Success: {response.status_code}")
if 'application/json' in response.headers.get('content-type', ''):
data = response.json()
print(f" Response: {json.dumps(data, indent=2)}")
else:
print(f" Response: {response.text[:100]}...")
return True
else:
print(f" ❌ Failed: {response.status_code}")
print(f" Error: {response.text}")
return False
except requests.exceptions.RequestException as e:
print(f" ❌ Request failed: {e}")
return False
def main():
# Get URL from command line or use localhost
if len(sys.argv) > 1:
base_url = sys.argv[1].rstrip('/')
else:
base_url = "http://localhost:8000"
print(f"Testing Games MCP API at: {base_url}")
print("=" * 50)
tests = [
# Health check
("/health", None),
# Text endpoints
("/flip-coin", {"flips": 3}),
("/roll-dice", {"dice": 2, "sides": 6}),
("/roll-custom", {"expression": "2d6+5"}),
# JSON endpoints
("/api/flip-coin", {"flips": 5}),
("/api/roll-dice", {"dice": 3, "sides": 20}),
("/api/roll-custom", {"expression": "4d6+2"}),
]
passed = 0
total = len(tests)
for endpoint, params in tests:
if test_endpoint(base_url, endpoint, params):
passed += 1
print()
print("=" * 50)
print(f"Results: {passed}/{total} tests passed")
if passed == total:
print("🎉 All tests passed! Your API is working correctly.")
return 0
else:
print("❌ Some tests failed. Check the errors above.")
return 1
if __name__ == "__main__":
sys.exit(main())