Skip to content

Make MCP server's WebSocket bridge idempotent across windows - #2

Merged
poppod56 merged 1 commit into
mainfrom
prototype-export-and-inline-svg
Sep 18, 2026
Merged

poppod56 merged 1 commit into
mainfrom
prototype-export-and-inline-svg

Conversation

@poppod56

Copy link
Copy Markdown
Owner

Summary

  • Opening several editor windows each spawns its own 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_bridge now 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.
  • Kept the embedded copy in ui.html's Settings > MCP Connect panel byte-identical to .mcp-server/mcp_server.py per the file's own sync note.

Test plan

  • node --test tests/code-regression.test.js passes
  • Manual test on an isolated port: two processes race for the bind, the loser doesn't crash and picks up state within one retry interval
  • Manual test: kill the leader process mid-session, confirm the follower takes over the port and accepts a new plugin connection directly

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.
@poppod56
poppod56 merged commit f5d6196 into main Sep 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant