/ 目錄 / 演練場 / mcp-unity
● 社群 CoderGamester ⚡ 即開即用

mcp-unity

作者 CoderGamester · CoderGamester/mcp-unity

一個專注於場景編輯、測試和 prefab 工作的 Unity MCP — 相比更大的替代方案更簡潔。

CoderGamester/mcp-unity 是 Unity 6+ 的 Node 型 MCP 外掛程式,擁有 ~30 個範圍明確的工具:場景管理、GameObject 操作、元件、prefab、材質、測試、控制台。設計用於 Cursor、Claude Code、Codex、Windsurf。

為什麼要用

核心特性

即時演示

實際使用效果

unity-3.replay ▶ 就緒
0/0

安裝

選擇你的客戶端

~/Library/Application Support/Claude/claude_desktop_config.json  · Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "unity-3": {
      "command": "TODO",
      "args": [
        "See README: https://github.com/CoderGamester/mcp-unity"
      ],
      "_inferred": true
    }
  }
}

開啟 Claude Desktop → Settings → Developer → Edit Config。儲存後重啟應用。

~/.cursor/mcp.json · .cursor/mcp.json
{
  "mcpServers": {
    "unity-3": {
      "command": "TODO",
      "args": [
        "See README: https://github.com/CoderGamester/mcp-unity"
      ],
      "_inferred": true
    }
  }
}

Cursor 使用與 Claude Desktop 相同的 mcpServers 格式。專案級設定優先於全域。

VS Code → Cline → MCP Servers → Edit
{
  "mcpServers": {
    "unity-3": {
      "command": "TODO",
      "args": [
        "See README: https://github.com/CoderGamester/mcp-unity"
      ],
      "_inferred": true
    }
  }
}

點擊 Cline 側欄中的 MCP Servers 圖示,然後選 "Edit Configuration"。

~/.codeium/windsurf/mcp_config.json
{
  "mcpServers": {
    "unity-3": {
      "command": "TODO",
      "args": [
        "See README: https://github.com/CoderGamester/mcp-unity"
      ],
      "_inferred": true
    }
  }
}

格式與 Claude Desktop 相同。重啟 Windsurf 生效。

~/.continue/config.json
{
  "mcpServers": [
    {
      "name": "unity-3",
      "command": "TODO",
      "args": [
        "See README: https://github.com/CoderGamester/mcp-unity"
      ]
    }
  ]
}

Continue 使用伺服器物件陣列,而非映射。

~/.config/zed/settings.json
{
  "context_servers": {
    "unity-3": {
      "command": {
        "path": "TODO",
        "args": [
          "See README: https://github.com/CoderGamester/mcp-unity"
        ]
      }
    }
  }
}

加入 context_servers。Zed 儲存後熱重載。

claude mcp add unity-3 -- TODO 'See README: https://github.com/CoderGamester/mcp-unity'

一行命令搞定。用 claude mcp list 驗證,claude mcp remove 移除。

使用場景

實戰用法: mcp-unity

如何用最少的儀式從聊天中建立簡單場景

👤 獨立 Unity 開發者 ⏱ ~15 min beginner

何時使用: 你想要一個 Unity MCP,不會有 100+ 個工具佔用你的上下文。

前置條件
  • Unity 6 或更新版本 — unity.com/download
  • Node 18+ — nodejs.org 或 nvm
  • 從 git URL 安裝套件 — 套件管理程式 > + > 從 git URL 新增:https://github.com/CoderGamester/mcp-unity.git
步驟
  1. 組合場景
    建立新場景 'Playground'。新增一個平面、一個方向光,以及 3 個立方體在位置 (-2,0,0)、(0,0,0)、(2,0,0)。✓ 已複製
    → 場景出現,物件可見
  2. 連接互動
    為每個立方體新增 Rigidbody 和 BoxCollider。讓原點的立方體為動力學。✓ 已複製
    → 元件在檢查器上可見
  3. 執行測試
    run_tests mode=EditMode。顯示失敗。✓ 已複製
    → 測試輸出

