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

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

桌面版跳出「無法為 Cowork 和 Code 工作階段啟動 unity-mcp」,轉接程式的紀錄檔同時長到 43,025,895 位元組(約 43 MB)、283,222 行。Unity 編輯器早就關了。警告只講結果不講原因,查案得靠紀錄檔自己開口。

技術環境

macOS(mbp)。Claude 桌面版透過設定檔啟動 Unity 的 MCP 轉接程式 relay_mac_arm64 --mcp,以 stdio 溝通。轉接程式讀 ~/.unity/mcp/connections/ 底下的 bridge-*.json,每份登記檔記一個 Unity 編輯器的 pipe 路徑(connection_type: named_pipe)、專案路徑與 editor_pid。桌面版對轉接程式送 initialize、tools/list 等請求,單次請求逾時為 120000 ms(桌面版 main.log 記載)。以下數字全部來自這台機器的原始檔案與紀錄,其他機器與版本沒測。

現象:警告一行,紀錄檔 28 萬行

現行紀錄檔 ~/Library/Logs/Claude/mcp-server-unity-mcp.log 共 283,222 行,其中 282,926 行是同一句 Named pipe connection error: ENOENT … /tmp/unity-mcp-2e1dff22-97341,其餘 296 行是啟動與請求訊息。同一份紀錄有 12 筆 Couldn't start for Cowork and Code sessions,桌面版 main.log 另有 17 筆 Failed to connect to unity-mcp: Request timed out(timeout: 120000),時間落在 12-04 02:25 到 12-05 05:44(台灣時間)。

28 萬行只是現行這一份。更早的四份輪替紀錄(最早起自 11-12)同樣以這個 pipe 的 ENOENT 為主,合計約 372 萬行。

錯誤傳染鏈(時序)

Claude 桌面版            relay (--mcp)                connections/ 與 /tmp
    |                         |                              |
    |── initialize ──────────>|                              |
    |<── 回應 ─────────────────|  ← 正常(乾淨目錄 0.64 s)   |
    |── tools/list ──────────>|── 登記檔指向 pipe ──────────>|  ← bridge-…-97341.json
    |                         |<── ENOENT ───────────────────|  ← /tmp/unity-mcp-2e1dff22-97341 不存在
    |                         |── 重試、寫 log、再重試 ───────>|  ← 282,926 行
    |   …等 120000 ms…        |                              |
    |  Request timed out      |                              |
桌面版:「無法為 Cowork 和 Code 工作階段啟動 unity-mcp」

關鍵節點:initialize 照常回應,只有 tools/list 沒有下文;握手成功,反而讓問題看起來像桌面版的事。圖為示意:實測只看到「tools/list 無回應」與「ENOENT 重複寫入」同時出現,ENOENT 是否由 tools/list 觸發沒有查。

容易誤判的原因

警告字面是「啟動失敗」,容易先懷疑桌面版設定、Unity 版本或 MCP 本身。轉接程式其實啟動得起來,initialize 在 0.64 秒內回應。Unity 編輯器沒開時 unity-mcp 沒有工具可用,這屬預期結果:12-07 在乾淨目錄重跑,tools/list 在 1.16 秒回 {"tools":[]}。

分界點:登記檔指向已不存在的編輯器

connections/ 裡有兩份登記檔,created_date 都在 09-10:bridge-2e1dff22-90545.json(檔案時間 19:00:31、editor_pid 90545)與 bridge-2e1dff22-97341.json(20:34:42、97341),專案路徑都是 /Users/justfly/AI TEST。pid 90545、97341 現在都不在,/tmp 下也沒有對應的 pipe 檔。

12-06 19:56:35 把兩份登記檔移出 connections/。同一秒,紀錄檔的最後寫入時間停在 19:56:35,之後再沒有新行。桌面版啟動的那個轉接程式行程(pid 79647,12-05 04:40:02 起)當時仍在跑,寫 log 的就是它。

12-07 03:1x 用同一批檔案重跑,當成對照:

  • 目錄乾淨:initialize 0.64 秒、tools/list 1.16 秒回應,15 秒內 0 筆 ENOENT。
  • 兩份都放回:initialize 0.64 秒回應,tools/list 20 秒內沒有回應,96 筆 ENOENT。
  • 只放 90545:tools/list 12 秒內沒有回應,62 筆 ENOENT。
  • 只放 97341:tools/list 12 秒內沒有回應,58 筆 ENOENT。
  • 再移走:桌面版那個轉接程式立刻停寫,紀錄檔大小 20 秒內維持不變。

