-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_mcp_agent.py
More file actions
executable file
·89 lines (78 loc) · 2.22 KB
/
test_mcp_agent.py
File metadata and controls
executable file
·89 lines (78 loc) · 2.22 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
#!/usr/bin/env python3
"""Test MCP agent functionality inside backend container"""
import subprocess
import json
import time
print("=" * 60)
print("MCP Agent Standalone Test (Inside Container)")
print("=" * 60)
# Test data
tests = [
{
"name": "List Tools",
"request": {
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {"name": "test", "version": "1.0"}
}
}
}
]
print("\n1. Testing MCP agent can be invoked...")
result = subprocess.run(
['docker', 'exec', 'jerai-backend', 'python', '/app/mcp_agent/agent.py', '--help'],
capture_output=True,
text=True,
timeout=5
)
if result.returncode == 0 or 'agent.py' in result.stderr:
print(" ✅ MCP agent script is accessible")
else:
print(f" ❌ Failed to access agent: {result.stderr}")
exit(1)
print("\n2. Testing MCP agent initialization...")
# Create test script inside container
test_script = """
import json
import sys
sys.path.insert(0, '/app/mcp_agent')
# Send initialize request
init_req = {
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {"name": "test", "version": "1.0"}
}
}
print(json.dumps(init_req))
"""
result = subprocess.run(
['docker', 'exec', '-i', 'jerai-backend', 'python', '-c', test_script],
capture_output=True,
text=True,
timeout=5
)
if result.returncode == 0:
print(" ✅ MCP agent can generate JSON-RPC requests")
print(f" Output: {result.stdout[:100]}...")
else:
print(f" ❌ Error: {result.stderr}")
print("\n3. Testing file access from MCP agent...")
result = subprocess.run(
['docker', 'exec', 'jerai-backend', 'python', '-c',
'import os; print("✅" if os.path.exists("/workspace/ecommerce/cart.py") else "❌", "Cart file exists:", os.path.exists("/workspace/ecommerce/cart.py"))'],
capture_output=True,
text=True,
timeout=5
)
print(f" {result.stdout.strip()}")
print("\n" + "=" * 60)
print("MCP Agent Standalone Tests Complete!")
print("=" * 60)