結果: 一個可工作的場景 + 通過的測試,全部在聊天中。

注意事項
  • batch_execute 回滾行為不一致 — 不是真正的交易 — 假設發生錯誤時部分成功;在批次後驗證
搭配使用: github

如何從聊天中編寫和實例化 prefab

👤 建立可重用資產的 Unity 開發者 ⏱ ~15 min intermediate

何時使用: 你想要代理維護一個 prefab 庫。

步驟
  1. 建立 prefab
    建立一個 GameObject 'Enemy',包含 Rigidbody + EnemyAI 元件,然後從它建立 prefab 在 Assets/Prefabs/Enemy.prefab。✓ 已複製
    → 建立 prefab 檔案
  2. 實例化
    在距離原點 50 單位內的 5 個隨機位置將 Assets/Prefabs/Enemy.prefab 新增到場景。✓ 已複製
    → 放置 5 個敵人

結果: 一個可重用的 Enemy prefab + 5 個放置的實例。

如何在緊密迴圈中用 run_tests 迭代修復

👤 具有測試覆蓋的 Unity 開發者 ⏱ ~15 min intermediate

何時使用: 錯誤 + 測試存在;想要快速紅-綠-重構。

步驟
  1. 看到失敗
    run_tests mode=EditMode filter='EnemyAI_ShouldPatrol'。顯示堆疊。✓ 已複製
    → 帶行號的失敗斷言
  2. 編輯和重新測試
    應用最小修復,儲存,並重新執行測試。✓ 已複製
    → 綠色測試

結果: 綠色測試,對修復有信心。

搭配使用: github

組合

與其他 MCP 搭配,撬動十倍槓桿

unity-3 + github

執行測試,然後提交 + 開啟修復的 PR

修復 EnemyAI 測試失敗,在分支 fix/enemy-patrol 上提交,開啟 PR。✓ 已複製

工具

此 MCP 暴露的能力

工具輸入參數何時呼叫成本
create_scene name: str 開始新場景 free
load_scene path: str 開啟現有場景 free
get_gameobject name_or_id: str 查詢一個物件 free
update_gameobject id, props 重新命名、重新提升父物件、切換活動 free
update_component target, component, values 調整元件欄位 free
create_prefab source_id, path 將物件擷取為 prefab free
add_asset_to_scene path, position?, rotation? 實例化資產/prefab free
run_tests mode: 'EditMode'|'PlayMode', filter? 單位測試 free
get_console_logs since_ms? 檢查錯誤 free
batch_execute calls: Call[] 組合多個工具呼叫 free

成本與限制

運行它的成本

API 配額
無 — 僅限本地
每次呼叫 Token 數
小;此 MCP 有緊湊的工具列表
費用
免費(開源)
提示
透過 batch_execute 批次相關操作以減少往返。

安全

權限、密鑰、影響範圍

最小權限: 僅限本地專案存取
憑證儲存:
資料出站: 本地主機;LLM 看到你的工具傳回的任何內容
切勿授予: 將 Node 橋接公開給非迴圈

故障排查

常見錯誤與修復

Unity '套件無法解析'

需要 Unity 6 或更新版本。檢查版本;git URL 安裝在舊編輯器上會失敗。

Node 橋接在啟動時當機

需要 Node 18 + npm 9。檢查 'node -v' 並升級。

驗證: node -v
測試未出現

測試組件必須在參考 TestRunner 的組件定義檔案中定義。

替代方案

mcp-unity 對比其他方案

替代方案何時用它替代權衡
MCP for Unity (CoplayDev)你想要最大的 Unity 工具表面,包含物理/VFX 覆蓋更多工具 = 更多上下文成本
Unity-MCP (IvanMurzak)你需要 Roslyn 支持的一次性 C# 執行更多功能,更多風險

更多

資源

📖 閱讀 GitHub 上的官方 README

🐙 查看未解決的 issue

🔍 瀏覽全部 400+ MCP 伺服器和 Skills