From 30163173b052012e43c7cc0ed65b116c24c5a13d Mon Sep 17 00:00:00 2001 From: MarekWo Date: Fri, 9 Jan 2026 13:36:24 +0100 Subject: [PATCH] fix: Use correct bridge API format (args list, not command string) Bridge expects {"args": ["infos"], "timeout": 30} Returns {"success": true, "stdout": "..."} Co-Authored-By: Claude Opus 4.5 --- app/main.py | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/app/main.py b/app/main.py index 30bd184..f4e0e54 100644 --- a/app/main.py +++ b/app/main.py @@ -3,6 +3,7 @@ mc-webui - Flask application entry point """ import logging +import shlex import requests from flask import Flask, request as flask_request from flask_socketio import SocketIO, emit @@ -86,25 +87,38 @@ def handle_send_command(data): logger.info(f"Console command received: {command}") # Execute command via bridge HTTP API + # Parse command into args list (split by spaces, respecting quotes) + try: + args = shlex.split(command) + except ValueError: + args = command.split() + def execute_and_respond(): try: response = requests.post( config.MC_BRIDGE_URL, - json={'command': command}, - timeout=30 + json={'args': args, 'timeout': 30}, + timeout=35 ) if response.status_code == 200: result = response.json() - output = result.get('output', '') - # Handle list output (join with newlines) - if isinstance(output, list): - output = '\n'.join(output) - socketio.emit('command_response', { - 'success': True, - 'command': command, - 'output': output - }, room=sid, namespace='/console') + if result.get('success'): + output = result.get('stdout', '').strip() + if not output: + output = '(no output)' + socketio.emit('command_response', { + 'success': True, + 'command': command, + 'output': output + }, room=sid, namespace='/console') + else: + error = result.get('stderr', 'Unknown error') + socketio.emit('command_response', { + 'success': False, + 'command': command, + 'error': error + }, room=sid, namespace='/console') else: socketio.emit('command_response', { 'success': False,