Skip to content

Two Editors on the same machine can't both hold an MCP connection (shared EditorPrefs PID key) #830

Description

@Ramlock

Summary

Running two Unity projects with the plugin at the same time (each on its own port) results in mutual exclusion: connecting/recompiling one Editor drops the other's MCP connection. Reconnect that one and the first drops. Only one project stays connected at a time, even though their ports differ.

Environment

  • Plugin: com.ivanmurzak.unity.mcp 0.81.0 (also present on main)
  • OS: Windows 11; two separate Unity projects, ports 26645 and 26646
  • connectionMode: Custom, keepServerRunning: true

Repro

  1. Open project A (port 26645) -> its server starts, MCP connects.
  2. Open project B (port 26646) -> its server starts, MCP connects.
  3. Recompile / enter Play / reconnect in project A -> project B's MCP connection drops (connection-refused on B's port; B's gamedev-mcp-server is gone).
  4. Symmetric: touching B second kills A.

Root cause

McpServerManager stores the running server PID under a fixed EditorPrefs key, "McpServerManager_ProcessId", that is not qualified by port/project. EditorPrefs are machine-global (shared across all projects of the same Editor version), so both Editors read/write one slot. After B overwrites the slot with B's PID, A's CheckExistingProcess() (on domain reload) reads B's PID, adopts B's server as its own _serverProcess, and StopServer() later terminates it. The per-project binary folder (Library/mcp-server) and KillOrphanedServerProcesses() are already port-scoped -- this PID key is the last piece of shared state.

Fix

Qualify the key by port. PR opened against this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions