Unity MCP
Exposes the Unity Editor through 27 tools for scene and GameObject management, component/material/property editing, asset search, C# compilation and execution, script generation, animation, uGUI, Timeline, play-mode control, screenshots, and workflow execution.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Unity MCP create a cube at origin and screenshot the scene"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Unity MCP
把 Unity 编辑器交给 AI 和流程图操作。一个小型桥接器 + 一个 MCP 服务器 + 一个可视工作流工作室。
Unity 端:
unity/是一个 UPM 包,在编辑器里起一个本地 HTTP 桥(默认127.0.0.1:17653),把编辑器操作暴露成 27 个工具。MCP 端:
server/unity-mcp-server.mjs,零依赖 Node 脚本,走 stdio 说 MCP 协议,任何 MCP 客户端(Claude Desktop / Cursor / Cline / DSH)都能直接调用 Unity。可视化:同一个服务器附带的网页工作流工作室(
127.0.0.1:17800),拖节点连线、填参数、一键跑,节点会实时变绿/变红,截图节点直接把相机画面贴回来。同一批工作流 agent 也能用unity_run_workflow跑。
文档
文档 | 内容 |
安装与接入:Unity 端两种装法、Node 端参数、Claude/Cursor/Cline/DSH 四种客户端配置、局域网、卸载、装不上时 | |
使用手册:10 个任务配方、工具速查表、工作流语法、工作室操作、能力边界、排错 |
想直接跑起来 → 快速开始。想先看能干什么 → USAGE.md 的任务配方。
┌──────────────┐ stdio JSON-RPC ┌────────────────────┐ HTTP ┌─────────────────┐
│ MCP 客户端 │ ─────────────────► │ unity-mcp-server │ ────────► │ Unity 编辑器 │
│ (Claude 等) │ │ · 工具转发 │ │ UnityMcpBridge │
└──────────────┘ │ · 工作流 DAG 引擎 │ ◄──────── │ 27 个工具 │
┌──────────────┐ HTTP/SSE │ · 静态站点 │ 结果 │ 主线程调度 │
│ 浏览器工作台 │ ◄────────────────► │ │ └─────────────────┘
└──────────────┘ └────────────────────┘Related MCP server: UniCortex
快速开始
1. 装进 Unity 项目
两种方式,任选:
A. 拷贝(最快)
把 unity/Editor 整个文件夹复制到你的 Unity 项目 Assets/ 下,重命名成 Assets/UnityMcpBridge/Editor。Unity 重新编译后,菜单栏出现 Tools > Unity MCP > Bridge Window。
B. UPM 本地包
Window > Package Manager > + > Add package from disk...,选中 unity/package.json。
打开 Tools > Unity MCP > Bridge Window,确认状态是 running on 127.0.0.1:17653。默认随编辑器自动启动,端口可在窗口里改。
2. 启动服务器
node server/unity-mcp-server.mjs # 同时开 MCP(stdio) 和网页工作台
node server/unity-mcp-server.mjs --stdio # 只跑 MCP
node server/unity-mcp-server.mjs --no-ui # 只跑 MCP(同 --headless)打开 http://127.0.0.1:17800。左上角显示 已连接 127.0.0.1:17653 就通了。
常用参数:
参数 | 作用 |
| 网页端口 |
| 直接指定桥端口(默认自动扫 17653–17700) |
| 配合 |
| 指定 Unity 项目根目录,读 |
| 启动后自动打开浏览器 |
3. 接到 MCP 客户端
服务器自己会打印可直接粘贴的配置,也可以在工作台右侧「接入 → 复制 MCP 配置」拿到。
Claude Desktop(claude_desktop_config.json):
{
"mcpServers": {
"unity": {
"command": "node",
"args": ["D:/path/to/unity-mcp/server/unity-mcp-server.mjs", "--stdio"]
}
}
}接好之后问它「用 unity_status 看看现在打开了什么场景」就能验证。
接到 DSH
本机已经装好了配置型 bundle @local/unity-mcp(profile desktop),它只是把上面的 stdio 配置交给 DSH 的 @deepseek-ai/dsh-mcp-client,serverName 是 unity,所以 agent 侧的工具名长这样:mcp__unity__unity_status、mcp__unity__unity_create、mcp__unity__unity_run_workflow。
开/关:Settings > Plugins 里找「Unity 编辑器」那条;或改 profile 的
dsh.profile.bundles列表。换目录:bundle 的
cordis.patch.yml里args[0]和cwd是绝对路径,仓库搬家后改成新路径,再plugin_manager install_bundle重装一次即可(同一个包名会覆盖,不会装出两份)。卸载:
plugin_manager remove_bundle @local/unity-mcp。验证:新会话里直接调
mcp__unity__unity_status,或mcp__unity__unity_run_workflow {file:"构建一个场景.json"}。
DSH 拉起的 server 是独立进程,和你手动开的 studio 互不影响:两者连的是同一个 Unity 桥(桥支持多客户端)。想看可视化节点图就用 npm run studio 单独开一个;如果 17800 已被占用,DSH 那个会自动跳过网页部分,只保留 MCP。
编辑器没开也不会让 DSH 启动失败:工具列表来自上一次的 schema 缓存(server/.tools-snapshot.json),调用会明确提示「bridge 不可达」,Unity 打开后下一次调用自动恢复。
工作流工作室

左侧点工具 → 画布落一个节点;从节点右侧圆点拖到另一个节点左侧圆点建立连接。
选中节点后在右侧改参数;参数值写
{{cube.path}}就能拿到上游节点的输出。顶部「运行」按拓扑顺序执行;节点边框变绿=成功、变红=失败并显示错误、半透明=被跳过。
底部三个页签轮流看:运行日志、每个节点的 JSON 输出、Unity 截图预览。
示例里「构建一个场景」是并行两条分支汇聚到截图,可以直接跑一遍看效果。
快捷键:Delete 删选中、Ctrl+S 保存、Ctrl+Enter 运行、空格+拖拽平移、滚轮缩放。
工作流存成 JSON 放在 workflows/,也能「导出」带走;?autorun=1 打开即自动跑一次(做演示/截图用)。同一批文件 agent 侧用 unity_run_workflow {file:"构建一个场景.json"} 或内联 graph 也能跑,不用打开浏览器。
数据传递
写法 | 含义 |
| 节点 |
| 同上,显式写法 |
| 直接上游节点的输出合并后的 |
|
|
整个字符串就是一个占位符时,返回原始类型(对象/数组/数字),不会被转成字符串。
执行控制
每个节点有三项:
条件(when):不成立就跳过该节点,下游继续。支持
{{a.b}} == true、>、<、>=这类比较,其余按真假值判断。失败后继续:默认一旦失败就中止整个运行。
禁用节点:保留在图上但不执行。
core.* 是流程节点,不经过 Unity:core.delay(等待)、core.log(写日志)、core.setvar(设变量)、core.assert(条件不满足则失败)。
工具清单
工具 | 作用 |
| 编辑器状态:版本、项目、播放模式、编译中、当前场景、选中 |
| 读控制台环形缓冲(log/warning/error + 堆栈) |
| 场景对象树,带路径、激活状态、组件名 |
| 按名字 glob + 组件类型查对象 |
| 建空对象或基元(cube/sphere/plane/…),可指定父节点、位置、旋转、缩放 |
| 删对象,或只删某个组件 |
| 世界/本地位置、旋转、缩放、激活 |
| 写任意序列化属性或字段(内置组件的 |
| 读属性,附类型信息 |
| 按类型名加组件(短名/全名/模糊匹配) |
| 改材质 shader 属性:颜色、浮点、向量 |
| 按名字/类型/目录搜资产 |
| 资产类型、GUID、依赖、标签 |
| new / open / save / save_as / info |
| play / stop / pause / unpause / step |
| 执行任意菜单项,如 |
| 刷新资产库、触发编译 |
| 相机渲染成 PNG(game 或 scene 视角),返回路径 |
| 读取/设置编辑器选中 |
| 反射调用任意公开静态方法(兜底口子) |
| 实例化预制体 / 把对象存成预制体 |
| 用 Unity 自带的 Roslyn 编译并执行一段 C#(编译错误带行号回来),可访问项目里的自定义类型 |
| 把代码写成 |
| 建 |
| 建 Canvas(含 EventSystem)、文字、图片、带标签的按钮 |
| 建 |
| 读 play 模式的 fps / 时间 / 帧数 / 已加载场景与对象数 |
| (服务器本地)一次跑完一张节点图,node 或 file 二选一 |
| (服务器本地)列出 |
属性名不用背:写错时错误信息会把该组件的可用属性列出来(最多 40 个),AI 能自己纠回来。数组和列表用 m_Materials[0]、m_Materials.size 这种写法,会转成 m_Materials.Array.data[0]。
能力边界
已经覆盖:场景/对象/组件/材质、C# 编译执行、脚本生成、动画片段、uGUI 界面、Timeline 资产与播放、play mode 下的运行时操作、局域网 + token。
还刻意不做:
建模:只有 cube/sphere/plane 等基元,没有建模或雕刻能力。
Timeline 内容编辑:能建轨道、绑
PlayableDirector、播放/暂停,但还不能往轨道里塞 clip。任意深度的 SerializedProperty:支持数组下标和
.size,不支持List<T>里某个对象的字段级路径。unity_run_csharp的产物不进项目:它编译到内存(毫秒级、不触发重载),关掉编辑器就没了;需要持久化成MonoBehaviour就用unity_create_script,那会触发一次 Unity 重编译。
实现要点
线程模型:TCP 监听在工作线程。普通工具整体派发回主线程执行;
unity_run_csharp这类耗时的编译放在工作线程,只有编译产物的调用回到主线程——所以编译不会冻结编辑器。play mode 安全:Undo 和 MarkSceneDirty 在播放中会抛异常,统一走
EditUtil包装(播放时降级为普通对象操作)。运行时改对象、建对象、截图都能用。零依赖:Unity 侧手写 JSON 解析/序列化,不依赖 Newtonsoft;uGUI 和 Timeline 通过反射访问,项目没装这些包也不会编译失败;Node 侧只用标准库。
域重载安全:静态构造里直接起监听,重载前彻底关闭 socket(先关 socket 再 Stop),端口失败会继续往后试。
截图落盘:写到
<项目>/Library/UnityMcpShots/,网页通过/api/shot读回(路径限制在该目录内)。工作流不 eval:条件表达式是手写解析器,占位符只做字符串替换,存下来的 JSON 不能执行任意代码。
局域网 / 远程
桥默认只听 127.0.0.1。要跨机器用:
Unity 里
Tools > Unity MCP > Bridge Window→ Network → Bind address 改0.0.0.0,填一个 Token,点 Apply(会重启桥)。客户端侧:
node server/unity-mcp-server.mjs --host 192.168.1.20 --unity-port 17653 --token 你的token/ping不需要 token(健康检查),/call和/tools需要x-mcp-token头,缺了返回 401。
只在受信网络里这么做;编辑器桥等于把整台编辑器的操作权交出去。
HTTP 接口
工作台和外部脚本共用这一套(只监听 127.0.0.1):
方法 | 路径 | 说明 |
GET |
| 桥状态、分类、已保存工作流 |
GET |
| 工具 schema + 中文元数据 |
POST |
|
|
POST |
|
|
POST |
| 中止当前运行 |
POST |
| 重新探测 Unity 桥 |
GET/POST/DELETE |
| 列出 / 读取 / 保存 / 删除工作流 |
GET |
| 取截图 PNG |
GET |
| SSE:节点开始/结束、日志、桥状态 |
node server/test-mcp.mjs 会用标准 MCP 客户端流程跑一遍 initialize → tools/list → tools/call,确认协议没问题。
排查
现象 | 处理 |
工作台显示「未找到 Unity」 | 确认编辑器开着、 |
端口被占 | 桥窗口改首选端口,服务器加 |
工具报 | 先 |
报 | 错误信息里已列出可用属性名,按名字重试 |
截图全黑 | 场景里没有相机或相机没朝向物体; |
中文在 Windows 终端乱码 | 只是终端编码问题,浏览器与 JSON 内容是 UTF-8 |
目录
unity-mcp/
├─ unity/ UPM 包(拖进 Assets 也行)
│ ├─ package.json
│ └─ Editor/
│ ├─ UnityMcpBridge.cs 监听、路由、主线程调度、日志缓冲
│ ├─ UnityMcpTools.cs 27 个工具的实现与 schema
│ ├─ UnityMcpUtil.cs 对象/类型/值解析
│ ├─ UnityMcpJson.cs JSON 读写
│ ├─ UnityMcpWindow.cs 编辑器内的状态面板
│ └─ UnityMcp.Editor.asmdef
├─ server/
│ ├─ unity-mcp-server.mjs 入口:HTTP + SSE + stdio
│ ├─ mcp.mjs MCP 协议(含离线 schema 缓存)
│ ├─ workflow.mjs DAG 执行与插值
│ ├─ bridge.mjs Unity 桥客户端 + 端口发现
│ ├─ catalog.mjs 工具中文元数据 + 本地工作流工具
│ ├─ test-mcp.mjs 协议自测(14 项)
│ ├─ test-offline.mjs 编辑器未开时的降级自测
│ └─ test-utf8.mjs 中文往返自测
├─ dsh-bundle/ DSH 配置型 bundle(已装进 profile)
│ ├─ package.json
│ ├─ cordis.patch.yml 插入 dsh-mcp-client(stdio → server)
│ ├─ locale/en.json|zh.json 插件列表里的标题与描述
│ ├─ icon.svg
│ └─ docs/DETAIL.md 插件详情页
├─ ui/ 工作流工作室(原生 JS)
├─ workflows/ 已保存的工作流
└─ docs/扩展
加一个工具只要在 UnityMcpTools.cs 的 Build() 里 Add(...) 一行,填名字、描述、JSON schema、handler;Unity 编译后服务器会自动发现(/tools 直接来自桥)。要给它在左侧工具库配中文名和分类,在 server/catalog.mjs 的 TOOL_META 加一条即可。
Available Tools
29 toolsunity_add_componentB
Add a component by type name (short or full name, fuzzy matched). (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: path (required), component (required).
unity_animationB
Author Animator-free animation clips: create a .anim asset, add float curves (position/scale/rotation), attach an Animation component to an object, and play it in play mode. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: clip, keys, loop, name, +6 more.
unity_asset_infoB
Inspect one asset: type, size, guid, dependencies. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: path (required).
unity_asset_searchA
Search project assets by name filter and/or type. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: type, limit, filter, folder.
unity_consoleA
Read the editor console ring buffer (log/warning/error) with stack traces. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: clear, level, limit.
unity_createB
Create a GameObject (empty or primitive) in the active scene, optionally parented and positioned. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: name (required), scale, parent, position, +2 more.
unity_create_scriptB
Write a .cs file into the project (MonoBehaviour by default), optionally compiling it right away. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: path (required), body, code, compile, +4 more.
unity_deleteB
Delete a GameObject (and its children) from the active scene. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: path (required), component.
unity_findA
Find game objects by name glob and/or component type name. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: name (required), limit, component.
unity_get_propertyC
Read a serialized property or component field value. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: path (required), property (required), component (required).
unity_hierarchyA
Dump the active scene object tree with paths, active flags and component type names. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: root, depth, components.
unity_invokeB
Invoke a public static C# method by type+method name with JSON args (escape hatch for anything not covered). (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: type (required), method (required), args.
unity_list_workflowsA
List workflow files that unity_run_workflow can execute. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: no named parameters.
unity_playmodeB
Enter/exit/pause play mode. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: action (required).
unity_prefabB
Instantiate a prefab into the scene or save a GameObject as a prefab. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: path (required), action (required), parent, target.
unity_refreshA
Refresh the asset database and trigger a script compile if needed. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: no named parameters.
unity_run_csharpA
Compile and run a C# snippet against the live editor with Unity's own Roslyn compiler. Use code for a method body (auto-wrapped, return a value to see it) or source for a complete file. Compile errors come back with line numbers so you can fix and retry. This is how you do anything the other tools do not cover: custom logic, batch edits, project-specific types. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: code, type, method, source, +2 more.
unity_runtimeA
Read play-mode runtime state: fps, time, frame count, loaded scenes, object counts. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: includeInactive.
unity_run_workflowA
Run a node graph against the Unity editor in one call. Pass either a saved workflow file name or an inline graph. Nodes run in dependency order; a node reads upstream output with {{nodeId.field}} placeholders. Returns per-node outputs plus errors. Use this instead of many separate calls when a job has several dependent steps. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: file, graph.
unity_sceneB
Scene operations: new, open, save, save_as, info. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: action (required), path.
unity_screenshotA
Render the game camera or scene view camera to a PNG and return its path. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: view, width, height, inline.
unity_selectionC
Get or set the editor selection. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: paths, action.
unity_set_materialA
Set a shader property (color/float/vector) on the material of an object, or on a material asset. By default the renderer gets its own copy so other objects sharing the material are untouched. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: mode, path, type, value, +2 more.
unity_set_propertyA
Set any serialized property or component field. Auto-resolves 'color' -> m_Color style names. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: path (required), value (required), property (required), component (required).
unity_set_transformB
Set position/rotation/scale/active state of a GameObject. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: path (required), scale, active, position, +3 more.
unity_statusA
Report editor state: Unity version, project, play mode, compile state, active scene, selection, bridge port. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: no named parameters.
unity_timelineB
Create Timeline assets, add tracks, bind a PlayableDirector on an object, and control playback in play mode. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: kind, name, path, action, +2 more.
unity_uiB
Build uGUI screens: create a Canvas (with EventSystem), text labels, images, and buttons with labels. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Inputs: name, size, text, color, +7 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 29 tools
Most tools target a distinct resource+action (create/delete/set_transform/set_property, asset_search/asset_info, screenshot, playmode). A few pairs overlap by design: unity_run_csharp vs unity_invoke vs unity_menu are all escape hatches, and unity_set_property vs unity_set_material both write component/material state, but descriptions make the intended boundary reasonably clear.
Every tool shares the unity_ snake_case prefix, which keeps the set highly predictable. However the stem ordering is mixed: verb_noun (unity_set_transform, unity_find, unity_create_script) alongside noun-first domain names (unity_console, unity_hierarchy, unity_scene, unity_asset_search, unity_playmode), and a couple of bare nouns (unity_selection, unity_prefab) that don't state an action.
29 tools is on the heavy side of the recommended range, though the breadth of Unity's editor domain (scene, assets, components, prefabs, animation, UI, timeline, play mode, workflows) justifies most of them. A few could be collapsed, notably the three escape-hatch tools (invoke, run_csharp, menu) and the separate run/list workflow pair.
Coverage is broad and lifecycle-aware for GameObjects, components, properties, scenes, prefabs, assets, animation, UI and timeline, plus runtime introspection. Gaps exist — no component removal, no asset create/delete/move, no prefab editing/unpack, no build or test-runner tools — but the documented escape hatches (run_csharp, invoke, menu, run_workflow) let an agent work around them.
Maintenance
Related MCP Connectors
Build and run AI workflows, agents, data tables and 1000+ API integrations from any MCP client.
Make games with AI: one MCP server that connects your agent to Unity, Unreal and Godot editors.
Build editable 3D scenes, direct characters and cameras, and export AI video references with MCP.
214 tools for AI agents over one MCP endpoint: image, video, audio, 3D, data, storage, mail, GPUs.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to control the Unity Editor through MCP, allowing scene building, runtime scripting, visual QA, and more.5Apache 2.0
- AlicenseNot gradedqualityBmaintenanceAn MCP server that enables AI agents to control the Unity Editor externally, providing tools for scene, GameObject, component, and other editor operations.1MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI assistants to control the Unity Editor via MCP, allowing scene manipulation, asset management, compilation, and testing through natural language.MIT
- AlicenseNot gradedqualityAmaintenanceEnables AI agents to drive the Unity Editor directly over HTTP, including scene and asset editing, diagnostics, play mode control, code execution, input simulation, and builds, with no separate MCP server process.346MIT