-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_github_tools_profile.py
More file actions
156 lines (132 loc) · 5.26 KB
/
test_github_tools_profile.py
File metadata and controls
156 lines (132 loc) · 5.26 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
"""Test GitHub MCP tools using FastMCP in-memory client (PROFILE-BASED VERSION)."""
import asyncio
import sys
import os
# Add src to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
from fastmcp import Client
from mcp_server import mcp
async def test_list_user_repos():
"""Test list_user_github_repos tool with PROFILE parameter."""
print("\n" + "="*70)
print("Testing list_user_github_repos (PROFILE-BASED)")
print("="*70)
async with Client(mcp) as client:
# Test 1: List repos using avi-cohen profile
print("\n1️⃣ Testing with profile='avi-cohen', limit=5")
print(" (Should load username from profile config)")
result = await client.call_tool(
"list_user_github_repos",
arguments={
"profile": "avi-cohen",
"limit": 5
}
)
print(f" Result type: {type(result)}")
if result.content:
import json
content = result.content[0].text
data = json.loads(content)
print(f" ✅ Profile: {data.get('profile')}")
print(f" ✅ Username (from profile): {data.get('username')}")
print(f" ✅ Count: {data.get('count')}")
print(f" ✅ Repos found: {len(data.get('repositories', []))}")
if data.get('repositories'):
print(f"\n First repo:")
first_repo = data['repositories'][0]
print(f" - Name: {first_repo.get('name')}")
print(f" - URL: {first_repo.get('url')}")
print(f" - Stars: {first_repo.get('stars')}")
# Test 2: List repos using default profile
print("\n2️⃣ Testing with default profile (should use avi-cohen), limit=3")
result = await client.call_tool(
"list_user_github_repos",
arguments={
"limit": 3,
"type_filter": "owner"
}
)
if result.content:
content = result.content[0].text
data = json.loads(content)
print(f" ✅ Profile: {data.get('profile')}")
print(f" ✅ Username: {data.get('username')}")
print(f" ✅ Count: {data.get('count')}")
if data.get('repositories'):
print(f"\n Top 3 repos:")
for repo in data['repositories'][:3]:
print(f" - {repo.get('name')} ({repo.get('stars')} ⭐)")
async def test_search_repos():
"""Test search_github_repos tool with PROFILE-BASED AUTO-SCOPING."""
print("\n" + "="*70)
print("Testing search_github_repos (PROFILE-BASED AUTO-SCOPING)")
print("="*70)
async with Client(mcp) as client:
print("\n🔍 Test 1: query='RAG', profile='avi-cohen', limit=5")
print(" (Should auto-inject: user:aviciot)")
result = await client.call_tool(
"search_github_repos",
arguments={
"query": "RAG",
"profile": "avi-cohen",
"limit": 5
}
)
if result.content:
import json
content = result.content[0].text
data = json.loads(content)
print(f" ✅ Query sent to GitHub: {data.get('query')}")
print(f" ✅ Profile: {data.get('profile')}")
print(f" ✅ Count: {data.get('count')}")
if data.get('repositories'):
print(f"\n Repos found:")
for repo in data['repositories']:
print(f" - {repo.get('name')} ({repo.get('stars')} ⭐)")
async def test_get_file():
"""Test get_github_file tool (unchanged - no profile parameter)."""
print("\n" + "="*70)
print("Testing get_github_file")
print("="*70)
async with Client(mcp) as client:
print("\n📄 Testing with owner='aviciot', repo='learning-mcp', path='README.md'")
result = await client.call_tool(
"get_github_file",
arguments={
"owner": "aviciot",
"repo": "learning-mcp",
"path": "README.md"
}
)
if result.content:
import json
content = result.content[0].text
data = json.loads(content)
print(f" ✅ Name: {data.get('name')}")
print(f" ✅ Size: {data.get('size')} bytes")
print(f" ✅ URL: {data.get('url')}")
if data.get('content'):
preview = data['content'][:200]
print(f"\n Content preview:")
print(f" {preview}...")
async def main():
"""Run all tests."""
print("\n" + "="*70)
print("🧪 GitHub MCP Tools Test Suite (PROFILE-BASED VERSION)")
print("="*70)
try:
await test_list_user_repos()
await test_search_repos()
await test_get_file()
print("\n" + "="*70)
print("✅ All tests completed successfully!")
print("="*70)
except Exception as e:
print(f"\n❌ Test failed: {e}")
import traceback
traceback.print_exc()
return 1
return 0
if __name__ == "__main__":
exit_code = asyncio.run(main())
sys.exit(exit_code)