兩份各自都足以卡住 tools/list;原始紀錄卻只出現 97341,90545 在 12-07 重跑前是 0 筆,為什麼只挑到其中一個沒有再追。12-06 日報另記載:手動啟動轉接程式立即回應、0 筆 pipe 錯誤,移檔後 15 秒內紀錄檔未增長;當時的量測輸出沒有留存,改由上面的重跑與最後寫入時間佐證。

Code 對照:修法前後

修法前:兩份登記檔都在,對應的編輯器都不在。

# 搬檔前的狀態(檔名與時間取自 connections.stale/ 內的原檔)
ls -laT ~/.unity/mcp/connections/
bridge-2e1dff22-90545.json   Sep 10 19:00:31 2026   # ← editor_pid 90545,行程不存在
bridge-2e1dff22-97341.json   Sep 10 20:34:42 2026   # ← editor_pid 97341,紀錄檔 282,926 行都指向它的 pipe

$ cat bridge-2e1dff22-97341.json
{ "connection_type": "named_pipe",
  "connection_path": "/tmp/unity-mcp-2e1dff22-97341",   # ← 這個 pipe 不存在
  "created_date": "2026-09-10T12:34:42.3811460Z",
  "project_path": "/Users/justfly/AI TEST",
  "protocol_version": "2.0",
  "editor_pid": 97341 }

修法後:先確認行程與 pipe 都不在,再整檔移走,不刪。

ps -p 90545 -o pid=,command=        # 沒有輸出=行程不在
ps -p 97341 -o pid=,command=
ls /tmp/unity-mcp-2e1dff22-*        # No such file or directory

mkdir -p ~/.unity/mcp/connections.stale
mv ~/.unity/mcp/connections/bridge-2e1dff22-90545.json \
   ~/.unity/mcp/connections/bridge-2e1dff22-97341.json \
   ~/.unity/mcp/connections.stale/

LOG=~/Library/Logs/Claude/mcp-server-unity-mcp.log
wc -c "$LOG"; sleep 15; wc -c "$LOG"   # 大小不變=停止增長

$ ls ~/.unity/mcp/connections/          # 空
$ ls ~/.unity/mcp/connections.stale/
bridge-2e1dff22-90545.json  bridge-2e1dff22-97341.json

用 mv 而不是 rm:登記檔欄位看得到,但格式沒有官方文件,「過期」靠行程與 pipe 不存在判斷。判斷錯了,放回去就能還原;12-07 的重跑就是這樣放回再移走的。

該被隔離的側效應:搬檔時沒動到的東西

12-07 實機盤點,搬檔只影響兩份登記檔,下列項目維持原狀:

  • 登記檔本體:移到 connections.stale/,內容與檔案時間不變。
  • 現行紀錄檔:沒有截斷或刪除,43 MB 的證據原樣保留(重跑對照多寫了 102 行 ENOENT,現為 43,041,399 位元組、283,324 行)。
  • 輪替紀錄檔:mcp-server-unity-mcp1 到 4.log 合計約 565 MB,最後寫入 11-19 到 12-05,沒動。
  • 桌面版的轉接程式行程:pid 79647 沒被重啟,12-05 04:40:02 起一直是同一個。
  • 其他轉接程式行程:命令列工作階段啟動的幾個(例如 pid 19953,11-24 起)仍在跑。
  • 開著的 Unity 編輯器:pid 53024 正在跑,connections/ 裡沒有它的登記檔,搬檔與它無關。
  • 桌面版設定:claude_desktop_config.json 的 unity-mcp 條目,最後修改 12-06 19:51,早於搬檔。
  • 專案資料夾:登記檔記的 /Users/justfly/AI TEST 還在,沒碰。

判斷標準:只動「指向已不存在行程」的登記,其餘全部原樣保留。

結論:驗證到哪、沒驗證什麼

已驗證三件事。一,兩份登記檔都指向不存在的編輯器(pid 與 pipe 皆不在)。二,這兩份檔案在場時,轉接程式 tools/list 無回應並持續寫 ENOENT,移走後 1.16 秒回應、不再寫錯。三,桌面版啟動的那個轉接程式,在搬檔同一秒停止寫紀錄,放回就寫、移走就停。

