@@ -12,12 +12,11 @@ SERVER_URL="http://127.0.0.1:8000/mcp"
1212HEADERS=(-H " Content-Type: application/json" -H " Accept: application/json, text/event-stream" )
1313REQ_ID=0
1414
15- # Helper: call an MCP tool and return the parsed content JSON.
16- # Usage: mcp_call <tool_name> '<json_arguments>'
17- # Prints the parsed content to stdout. Exits 1 on failure.
15+ # Helper: call an MCP tool and extract the content JSON from the SSE response.
16+ # Prints parsed content to stdout; diagnostics to stderr. Returns 1 on failure.
1817mcp_call () {
1918 local tool=" $1 "
20- local args=" ${2 :- \{\} } "
19+ local args=" $2 "
2120 REQ_ID=$(( REQ_ID + 1 ))
2221 local raw
2322 raw=$( curl -s --max-time 30 " $SERVER_URL " -X POST " ${HEADERS[@]} " \
@@ -29,17 +28,37 @@ raw = sys.stdin.read()
2928for line in raw.split('\n'):
3029 if line.startswith('data: '):
3130 data = json.loads(line[6:])
32- content = data.get('result', {}).get('structuredContent', {})
31+ result = data.get('result', {})
32+ if result.get('isError'):
33+ msg = result.get('content', [{}])[0].get('text', 'unknown error')
34+ print(f'Tool error: {msg}', file=sys.stderr)
35+ print('{}')
36+ sys.exit(1)
37+ content = result.get('structuredContent', {})
3338 if not content:
34- text = data.get(' result', {}) .get('content', [{}])[0].get('text', '{}')
39+ text = result.get('content', [{}])[0].get('text', '{}')
3540 content = json.loads(text)
3641 print(json.dumps(content))
3742 sys.exit(0)
43+ print(f'No SSE data in response (first 500 chars): {raw[:500]}', file=sys.stderr)
3844print('{}')
3945sys.exit(1)
4046"
4147}
4248
49+ # Helper: call mcp_call and capture output. On failure, print the captured output and exit.
50+ mcp_call_or_die () {
51+ local label=" $1 "
52+ shift
53+ local result
54+ if ! result=$( mcp_call " $@ " ) ; then
55+ echo " FAIL at $label (tool: $1 )"
56+ echo " Captured output: $result "
57+ exit 1
58+ fi
59+ echo " $result "
60+ }
61+
4362# Initialize MCP session
4463echo " Initializing MCP session..."
4564SESSION_ID=$( curl -si " $SERVER_URL " -X POST " ${HEADERS[@]} " \
@@ -57,7 +76,7 @@ curl -s "$SERVER_URL" -X POST "${HEADERS[@]}" \
5776
5877# --- Step 1: Create a cube with the OLD plugin ---
5978echo " Creating test node with old plugin..."
60- CREATE_RESULT=$( mcp_call node_create ' {"type":"MeshInstance3D","name":"ReloadTestCube","parent_path":""}' )
79+ CREATE_RESULT=$( mcp_call_or_die " node_create " node_create ' {"type":"MeshInstance3D","name":"ReloadTestCube","parent_path":""}' )
6180echo " $CREATE_RESULT " | python3 -c "
6281import json, sys
6382content = json.loads(sys.stdin.read())
@@ -70,7 +89,7 @@ print(f'Created node: {path}')
7089
7190# --- Step 2: Reload the plugin ---
7291echo " Calling reload_plugin..."
73- RELOAD_RESULT=$( mcp_call reload_plugin)
92+ RELOAD_RESULT=$( mcp_call_or_die " reload_plugin" reload_plugin ' {} ' )
7493echo " $RELOAD_RESULT " | python3 -c "
7594import json, sys
7695content = json.loads(sys.stdin.read())
@@ -89,7 +108,7 @@ print(f'reload_plugin OK: {old_id[:12]}... -> {new_id[:12]}...')
89108
90109# --- Step 3: Verify log buffer is fresh (proves plugin fully rebuilt) ---
91110echo " Checking log buffer..."
92- LOGS_RESULT=$( mcp_call logs_read ' {"count":20}' )
111+ LOGS_RESULT=$( mcp_call_or_die " logs_read " logs_read ' {"count":20}' )
93112echo " $LOGS_RESULT " | python3 -c "
94113import json, sys
95114content = json.loads(sys.stdin.read())
@@ -108,7 +127,7 @@ print(f'Log buffer OK: {total} lines, starts with \"{lines[0]}\"')
108127
109128# --- Step 4: Find the cube with the NEW plugin (scene tree survived) ---
110129echo " Finding test node with new plugin..."
111- FIND_RESULT=$( mcp_call node_find ' {"name":"ReloadTestCube"}' )
130+ FIND_RESULT=$( mcp_call_or_die " node_find " node_find ' {"name":"ReloadTestCube"}' )
112131echo " $FIND_RESULT " | python3 -c "
113132import json, sys
114133content = json.loads(sys.stdin.read())
@@ -122,7 +141,7 @@ print(f'Found node: {node.get(\"name\", \"?\")} ({node.get(\"type\", \"?\")})')
122141
123142# --- Step 5: Verify editor_state works ---
124143echo " Verifying editor_state..."
125- HEALTH_RESULT=$( mcp_call editor_state)
144+ HEALTH_RESULT=$( mcp_call_or_die " editor_state" editor_state ' {} ' )
126145echo " $HEALTH_RESULT " | python3 -c "
127146import json, sys
128147content = json.loads(sys.stdin.read())
0 commit comments