From cd0e628ca6b04569a56e9a76696113b18763714c Mon Sep 17 00:00:00 2001 From: David Sarno Date: Thu, 23 Oct 2025 12:53:49 -0700 Subject: [PATCH] Fix port discovery protocol mismatch - Update _try_probe_unity_mcp to recognize Unity bridge welcome message - Unity bridge sends 'WELCOME UNITY-MCP' instead of JSON pong response - Maintains backward compatibility with JSON pong format - Fixes MCP server connection to Unity Editor --- MCPForUnity/UnityMcpServer~/src/port_discovery.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MCPForUnity/UnityMcpServer~/src/port_discovery.py b/MCPForUnity/UnityMcpServer~/src/port_discovery.py index b936f967..c759e745 100644 --- a/MCPForUnity/UnityMcpServer~/src/port_discovery.py +++ b/MCPForUnity/UnityMcpServer~/src/port_discovery.py @@ -56,7 +56,7 @@ def list_candidate_files() -> List[Path]: @staticmethod def _try_probe_unity_mcp(port: int) -> bool: """Quickly check if a MCP for Unity listener is on this port. - Tries a short TCP connect, sends 'ping', expects a JSON 'pong'. + Tries a short TCP connect, sends 'ping', expects Unity bridge welcome message. """ try: with socket.create_connection(("127.0.0.1", port), PortDiscovery.CONNECT_TIMEOUT) as s: @@ -64,8 +64,8 @@ def _try_probe_unity_mcp(port: int) -> bool: try: s.sendall(b"ping") data = s.recv(512) - # Minimal validation: look for a success pong response - if data and b'"message":"pong"' in data: + # Check for Unity bridge welcome message format + if data and (b"WELCOME UNITY-MCP" in data or b'"message":"pong"' in data): return True except Exception: return False