桌面版端的警告是否消失,沒有驗證。桌面版對 unity-mcp 的最後一次連線嘗試是 12-05 05:44,搬檔之後紀錄檔與 main.log 都沒有新的 unity-mcp 啟動紀錄,那個轉接程式行程也沒重啟過。因此本文結論止於轉接程式與紀錄檔,不含桌面版畫面。

— 邱柏宇

延伸閱讀

本文數字與時間為本機第一手紀錄(登記檔、轉接程式紀錄檔、桌面版 main.log、12-07 重跑輸出),不引用第三方文章。官方文件只佐證通用概念:


unity-mcp Timeouts Traced to Two Stale Files

The Claude desktop app warned that it could not start unity-mcp for Cowork and Code sessions, while the relay’s log grew to 43,025,895 bytes (about 43 MB) and 283,222 lines. The Unity editors had been closed long before. The warning states the result and none of the cause, so the log had to supply it.

Technical environment

macOS (the mbp). The Claude desktop app launches Unity’s MCP relay, relay_mac_arm64 --mcp, over stdio, from its config file. The relay reads bridge-*.json under ~/.unity/mcp/connections/; each file records one Unity editor’s pipe path (connection_type: named_pipe), project path and editor_pid. The app sends the relay initialize and tools/list requests, with a 120000 ms per-request timeout (recorded in the app’s main.log). All numbers below come from raw files and logs on this one machine; other machines and versions were not tested.

Symptom: one warning line, 280,000 log lines

The current log, ~/Library/Logs/Claude/mcp-server-unity-mcp.log, has 283,222 lines. 282,926 of them are the same message, Named pipe connection error: ENOENT … /tmp/unity-mcp-2e1dff22-97341; the other 296 are startup and request messages. The same file holds 12 Couldn't start for Cowork and Code sessions entries, and the app’s main.log holds 17 Failed to connect to unity-mcp: Request timed out entries (timeout: 120000), between 12-04 02:25 and 12-05 05:44 (Taipei time).

The 280,000 lines are only the current file. The four earlier rotated logs (the oldest starts on 11-12) are dominated by ENOENT for the same pipe, about 3.72 million lines in total.

Error Propagation Sequence

Claude desktop app       relay (--mcp)                connections/ and /tmp
    |                         |                              |
    |── initialize ──────────>|                              |
    |<── response ─────────────|  ← normal (0.64 s, clean dir)|
    |── tools/list ──────────>|── registration → pipe ──────>|  ← bridge-…-97341.json
    |                         |<── ENOENT ───────────────────|  ← /tmp/unity-mcp-2e1dff22-97341 missing
    |                         |── retry, log, retry ─────────>|  ← 282,926 lines
    |   …waits 120000 ms…     |                              |
    |  Request timed out      |                              |
Desktop app: "unable to start unity-mcp for Cowork and Code sessions"

Key point: initialize is answered normally and only tools/list gets no reply. A successful handshake makes the failure look like the desktop app’s problem. The diagram is a sketch: the tests only showed “no tools/list reply” and “repeated ENOENT” occurring together; whether tools/list triggers the ENOENT was not traced.

Why it is easy to misread

The warning says startup failed, which points at the app’s config, the Unity version or MCP itself. The relay does start; it answers initialize within 0.64 seconds. With no Unity editor open, unity-mcp has no tools, which is expected: a rerun on 12-07 with a clean directory returned {"tools":[]} to tools/list in 1.16 seconds.

The dividing line: registrations pointing at editors that no longer exist

connections/ held two registration files, both with created_date on 09-10: bridge-2e1dff22-90545.json (file time 19:00:31, editor_pid 90545) and bridge-2e1dff22-97341.json (20:34:42, 97341). Both name /Users/justfly/AI TEST as the project. Neither pid is running now, and no matching pipe file exists under /tmp.

At 12-06 19:56:35 both files were moved out of connections/. In the same second the log’s last-write time stopped at 19:56:35, with no new lines afterwards. The relay process the desktop app had launched (pid 79647, running since 12-05 04:40:02) was still alive then, and it was the one writing the log.

A rerun on 12-07 around 03:10 used the same files as a control:

  • Clean directory: initialize in 0.64 s and tools/list in 1.16 s; 0 ENOENT lines in 15 s.
  • Both files put back: initialize in 0.64 s, no tools/list reply in 20 s, 96 ENOENT lines.
  • Only 90545: no tools/list reply in 12 s, 62 ENOENT lines.
  • Only 97341: no tools/list reply in 12 s, 58 ENOENT lines.
  • Moved away again: the desktop app’s relay stopped writing at once; the log size held for 20 seconds.

