-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_script.py
More file actions
134 lines (119 loc) · 4.07 KB
/
debug_script.py
File metadata and controls
134 lines (119 loc) · 4.07 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
#!/usr/bin/env python3
"""
Test script to check which MCP servers are working
Run this before running your main client
"""
import asyncio
import sys
import os
from langchain_mcp_adapters.client import MultiServerMCPClient
async def test_individual_server(name, config):
"""Test a single MCP server"""
print(f"Testing {name}...", end=" ", flush=True)
try:
# Create client with just this server
test_client = MultiServerMCPClient({name: config})
tools = await test_client.get_tools()
print(f"✅ OK ({len(tools)} tools)")
# Print tool names for debugging
tool_names = [tool.name for tool in tools]
if tool_names:
print(f" Tools: {', '.join(tool_names)}")
return True, len(tools), tool_names
except Exception as e:
print(f"❌ FAILED: {str(e)}")
return False, 0, []
async def main():
"""Test all MCP servers"""
print("MCP Server Connectivity Test")
print("=" * 40)
python_exec = sys.executable
servers = {
"math_server": {
"command": python_exec,
"args": ["mathserver.py"],
"transport": "stdio",
},
"weather": {
"command": python_exec,
"args": ["weather.py"],
"transport": "stdio",
},
"Translate": {
"command": python_exec,
"args": ["translate.py"],
"transport": "stdio",
},
"websearch": {
"command": python_exec,
"args": ["websearch.py"],
"transport": "stdio",
},
"gmail": {
"command": python_exec,
"args": ["gmail.py"],
"transport": "stdio",
},
"spotify": {
"command": python_exec,
"args": ["spotify.py"],
"transport": "stdio",
}
}
working_servers = {}
failed_servers = {}
total_tools = 0
for name, config in servers.items():
# Check if file exists for stdio servers
if config.get("transport") == "stdio":
script_file = config["args"][0]
if not os.path.exists(script_file):
print(f"Testing {name}... ❌ FAILED: File {script_file} not found")
failed_servers[name] = f"File {script_file} not found"
continue
success, tool_count, tool_names = await test_individual_server(name, config)
if success:
working_servers[name] = {
"config": config,
"tool_count": tool_count,
"tools": tool_names
}
total_tools += tool_count
else:
failed_servers[name] = "Connection failed"
print("\n" + "=" * 40)
print("SUMMARY")
print("=" * 40)
if working_servers:
print(f"✅ Working servers ({len(working_servers)}):")
for name, info in working_servers.items():
print(f" {name}: {info['tool_count']} tools")
print(f"\nTotal tools available: {total_tools}")
else:
print("No servers are working!")
if failed_servers:
print(f"\n Failed servers ({len(failed_servers)}):")
for name, reason in failed_servers.items():
print(f" {name}: {reason}")
print("\n" + "=" * 40)
if working_servers:
print("Tools are available")
return True
else:
print(" Fix the server issues before running client.py")
print("\nTroubleshooting tips:")
print("1. Make sure all .py files exist in the current directory")
print("2. Check that your .env file has GROQ_API_KEY")
print("3. For gmail.py, ensure client_secret.json exists")
print("4. For weather server, make sure localhost:8000 is running")
return False
if __name__ == "__main__":
try:
success = asyncio.run(main())
sys.exit(0 if success else 1)
except KeyboardInterrupt:
print("\nTest interrupted")
sys.exit(1)
except Exception as e:
print(f"Test failed with error: {e}")
sys.exit(1)