Skip to content

Commit cd0e628

Browse files
committed
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
1 parent 26eafbf commit cd0e628

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

MCPForUnity/UnityMcpServer~/src/port_discovery.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ def list_candidate_files() -> List[Path]:
5656
@staticmethod
5757
def _try_probe_unity_mcp(port: int) -> bool:
5858
"""Quickly check if a MCP for Unity listener is on this port.
59-
Tries a short TCP connect, sends 'ping', expects a JSON 'pong'.
59+
Tries a short TCP connect, sends 'ping', expects Unity bridge welcome message.
6060
"""
6161
try:
6262
with socket.create_connection(("127.0.0.1", port), PortDiscovery.CONNECT_TIMEOUT) as s:
6363
s.settimeout(PortDiscovery.CONNECT_TIMEOUT)
6464
try:
6565
s.sendall(b"ping")
6666
data = s.recv(512)
67-
# Minimal validation: look for a success pong response
68-
if data and b'"message":"pong"' in data:
67+
# Check for Unity bridge welcome message format
68+
if data and (b"WELCOME UNITY-MCP" in data or b'"message":"pong"' in data):
6969
return True
7070
except Exception:
7171
return False

0 commit comments

Comments
 (0)