Either file alone is enough to block tools/list. The original log only ever names 97341; 90545 had 0 lines before the 12-07 rerun, and why only one of them was picked was not traced. The 12-06 daily report also records that a hand-started relay responded immediately with 0 pipe errors and that the log stopped growing within 15 seconds after the move; the raw output of those measurements was not kept, so the rerun above and the last-write time stand in as evidence.

Code Diff: Before and After

Before: both registration files present, neither editor running.

# state before the move (names and times taken from the originals in connections.stale/)
ls -laT ~/.unity/mcp/connections/
bridge-2e1dff22-90545.json   Sep 10 19:00:31 2026   # ← editor_pid 90545, process gone
bridge-2e1dff22-97341.json   Sep 10 20:34:42 2026   # ← editor_pid 97341; all 282,926 log lines point at its pipe

$ cat bridge-2e1dff22-97341.json
{ "connection_type": "named_pipe",
  "connection_path": "/tmp/unity-mcp-2e1dff22-97341",   # ← this pipe does not exist
  "created_date": "2026-09-10T12:34:42.3811460Z",
  "project_path": "/Users/justfly/AI TEST",
  "protocol_version": "2.0",
  "editor_pid": 97341 }

After: confirm the processes and pipes are gone, then move the files whole, no deletion.

ps -p 90545 -o pid=,command=        # no output = process gone
ps -p 97341 -o pid=,command=
ls /tmp/unity-mcp-2e1dff22-*        # No such file or directory

mkdir -p ~/.unity/mcp/connections.stale
mv ~/.unity/mcp/connections/bridge-2e1dff22-90545.json \
   ~/.unity/mcp/connections/bridge-2e1dff22-97341.json \
   ~/.unity/mcp/connections.stale/

LOG=~/Library/Logs/Claude/mcp-server-unity-mcp.log
wc -c "$LOG"; sleep 15; wc -c "$LOG"   # same size = stopped growing

$ ls ~/.unity/mcp/connections/          # empty
$ ls ~/.unity/mcp/connections.stale/
bridge-2e1dff22-90545.json  bridge-2e1dff22-97341.json

mv instead of rm: the file fields are readable but the format has no official documentation, and “stale” rests on the process and pipe being gone. A wrong call is undone by moving the file back, which is exactly what the 12-07 rerun did.

Side Effects That Should Be Isolated: what the move left alone

A hands-on check on 12-07 shows the move touched only the two registration files. Everything below stayed as it was:

  • The registration files themselves: moved to connections.stale/ with content and file times unchanged.
  • The current log: not truncated or deleted; the 43 MB of evidence stayed (the rerun added 102 ENOENT lines, so it now stands at 43,041,399 bytes and 283,324 lines).
  • Rotated logs: mcp-server-unity-mcp1 through 4.log, about 565 MB in total, last written 11-19 to 12-05, untouched.
  • The desktop app’s relay process: pid 79647 was not restarted; it has been the same process since 12-05 04:40:02.
  • Other relay processes: several started from command-line sessions (for example pid 19953, since 11-24) are still running.
  • The open Unity editor: pid 53024 is running, has no registration file in connections/, and is unrelated to the move.
  • The desktop app config: the unity-mcp entry in claude_desktop_config.json was last modified 12-06 19:51, before the move.
  • The project folder: /Users/justfly/AI TEST, named in the files, still exists and was not touched.

Rule of thumb: touch only the registrations that point at a process that no longer exists, and leave everything else as it is.

Conclusion: what was verified and what was not

Three things were verified. One: both registration files point at editors that no longer exist (pid and pipe both gone). Two: with those files present, the relay does not answer tools/list and keeps writing ENOENT; with them moved away it answers in 1.16 seconds and writes no errors. Three: the relay the desktop app launched stopped writing in the same second as the move, writes again when the files are put back, and stops again when they are removed.

Whether the warning is gone in the desktop app itself was not verified. The app’s last connection attempt to unity-mcp was 12-05 05:44; after the move neither the log nor main.log shows a new unity-mcp start, and the relay process was never restarted. This write-up therefore stops at the relay and its log, and says nothing about what the desktop window shows.

— 邱柏宇

Further reading

The numbers and times here are first-hand records from this machine (the registration files, the relay log, the app’s main.log, and the 12-07 rerun output); no third-party article is cited. The official documents below support only the general concepts:

延伸閱讀

分類: 技術筆記,標籤: 、、、,作者: 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.