-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_mcp.py
More file actions
97 lines (87 loc) · 3.27 KB
/
Copy pathtest_mcp.py
File metadata and controls
97 lines (87 loc) · 3.27 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 GitHub MCP server operations"""
import subprocess
import json
import os
def test_github_mcp():
github_token = subprocess.check_output(['gh', 'auth', 'token'], text=True).strip()
# Test data for different operations
tests = [
{
"name": "List Issues",
"method": "tools/call",
"params": {
"name": "list_issues",
"arguments": {
"owner": "mirichard",
"repo": "warp-github-mcp-demo"
}
}
},
{
"name": "Get Repository Info",
"method": "tools/call",
"params": {
"name": "get_file_contents",
"arguments": {
"owner": "mirichard",
"repo": "warp-github-mcp-demo",
"path": "README.md"
}
}
},
{
"name": "List Commits",
"method": "tools/call",
"params": {
"name": "list_commits",
"arguments": {
"owner": "mirichard",
"repo": "warp-github-mcp-demo",
"perPage": 3
}
}
}
]
print("🧪 Testing GitHub MCP Operations")
print("=" * 50)
for i, test in enumerate(tests, 1):
print(f"\n{i}. {test['name']}")
print("-" * 30)
# Prepare the JSON-RPC messages
init_msg = json.dumps({"jsonrpc": "2.0", "method": "initialize", "params": {}, "id": 1})
test_msg = json.dumps({"jsonrpc": "2.0", "method": test["method"], "params": test["params"], "id": 2})
input_data = f"{init_msg}\n{test_msg}\n"
try:
# Run the Docker command
cmd = [
"docker", "run", "-i", "--rm",
"-e", f"GITHUB_PERSONAL_ACCESS_TOKEN={github_token}",
"ghcr.io/github/github-mcp-server"
]
result = subprocess.run(cmd, input=input_data, text=True,
capture_output=True, timeout=10)
# Parse the output
lines = result.stdout.strip().split('\n')
for line in lines:
if line.startswith('{"jsonrpc"') and '"id":2' in line:
response = json.loads(line)
if "result" in response:
content = response["result"]["content"][0]["text"]
# Pretty print JSON if it's JSON
try:
parsed_content = json.loads(content)
print(json.dumps(parsed_content, indent=2)[:500] + "...")
except:
print(content[:500] + "...")
elif "error" in response:
print(f"❌ Error: {response['error']}")
break
else:
print("✅ Operation completed (no direct output)")
except subprocess.TimeoutExpired:
print("⏱️ Operation timed out")
except Exception as e:
print(f"❌ Error: {e}")
if __name__ == "__main__":
test_github_mcp()