Repository navigation
Expand file tree
/
Copy pathtest-docker-flow-mcp.sh
More file actions
executable file
·162 lines (139 loc) · 4.98 KB
/
Copy pathtest-docker-flow-mcp.sh
File metadata and controls
executable file
·162 lines (139 loc) · 4.98 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
162
#!/bin/bash
# Test the Docker config flow using the Playwright MCP server
# This script uses the mcp-proxy to send MCP commands and verify the flow
set -e
echo "================================================"
echo "Docker Config Flow Test (ticket-040)"
echo "Using Playwright MCP server"
echo "================================================"
echo ""
# Check prerequisites
if ! docker ps | grep -q playwright-novnc; then
echo "❌ Error: playwright-novnc container is not running"
echo " Start it with: docker-compose -f docker/docker-compose.mcp-proxy.yml up -d"
exit 1
fi
if ! curl -s http://localhost:9888/ > /dev/null 2>&1; then
echo "❌ Error: Editor is not running at http://localhost:9888"
echo " Start it with: docker compose up -d"
exit 1
fi
echo "✅ Prerequisites OK"
echo " - playwright-novnc container running"
echo " - Editor accessible at http://localhost:9888"
echo ""
# Create a temporary file for the MCP session
INPUT_PIPE=$(mktemp -u)
OUTPUT_PIPE=$(mktemp -u)
mkfifo "$INPUT_PIPE" "$OUTPUT_PIPE"
# Cleanup on exit
cleanup() {
kill $PROXY_PID 2>/dev/null
rm -f "$INPUT_PIPE" "$OUTPUT_PIPE"
}
trap cleanup EXIT
# Start the mcp-proxy
echo "🚀 Starting MCP proxy session..."
COMPOSE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/docker"
docker-compose -f "$COMPOSE_DIR/docker-compose.mcp-proxy.yml" run --rm -i mcp-proxy \
< "$INPUT_PIPE" > "$OUTPUT_PIPE" 2>/dev/null &
PROXY_PID=$!
# Wait for proxy to establish connection
sleep 2
# Function to send a JSON-RPC request
send_request() {
local method="$1"
local params="$2"
local id="$3"
printf '{"jsonrpc":"2.0","id":%s,"method":"%s","params":%s}\n' "$id" "$method" "$params" > "$INPUT_PIPE"
echo "📤 $method (id=$id)"
}
# Function to read a response
read_response() {
local timeout="$1"
local start=$(date +%s)
while [ $(($(date +%s) - start)) -lt $timeout ]; do
if read -t 0.5 line < "$OUTPUT_PIPE"; then
if [[ "$line" =~ ^data:\ (.+)$ ]]; then
echo "${BASH_REMATCH[1]}" | python3 -c "
import sys, json
try:
data = json.load(sys.stdin)
print(json.dumps(data, indent=2))
except:
print('Invalid JSON')
sys.exit(1)
" 2>/dev/null && return 0
fi
fi
done
return 1
}
# Wait for proxy to be ready
sleep 1
echo ""
echo "1️⃣ Initializing MCP session..."
send_request "initialize" '{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"docker-config-test","version":"1.0"}}' 1
if read_response 5; then
echo " ✅ Initialized"
else
echo " ⚠️ No response (continuing anyway)..."
fi
sleep 1
echo ""
echo "2️⃣ Navigating to editor (http://localhost:9888/)..."
send_request "tools/call" '{"name":"browser_navigate","arguments":{"url":"http://localhost:9888/"}}' 2
read_response 10 || echo " ⚠️ No response"
echo " Waiting for page to load..."
sleep 4
echo ""
echo "3️⃣ Taking snapshot to find Docker card..."
send_request "tools/call" '{"name":"browser_snapshot","arguments":{"interactive":true}}' 3
if read_response 5; then
echo " ✅ Snapshot captured"
else
echo " ⚠️ Snapshot failed"
fi
echo ""
echo "4️⃣ Looking for Docker card in page..."
# For now, we'll try to click by selector that should exist
send_request "tools/call" '{"name":"browser_click","arguments":{"selector":"[data-card=\"docker\"]"}}' 4
if read_response 5; then
echo " ✅ Clicked Docker card"
else
echo " ⚠️ Click might have failed (trying text fallback)"
send_request "tools/call" '{"name":"browser_click","arguments":{"selector":"text=Docker"}}' 5
read_response 5 || echo " ⚠️ Text click also failed"
fi
sleep 2
echo ""
echo "5️⃣ Verifying config modal appears..."
send_request "tools/call" '{"name":"browser_snapshot","arguments":{"interactive":true}}' 6
read_response 5 > /dev/null
echo " ✅ Check the browser display at http://localhost:6080/vnc.html"
echo " or look at the snapshot output above for #panel-docker-config"
echo ""
echo "6️⃣ Simulating config form fill (tmp dir, port 18791)..."
echo " NOTE: In actual usage, you would:"
echo " - Fill #config-data-dir with /tmp/openclaw-data"
echo " - Fill #config-gateway-port with 18791"
echo " - Click 'Next →'"
echo " - Then 'Confirm & Start' on Step 2"
echo " This would save to docker/.env.openclaw and start provisioning"
echo ""
echo "================================================"
echo "✅ MCP test script completed"
echo ""
echo "To manually complete the test:"
echo "1. Open http://localhost:6080/vnc.html in a browser"
echo "2. Watch the editor UI"
echo "3. Click Docker card manually if needed"
echo "4. Verify Step 1 appears with 4 fields"
echo "5. Enter /tmp/openclaw-data and port 18791"
echo "6. Click Next, then Confirm & Start"
echo "7. Verify Step 3 (provisioning) starts"
echo "8. Check docker/.env.openclaw was created"
echo "9. Check gateway container: docker ps | grep openclaw"
echo "================================================"
# Cleanup happens via trap
exit 0