-
Notifications
You must be signed in to change notification settings - Fork 532
fix: Port Discovery Protocol Mismatch #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- 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
WalkthroughThe port probe validation logic is updated to accept either the Unity MCP welcome message or the previous pong-based JSON response format. The docstring is updated to reflect this flexibility. No public API changes occur. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
MCPForUnity/UnityMcpServer~/src/port_discovery.py (2)
59-59: Consider clarifying that both formats are accepted.The docstring mentions "expects Unity bridge welcome message" but the implementation accepts both the Unity bridge welcome format and the legacy pong JSON format for backward compatibility. Consider updating to reflect this dual acceptance.
Example:
- Tries a short TCP connect, sends 'ping', expects Unity bridge welcome message. + Tries a short TCP connect, sends 'ping', expects Unity bridge welcome message or legacy pong JSON.
67-69: LGTM! Fix correctly addresses the protocol mismatch.The updated logic properly recognizes both the Unity MCP bridge welcome message format (
WELCOME UNITY-MCP) and the legacy pong JSON format, resolving the port discovery failure while maintaining backward compatibility. The substring matching approach is appropriate for this protocol handshake scenario.Optional: Consider extracting the protocol strings as class constants for better maintainability:
class PortDiscovery: """Handles port discovery from Unity Bridge registry""" REGISTRY_FILE = "unity-mcp-port.json" DEFAULT_PORT = 6400 CONNECT_TIMEOUT = 0.3 UNITY_WELCOME_MSG = b"WELCOME UNITY-MCP" LEGACY_PONG_MSG = b'"message":"pong"'Then use them in the check:
- if data and (b"WELCOME UNITY-MCP" in data or b'"message":"pong"' in data): + if data and (PortDiscovery.UNITY_WELCOME_MSG in data or PortDiscovery.LEGACY_PONG_MSG in data): return True
Problem: The MCP server's port discovery was failing to connect to Unity Editor because of a protocol mismatch. The Python server's
_try_probe_unity_mcp()method was sending a "ping" and expecting a JSON response with"message":"pong", but the Unity MCP bridge actually responds with a welcome message format:"WELCOME UNITY-MCP 1 FRAMING=1".This caused the port discovery to fall back to the default port (6400) instead of finding the actual Unity port (6402), resulting in connection failures and the error "Could not connect to Unity. Ensure the Unity Editor and MCP Bridge are running."
Solution: Updated the port discovery probe to recognize both the Unity bridge's actual welcome message format and maintain backward compatibility with the original JSON pong format. The fix allows the MCP server to successfully discover and connect to Unity Editor on the correct port.
Impact: MCP tools now properly connect to Unity Editor, enabling all MCP functionality including asset management, console reading, and GameObject operations.
Summary by CodeRabbit