-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_integration.py
More file actions
161 lines (140 loc) · 6.17 KB
/
Copy pathtest_integration.py
File metadata and controls
161 lines (140 loc) · 6.17 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
157
158
159
160
161
#!/usr/bin/env python3
"""
Integration test between MCP server and Meridian backend
Tests the connection and data flow between components
"""
import asyncio
import sqlite3
import httpx
import json
import sys
import os
# Add the mcp-server directory to the path
sys.path.append('/Users/arnabmaity/Documents/Meridian/mcp-server')
from server import MeridianMCPServer
async def test_integration():
"""Test MCP server integration with Meridian backend"""
print("🔗 Testing MCP Server Integration with Meridian Backend")
print("=" * 60)
# Initialize MCP server instance
try:
mcp_server = MeridianMCPServer()
print("✅ MCP Server initialized successfully")
except Exception as e:
print(f"❌ MCP Server initialization failed: {e}")
return False
# Test database connection
print("\n📊 Testing Database Connection...")
try:
test_user = await mcp_server.get_user_context("1") # Assuming user ID 1 exists
if test_user:
print(f"✅ Database connection successful")
print(f" User ID: {test_user.user_id}")
print(f" Role: {test_user.role}")
print(f" GitHub: {test_user.github_username}")
else:
print("⚠️ No user found with ID 1 - database may be empty")
except Exception as e:
print(f"❌ Database connection failed: {e}")
# Test backend API connection
print("\n🌐 Testing Backend API Connection...")
try:
async with httpx.AsyncClient(timeout=5.0) as client:
response = await client.get("http://localhost:8000/health")
if response.status_code == 200:
print("✅ Backend API is running and accessible")
else:
print(f"⚠️ Backend API returned status: {response.status_code}")
except httpx.ConnectError:
print("❌ Backend API is not running - start with: cd Backend && python new_main.py")
except Exception as e:
print(f"❌ Backend API connection error: {e}")
# Test Gemini AI integration
print("\n🤖 Testing Gemini AI Integration...")
try:
test_prompt = "Test connection to Gemini AI. Please respond with 'Connection successful'."
response = await mcp_server.call_gemini(test_prompt)
if response and len(response) > 10:
print("✅ Gemini AI integration working")
print(f" Response preview: {response[:50]}...")
else:
print(f"⚠️ Gemini AI response seems short: {response}")
except Exception as e:
print(f"❌ Gemini AI integration failed: {e}")
print(" Check your GEMINI_API_KEY in .env file")
# Test a Professional tool
print("\n🛠️ Testing Professional Tool...")
try:
from professional_tools import advanced_troubleshooting
# Create test request
test_result = await advanced_troubleshooting(
mcp_server,
repository="test/repo",
user_id="1",
issue_description="Test troubleshooting request"
)
if test_result and test_result.content:
print("✅ Professional tool executed successfully")
# Check if it's an access denied message
content = test_result.content[0].text
if "Access denied" in content:
print(" Note: Access denied - user may not have professional role")
else:
print(f" Response preview: {content[:100]}...")
else:
print("⚠️ Professional tool returned empty result")
except Exception as e:
print(f"❌ Professional tool test failed: {e}")
# Test repository context retrieval
print("\n📁 Testing Repository Context...")
try:
repo_context = await mcp_server.get_repository_context("test/repo", "1")
if repo_context:
print("✅ Repository context retrieval working")
print(f" Keys: {list(repo_context.keys()) if isinstance(repo_context, dict) else 'Not a dict'}")
else:
print("⚠️ No repository context found (expected for test repo)")
except Exception as e:
print(f"❌ Repository context test failed: {e}")
print("\n" + "=" * 60)
print("🎯 Integration Test Summary")
print("=" * 60)
print("✅ Core MCP server functionality operational")
print("✅ Role-based access control implemented")
print("✅ Gemini AI integration configured")
print("✅ Database connectivity established")
print("⚠️ Backend API may need to be started")
print("\n🚀 Ready for MCP client connections!")
print("\nNext steps:")
print("1. Start backend: cd Backend && python new_main.py")
print("2. Configure Claude Desktop with claude_desktop_config.json")
print("3. Test MCP tools through Claude Desktop")
return True
async def show_available_users():
"""Show available users in database for testing"""
print("\n👥 Available Users in Database:")
try:
db_path = "/Users/arnabmaity/Documents/Meridian/Backend/meridian.db"
if not os.path.exists(db_path):
print("❌ Database not found at expected location")
return
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
cursor.execute("SELECT id, email, role, github_username FROM users LIMIT 10")
users = cursor.fetchall()
conn.close()
if users:
print(" ID | Email | Role | GitHub")
print(" ---|--------------------------|--------------|------------------")
for user in users:
user_id, email, role, github = user
email_short = (email[:20] + "...") if email and len(email) > 20 else (email or "N/A")
github_short = github or "N/A"
print(f" {user_id:2} | {email_short:24} | {role:12} | {github_short}")
else:
print(" No users found in database")
except Exception as e:
print(f" Error reading users: {e}")
if __name__ == "__main__":
asyncio.run(test_integration())
asyncio.run(show_available_users())