Make MCP server's WebSocket bridge idempotent across windows - #2
Merged
Merged
Conversation
Opening multiple editor windows each spawns its own mcp_server.py, and every instance raced to bind port 8788 for the Figma plugin, crashing all but the first. Now a losing instance polls a shared-state file the port holder writes on each message instead of crashing, and keeps retrying the bind so it takes over automatically if that process exits.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mcp_server.py, and every instance tried to bind port 8788 for the Figma plugin — only the first succeeded, the rest crashed instead of serving their window's MCP tools._run_websocket_bridgenow loops: on a bind failure it doesn't crash, it reads a shared-state file (written by whichever instance currently holds the port on every plugin message) and retries the bind every 5s, so it self-promotes to leader automatically if that process exits.ui.html's Settings > MCP Connect panel byte-identical to.mcp-server/mcp_server.pyper the file's own sync note.Test plan
node --test tests/code-regression.test.jspasses