-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_test.py
More file actions
78 lines (67 loc) · 2.02 KB
/
debug_test.py
File metadata and controls
78 lines (67 loc) · 2.02 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
#!/usr/bin/env python3
import asyncio
import os
from dotenv import load_dotenv
from mcp_use import MCPClient, MCPAgent
from langchain_anthropic import ChatAnthropic
load_dotenv()
async def debug_test():
print("🔧 Starting debug test...")
config = {
"mcpServers": {
"wordpress_server": {
"url": os.getenv("MCP_BASE_URL"),
"headers": {
"Authorization": f"Bearer {os.getenv('JWT_TOKEN')}",
"Content-Type": "application/json"
}
}
}
}
# Create MCP client
client = MCPClient.from_dict(config)
# Create sessions
try:
sessions = await client.create_all_sessions()
print(f"✅ Created sessions: {list(sessions.keys())}")
except Exception as e:
print(f"❌ Error creating sessions: {e}")
return
# Create Claude LLM
llm = ChatAnthropic(
model="claude-3-5-haiku-20241022",
api_key=os.getenv("ANTHROPIC_API_KEY"),
temperature=0.1,
max_tokens=1000,
max_retries=2
)
# Create agent
agent = MCPAgent(
llm=llm,
client=client,
max_steps=5,
memory_enabled=True,
auto_initialize=False
)
# Initialize agent
await agent.initialize()
print("✅ Agent initialized")
# Test the agent
print("\n🧪 Testing agent.run()...")
try:
result = await agent.run("how are you?", manage_connector=False, max_steps=5)
print(f"📤 Result type: {type(result)}")
print(f"📤 Result length: {len(result) if result else 0}")
print(f"📤 Result repr: {repr(result)}")
print(f"📤 Result: '{result}'")
except Exception as e:
print(f"❌ Error in agent.run(): {e}")
import traceback
traceback.print_exc()
# Close connections
try:
await client.close_all_sessions()
except Exception as e:
print(f"⚠️ Error closing: {e}")
if __name__ == "__main__":
asyncio.run(debug_test())