magicciv/scripts/render-driver-server.sh
Natalie 70537bc0d1 feat(@projects/@magic-civilization): claude-player-mcp rendered tools — magic_civ_screenshot / open_screen (p2-86 phase 2)
- render_client.ts: TCP client that spawns the rendered game via
  render-driver-server.sh, then sends screenshot / open_screen / ping correlated
  by id (distinct from the headless stdin HarnessClient).
- scripts/render-driver-server.sh: boots the REAL game (MC_AUTO_START +
  MC_MCP_RENDER, gl_compatibility, not --headless) so the driver captures real
  frames; client connects on MC_MCP_PORT.
- index.ts: magic_civ_screenshot + magic_civ_open_screen tools, render-client
  holder + cleanup.

Verified end-to-end through the BUILT TypeScript (no Claude restart needed):
RenderClient -> game -> TCP ping {ok}, screenshot -> a real 3420x1923 PNG of the
live world map. dist/ is gitignored (built locally per .mcp.json); the tools
surface in a Claude session after the next restart.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-18 21:09:10 -05:00

54 lines
2.1 KiB
Bash
Executable file

#!/usr/bin/env bash
# Rendered-game launch for the MCP render driver (p2-86).
#
# Unlike player-api-server.sh (a --headless state bench), this boots the REAL
# game WITH rendering so the driver's `screenshot` command captures real frames.
# MC_AUTO_START=1 skips the menu into an interactive seeded game;
# MC_MCP_RENDER=1 activates mcp_render_driver.gd, which listens on MC_MCP_PORT
# (default 8787). The client (RenderClient) connects over TCP — stdout is not
# used for the protocol (Godot block-buffers windowed stdout).
#
# Env:
# MC_MCP_PORT — driver TCP port (default 8787)
# MC_AUTOSTART_SEED — game seed (default 42)
# MC_AUTOSTART_PLAYERS / MC_AUTOSTART_MAP_SIZE — optional overrides
#
# Linux note: rendered mode needs a display server (weston/xvfb on a GPU node,
# per MAGIC_CIV_CLOUD_HANDOFF.md). macOS renders directly via the windowing
# system. Headless state play is unchanged (player-api-server.sh).
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
: "${MC_MCP_PORT:=8787}"
: "${MC_AUTOSTART_SEED:=42}"
export MC_AUTO_START=1 MC_MCP_RENDER=1 MC_MCP_PORT MC_AUTOSTART_SEED \
MC_AUTOSTART_PLAYERS MC_AUTOSTART_MAP_SIZE
case "$(uname -s)" in
Darwin)
GODOT_BIN="${GODOT_BIN:-godot}"
if ! command -v "$GODOT_BIN" >/dev/null 2>&1; then
echo "ERROR: no godot binary on PATH (set GODOT_BIN or 'brew install godot')." >&2
exit 1
fi
exec "$GODOT_BIN" \
--path "$PROJECT_DIR/src/game" \
--rendering-method gl_compatibility
;;
*)
# Linux: flatpak Godot. Rendered mode requires a display (weston/xvfb);
# the caller is responsible for providing WAYLAND_DISPLAY / DISPLAY.
exec flatpak run --user \
--env=MC_AUTO_START=1 \
--env=MC_MCP_RENDER=1 \
--env=MC_MCP_PORT="$MC_MCP_PORT" \
--env=MC_AUTOSTART_SEED="$MC_AUTOSTART_SEED" \
org.godotengine.Godot \
--path "$PROJECT_DIR/src/game" \
--rendering-method gl_compatibility
;;
esac