Skip to content

Commit 941a308

Browse files
committed
this is it!
1 parent a420504 commit 941a308

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

.github/workflows/claude-nl-suite.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ jobs:
251251
-e HOME=/root \
252252
-e UNITY_MCP_ALLOW_BATCH=1 \
253253
-e UNITY_MCP_STATUS_DIR="${{ github.workspace }}/.unity-mcp" \
254-
-e UNITY_MCP_BIND_HOST=127.0.0.1 \
254+
-e UNITY_MCP_BIND_HOST=0.0.0.0 \
255255
-v "${{ github.workspace }}:${{ github.workspace }}" -w "${{ github.workspace }}" \
256256
-v "$RUNNER_TEMP/unity-config:/root/.config/unity3d" \
257257
-v "$RUNNER_TEMP/unity-local:/root/.local/share/unity3d" \
@@ -435,6 +435,16 @@ jobs:
435435
fi
436436
437437
# ---------- MCP client config ----------
438+
# Get host IP for network connectivity (Claude Code might run in isolated network)
439+
- name: Get host IP
440+
id: host_ip
441+
run: |
442+
set -eux
443+
# Get the default route's source IP (works on GitHub Actions Linux)
444+
HOST_IP=$(ip route get 1.1.1.1 2>/dev/null | grep -oP 'src \K\S+' || echo "127.0.0.1")
445+
echo "host_ip=$HOST_IP" >> "$GITHUB_OUTPUT"
446+
echo "Host IP: $HOST_IP"
447+
438448
- name: Write MCP config (.claude/mcp.json)
439449
run: |
440450
set -eux
@@ -446,6 +456,9 @@ jobs:
446456
447457
workspace = os.environ["GITHUB_WORKSPACE"]
448458
default_inst = os.environ.get("UNITY_MCP_DEFAULT_INSTANCE", "").strip()
459+
# Use host IP if available, fallback to 127.0.0.1
460+
# This handles cases where Claude Code spawns MCP server in isolated network namespace
461+
host_ip = os.environ.get("HOST_IP", "127.0.0.1")
449462
450463
cfg = {
451464
"mcpServers": {
@@ -468,7 +481,7 @@ jobs:
468481
"MCP_LOG_LEVEL": "debug",
469482
"UNITY_PROJECT_ROOT": f"{workspace}/TestProjects/UnityMCPTests",
470483
"UNITY_MCP_STATUS_DIR": f"{workspace}/.unity-mcp",
471-
"UNITY_MCP_HOST": "127.0.0.1",
484+
"UNITY_MCP_HOST": host_ip,
472485
},
473486
}
474487
}
@@ -482,8 +495,10 @@ jobs:
482495
483496
path = Path(".claude/mcp.json")
484497
path.write_text(json.dumps(cfg, indent=2) + "\n")
485-
print(f"Wrote {path} (UNITY_MCP_DEFAULT_INSTANCE={default_inst or 'unset'})")
498+
print(f"Wrote {path} (UNITY_MCP_HOST={host_ip}, UNITY_MCP_DEFAULT_INSTANCE={default_inst or 'unset'})")
486499
PY
500+
env:
501+
HOST_IP: ${{ steps.host_ip.outputs.host_ip }}
487502

488503
- name: Debug MCP config
489504
run: |

Server/src/main.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ def main():
376376
try:
377377
from transport.legacy.port_discovery import PortDiscovery
378378
import glob
379+
unity_host = os.environ.get("UNITY_MCP_HOST", "127.0.0.1")
380+
startup_debug_lines.append(f"UNITY_MCP_HOST={unity_host}")
379381
status_dir = PortDiscovery.get_registry_dir()
380382
startup_debug_lines.append(f"status_dir={status_dir}")
381383
startup_debug_lines.append(f"status_dir_exists={status_dir.exists()}")
@@ -389,9 +391,9 @@ def main():
389391
data = json.load(f)
390392
port = data.get('unity_port')
391393
startup_debug_lines.append(f"file={sf}, port={port}")
392-
# Try probe
393-
probe_result = PortDiscovery._try_probe_unity_mcp(port) if port else False
394-
startup_debug_lines.append(f"probe_port_{port}={probe_result}")
394+
# Try probe with the configured host
395+
probe_result = PortDiscovery._try_probe_unity_mcp(port, unity_host) if port else False
396+
startup_debug_lines.append(f"probe_{unity_host}:{port}={probe_result}")
395397
except Exception as e:
396398
startup_debug_lines.append(f"error_reading_{sf}={e}")
397399
instances = PortDiscovery.discover_all_unity_instances()
@@ -412,6 +414,7 @@ def main():
412414
f.write(f"Timestamp: {time.strftime('%Y-%m-%d %H:%M:%S')}\n")
413415
f.write(f"args.status_dir: {args.status_dir}\n")
414416
f.write(f"UNITY_MCP_STATUS_DIR env: {os.environ.get('UNITY_MCP_STATUS_DIR', 'NOT SET')}\n")
417+
f.write(f"UNITY_MCP_HOST env: {os.environ.get('UNITY_MCP_HOST', 'NOT SET')}\n")
415418
f.write("\n".join(startup_debug_lines))
416419
f.write("\n")
417420
logger.info(f"Wrote startup debug to {debug_file_path}")

Server/src/transport/legacy/port_discovery.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,20 @@ def list_candidate_files() -> list[Path]:
6161
return hashed
6262

6363
@staticmethod
64-
def _try_probe_unity_mcp(port: int) -> bool:
64+
def _try_probe_unity_mcp(port: int, host: str | None = None) -> bool:
6565
"""Quickly check if a MCP for Unity listener is on this port.
6666
Uses Unity's framed protocol: receives handshake, sends framed ping, expects framed pong.
67+
68+
Args:
69+
port: Port number to probe
70+
host: Host to connect to (defaults to UNITY_MCP_HOST env var or 127.0.0.1)
6771
"""
72+
if host is None:
73+
host = os.environ.get("UNITY_MCP_HOST", "127.0.0.1")
6874
try:
6975
# Increased timeout for CI stability
7076
timeout = 2.0
71-
with socket.create_connection(("127.0.0.1", port), timeout) as s:
77+
with socket.create_connection((host, port), timeout) as s:
7278
s.settimeout(timeout)
7379
try:
7480
# 1. Receive handshake from Unity

0 commit comments

Comments
 (0)