unity-mcp 啟動逾時,兇手是兩個過期登記檔

unity-mcp 啟動逾時,兇手是兩個過期登記檔
情境示意圖

環境:macOS、Unity 編輯器接 Model Context Protocol(MCP)的 unity-mcp、搭配 Claude 桌面版。症狀:桌面版跳出「無法為 Cowork 和 Code 工作階段啟動 unity-mcp」,同時轉接程式的紀錄檔一路長大,這次量到 43 MB、28 萬行。Unity 編輯器明明已經關掉,才會碰到這種情況。

根因:登記檔還在,編輯器已經不在

~/.unity/mcp/connections/ 裡留著兩個連線登記檔,對應的是兩個早已關閉的 Unity 編輯器(09-10 開的)。編輯器關掉後,登記檔沒有被自動清掉。

轉接程式啟動時讀這個資料夾,照登記檔去連 pipe。pipe 的另一端早就沒人了,連線失敗,錯誤寫進紀錄檔,再重試、再寫,28 萬行就是這樣刷出來的。桌面版等轉接程式回應,等到逾時,就顯示上面那句警告。

警告訊息本身看不出任何線索,真正的證據在轉接程式的紀錄檔和那個資料夾裡。

修法:只移不刪

  1. 列出目前的登記檔。
  2. 用 pgrep -fl Unity 確認現在實際開著哪些編輯器。
  3. 對不上任何開著的編輯器的登記檔,移到備份資料夾,不要直接刪。
  4. 量紀錄檔大小,隔 15 秒再量一次。
# 1. 列出目前的 unity-mcp 連線登記檔
ls -la ~/.unity/mcp/connections/

# 2. 確認現在實際開著哪些 Unity 編輯器
pgrep -fl Unity

# 3. 對不上任何開著的編輯器的登記檔,移到備份資料夾(只移不刪,之後可放回)
mkdir -p ~/.unity/mcp/connections.stale
mv ~/.unity/mcp/connections/<過期的登記檔> ~/.unity/mcp/connections.stale/

# 4. 觀察紀錄檔有沒有停止增長(LOG 換成你機器上 unity-mcp 轉接程式的紀錄檔)
LOG="<unity-mcp 紀錄檔路徑>"
wc -c "$LOG"; sleep 15; wc -c "$LOG"

移到 connections.stale/ 而不是 rm,原因很單純:登記檔的內部格式沒有文件可查,判斷「過期」靠的只是和目前開著的編輯器對照。判斷錯了,把檔案放回去就能還原。

怎麼驗證

這次的驗證分兩步。第一,手動啟動轉接程式,確認立刻回應,紀錄裡沒有新的 pipe 錯誤;修正後的結果是立即回應、0 筆 pipe 錯誤。第二,上面第 4 步量兩次紀錄檔大小,桌面版的紀錄檔在 15 秒內沒有再增長。

紀錄檔裡搜 pipe 相關的錯誤字樣,也是確認根因的快速做法:同一類錯誤重複幾十萬次,基本上就指向同一個壞掉的來源。

適用範圍與限制

  • 情境:macOS 上 Unity 編輯器接 MCP、搭配 Claude 桌面版,編輯器關掉後登記檔沒有自動清除。
  • 登記檔內部格式沒有資料可參考,哪些已過期,要用「目前開著的編輯器」對照判斷。同時開著多個編輯器時,先確認每一個再動手。
  • 這次只驗到轉接程式恢復回應、紀錄檔停止增長。桌面版的警告是否消失,要等它下次啟動這個工具時才看得到,還沒確認。

下一個待辦很具體:下次開啟 Claude 桌面版,看「無法為 Cowork 和 Code 工作階段啟動 unity-mcp」那行字還在不在。

— 邱柏宇


unity-mcp Timeouts Traced to Two Stale Files

Environment: macOS, a Unity editor connected through unity-mcp (a Model Context Protocol server), used with the Claude desktop app. Symptom: the desktop app shows the warning that it cannot start unity-mcp for Cowork and Code sessions, while the relay’s log file keeps growing. This time it reached 43 MB and 280,000 lines, even though the Unity editors had already been closed.

Root cause: registration files outlived their editors

~/.unity/mcp/connections/ still held two connection registration files belonging to two Unity editors that had been closed (opened on 09-10). Closing an editor did not remove its file.

The relay reads that folder at startup and tries to connect to each registered pipe. Nothing is listening on the other end, so each attempt fails, writes an error to the log, retries, and writes again. That loop produced the 280,000 lines. The desktop app waits for the relay to answer, hits its timeout, and shows the warning.

The warning text itself carries no hint of any of this. The evidence is in the relay’s log and in that folder.

The fix: move, don’t delete

  1. List the current registration files.
  2. Run pgrep -fl Unity to see which editors are actually open.
  3. Move any file that matches no open editor into a backup folder instead of deleting it.
  4. Measure the log size, wait 15 seconds, measure again.
# 1. 列出目前的 unity-mcp 連線登記檔
ls -la ~/.unity/mcp/connections/

# 2. 確認現在實際開著哪些 Unity 編輯器
pgrep -fl Unity

# 3. 對不上任何開著的編輯器的登記檔,移到備份資料夾(只移不刪,之後可放回)
mkdir -p ~/.unity/mcp/connections.stale
mv ~/.unity/mcp/connections/<過期的登記檔> ~/.unity/mcp/connections.stale/

# 4. 觀察紀錄檔有沒有停止增長(LOG 換成你機器上 unity-mcp 轉接程式的紀錄檔)
LOG="<unity-mcp 紀錄檔路徑>"
wc -c "$LOG"; sleep 15; wc -c "$LOG"

Moving to connections.stale/ instead of running rm has a simple reason: the internal format of these files is undocumented, and “stale” is judged only by comparing against the editors currently open. If that judgment is wrong, the file can simply be moved back.

Verifying

Verification had two steps. First, start the relay by hand and confirm it responds immediately with no new pipe errors in its log; after the fix it responded at once with zero pipe errors. Second, the size check in step 4: the desktop app’s log stopped growing within 15 seconds.

Searching the log for the pipe error text is also a quick way to confirm the cause: the same error repeated hundreds of thousands of times points at one broken source.

Scope and limits

  • Applies to: a Unity editor connected via MCP on macOS with the Claude desktop app, where registration files were not cleaned up after the editor closed.
  • The registration file format is undocumented, so deciding which files are stale means comparing against the editors that are open right now. With several editors open, check each one before moving anything.
  • Only two things were confirmed: the relay responds again and the log stopped growing. Whether the desktop app’s warning is gone will only show the next time the app launches the tool, and that has not been checked yet.

The remaining check is concrete: open the Claude desktop app again and see whether the unity-mcp startup warning is still there.

— 邱柏宇

延伸閱讀

分類: 技術筆記,標籤: 、、、,作者: Jett。這篇內容的永久連結。

關於「Jett」

邱柏宇,新北人,寫程式的工程師。踩到的坑習慣整理成筆記,從錯誤訊息一路追到根因才收工;在 JustBlog 寫開發除錯、工具與工作流程的實戰紀錄,下班喜歡哼歌、做點手作。 Jett Chiu is a New Taipei–based software engineer who writes up the bugs he runs into, tracing each error message down to its root cause.