SimpleMcpServer
Allows AI agents to manipulate Unity scenes, including creating, deleting, and modifying GameObjects and their components, as well as querying the scene hierarchy.
Click on "Install 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., "@SimpleMcpServercreate a cube at position (0, 1, 0)"
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.
SimpleMcpServer
让 AI 代理(Claude Code、OpenCode 等)通过 MCP 协议直接操作 Unity 场景。
必须配合 SimpleMCPBridge(Unity 侧桥接包)使用。
架构
AI Agent (Claude Code / OpenCode)
│ MCP (stdio)
▼
SimpleMcpServer (Node.js/TypeScript) ← 本仓库
│ WebSocket
▼
SimpleMCPBridge (C#) ← 另一个仓库,需单独 clone 到 Unity Assets/
│
▼
Unity Editor / RuntimeSimpleMcpServer(本仓库)— 处理 MCP 协议,注册工具,转发请求到 Unity
SimpleMCPBridge(companion repo)— 在 Unity 内运行的 WebSocket 客户端,执行场景操作
Related MCP server: Agent Bridge for Unity
前置条件
Node.js 22+
Unity 2022.3+ — 项目已安装 SimpleMCPBridge 包
npm — 随 Node.js 一起安装
验证 Node.js:
node --version # 应输出 v22.x.x 或更高
npm --version # 应输出 10.x.x 或更高安装与设置
自动安装(推荐)
双击 setup.bat。
手动安装
cd SimpleMcpServer
npm install
npm run build使用
前置:安装 SimpleMCPBridge
cd YourUnityProject/Assets/
git clone https://github.com/redcool/SimpleMCPBridge_Unity.git SimpleMCPBridge1. 启动 Unity Bridge(prefab 方式)
用 Unity 打开项目
将
Assets/SimpleMCPBridge/Prefabs/MCPBridge.prefab拖入场景(或给任意 GameObject 添加MCPBridge组件)选中该对象,Inspector 顶部即显示连接状态(● Connected / ○ Disconnected)、
ws://ip:port、Bridge ID 与 Connect / Disconnect 按钮Server IP / Port 默认
127.0.0.1:45678,如需修改见下方bridge-config.json
Bridge 通过 [ExecuteAlways] 在 Edit Mode、Play Mode、打包运行三态下均工作;默认 isAutoReconnect=true,场景加载、进出 Play Mode、脚本重编译(domain reload)后自动重连,无需手动操作。
bridge-config.json(可选,默认即可用)
Bridge 启动时自动加载配置——配置文件不存在时,首次自动从包内 Resources/bridge-config.json 拷贝生成(已存在则不覆盖),改完需重启生效:
环境 | 路径 |
Editor | 项目 |
Player |
|
兜底 | 包内 |
{ "serverIp": "127.0.0.1", "serverPort": 45678, "encryptionKey": "" }serverIp/serverPort— 与 Server 侧config.json的ip/port对应encryptionKey— 与 Server 侧encryptionKey一致时启用 AES-256-CBC 载荷加密;空 = 透传methodBlocklist/methodAllowlist(可选)—scene.call_component_method权限控制,详见桥 README
2. 启动 MCP Server
推荐:在独立 cmd 窗口运行(不占用 AI 工具的终端)
# 在 PowerShell 或 cmd 中执行:
Start-Process -FilePath "cmd.exe" -ArgumentList "/K", "cd /d path\to\SimpleMcpServer && start.bat"或者在文件管理器双击 start.bat 也会弹出 cmd 窗口。
# 编译 + 启动(直接在当前终端)
start.bat
# 跳过编译(代码未改时)
start-quick.bat连接成功输出:
[Server] Bridge connected
[Server] Registered N tool(s) from bridge [ID: xxxx]
[Server] Ready (ws://127.0.0.1:45678)3. 配置 AI 代理
{
"mcpServers": {
"unity": {
"command": "node",
"args": ["path/to/SimpleMcpServer/dist/index.js"]
}
}
}4. 验证连通性
node tests/test-e2e.cjs预期输出:*** TEST PASSED ***
对象寻址
Unity 侧的场景工具同时支持两种方式定位 GameObject:
参数 | 说明 |
| Unity 实例 ID,精确唯一,但 domain reload 后失效 |
| Transform 路径(如 |
解析优先级:instanceId > path。get_hierarchy 和 get_objects 的返回值同时包含两者。
可用工具
工具由 Unity Bridge 通过 register_tools 动态注册,数量随桥接平台/条件编译变化(当前 Editor 桥实测 127 个桥工具 + 服务端合成 2 个 = 129 个)。下表按类别简述常用工具;完整清单见 SimpleMCPBridge 仓库 README。
场景工具(SceneHandler)
工具 | 说明 |
| 获取场景层级树(含 path、instanceId、组件名、位置) |
| 查找对象,可选按 |
| 创建 GameObject,支持 name / parentPath / position / rotation / scale |
| 按 instanceId 或 path 删除对象 |
| 按 instanceId 或 path 设置 position / rotation / scale |
| 修改组件字段/属性,支持 Vector3、Color、Enum 等类型 |
| 按 instanceId 或 path 获取 GameObject 所有组件列表 |
| 获取组件所有可序列化属性名和当前值 |
| 按 instanceId 或 path 启用/禁用 GameObject |
| 按 instanceId 或 path 复制 GameObject |
| 按 instanceId 或 path 重命名 GameObject |
| 按 instanceId/path 设置父级, |
| 按类型名添加组件(如 Rigidbody) |
| 按 assetPath 实例化预制体到场景,支持 transform 和 parent(仅 Editor) |
| 修改运行时材质颜色/纹理。资产级修改建议直接改 |
| 进入播放模式(仅 Editor) |
| 退出播放模式(仅 Editor) |
| 暂停/继续播放模式 — 传 |
| 获取当前播放模式状态 — 返回 isPlaying/isPaused/mode(仅 Editor) |
| 加载场景(按 Assets 路径,支持 |
| 将 GameObject 保存为预制体(仅 Editor) |
| 调用组件公开方法,带黑名单/白名单权限控制 |
资源工具(AssetHandler,仅 Editor)
工具 | 说明 |
| 按名称和/或类型搜索项目 Assets。参数: |
| 查找引用了指定资源的所有资源(反向依赖)。参数: |
| 创建资源(材质/文件夹等)(仅 Editor) |
| 删除资源(带引用预检,force 可跳过)(仅 Editor) |
| 重命名资源(仅 Editor) |
| 移动资源到新路径(仅 Editor) |
录制工具(RecordingHandler)
工具 | 说明 |
| 开始录制 Game 视图画面。仅 Play Mode 可用。可选参数:width/height/fps/videoBitRate/enableAudio/keyframeInterval |
| 停止录制并导出 MP4(异步)。返回后调用 |
| 查询录制/导出状态 — 返回 isRecording/elapsedSeconds/state/exported filePath |
保存位置:
PC: 项目根目录
VideoRecord/(Assets 同级)Android/iOS: app 临时目录
{temporaryCachePath}/VideoRecord/
编辑器工具
工具 | 说明 |
| 触发 Unity 脚本重新编译(外部修改 C# 后用)(仅 Editor) |
| 按菜单路径打开 Unity Editor 窗口,如 |
PlayerPrefs 工具(PlayerPrefsHandler)
工具 | 说明 |
| 读取全部 PlayerPrefs(按 key 过滤可选) |
| 读取单个 key |
| 设置 key(自动类型推断) |
| 删除 key(支持通配符) |
UI Toolkit 工具(UIToolkitHandler)
工具 | 说明 |
| 在指定面板创建视觉元素 |
| 移除视觉元素 |
配置
编辑 config.json(不存在时首次启动自动从 config.json.template 复制生成,见「首次运行」)。完整字段:
{
"ip": "0.0.0.0",
"port": 45678,
"encryptionKey": "",
"encryption": false,
"evalEnabled": true,
"allowedIps": ["127.0.0.1", "::1"],
"llm": { "enabled": true, "provider": "agnes", "baseUrl": "https://apihub.agnes-ai.com/v1", "apiKey": "YOUR_API_KEY_HERE", "model": "agnes-2.0-flash", "temperature": 0.7, "maxTokens": 1024 }
}ip/port:监听地址与端口。本地127.0.0.1,云端0.0.0.0encryption/encryptionKey:可选 AES-256-CBC 载荷加密(替代 TLS/wss),Server 与 Bridge 配置需一致;空密钥 = 透传evalEnabled:editor.eval工具开关(默认true,以用户方便为先 —— 开发调试/快速原型/补救缺口工具时即时可用)。false时tools/list不暴露editor.eval给 agent。风险:eval 执行任意 C# = 完全机器控制,任何能调/rpc的 AI 可执行任意代码(读写文件、删资产、网络访问);不可信环境(共享机器/公网暴露)务必关闭或扩allowedIps白名单。Editor 侧另有EditorPrefs SimpleMCPBridge_EvalEnabled二次 gate,见桥 README「Editor Eval 开关与安全说明」allowedIps:IP 白名单(本版本新增)——只放行白名单内的客户端调用 HTTP/rpc、/sse、/mcp端点,其余返回 403;默认["127.0.0.1","::1"]仅本机;WebSocket 与/ab资源端点不受此限制。配置缺失时自动从config.json.template复制生成 config.json(首次启动自动创建,见「首次运行」);字段缺失/为空数组/非数组时回退到默认["127.0.0.1","::1"](仅本机)llm:LLM 配置(apiKey 用环境变量LLM_API_KEY覆盖更安全;config.json 已被 .gitignore 排除,勿提交真实 key)
开发
npm run dev # tsx 监听模式
node tests/test-e2e.cjs # E2E 测试
# 目录结构
src/
├── index.ts # 入口(启动 server)
├── server.ts # WS Server + MCP handlers(核心)
├── bridgeState.ts # bridge 连接状态/路由(last-registration-wins、failover)
├── ab.ts # AssetBundle 上传/部署端点
├── crypto.ts # AES-256-CBC 载荷加密(#ENC# 前缀)
├── config.ts # config.json 加载(缺失时从 template 生成)
├── llm.ts # LLM 代理(ai_request/ai_response)
├── logger.ts # 日志(stderr + server.log,脱敏)
├── tools.ts # 服务端合成工具(bridge.list / bridge.call)
└── types.ts # 类型定义
tests/
├── test-e2e.cjs # E2E 测试(initialize + tools/list + get_hierarchy)
├── test-playmode-cycle.cjs # Play Mode 循环测试(进出播放验证 bridge 自动重连)
└── auto-test-android.ps1 # Android 全流程自动化测试故障排查
"WebSocket server error: listen EADDRINUSE" → 端口被占用,杀掉残留进程:
Get-Process -Name "node" | Stop-Process -Force"Unity not connected" → Unity 没打开,或 SimpleMCPBridge 没启动
Bridge 进出 Play Mode 后断连
→ 确认 Unity 菜单 Edit → Project Settings → Editor → Enter Play Mode Settings 中 Reload Domain 已开启。Bridge 依赖 [InitializeOnLoad] 在 domain reload 后重新订阅 EditorApplication.update。如关闭 Domain Reload,Bridge 连接会在 Play Mode 期间保持,但退出后无法自动重连。
测试超时 → E2E 测试会启动自己的 Server 实例,Bridge 需要通过重试循环重连到新 Server
HTTP 调用返回 403
→ 请求源 IP 不在 allowedIps 白名单。修改 config.json 的 allowedIps 加来源 IP 后重启服务端。
相关仓库
仓库 | 说明 |
本仓库 — MCP Server,Node.js 端 | |
Unity 桥接包,clone 到 Unity 项目的 |
技术说明
MCP SDK v1.x 低阶 API(
setRequestHandler),不用registerTool()(该 API 在connect()后抛出异常)WebSocket 通信(
ws库),IP/Port 来自config.json工具通过
register_tools消息从 Bridge 动态注册到 Server,Bridge 重连后自动重新注册Unity Bridge 活动传输为 .NET
ClientWebSocket(NetWebSocketClient封装,BridgeClient.ConnectToServer()创建);旧版纯 TCP RFC 6455 实现(WebSocketClient)已标记[Obsolete]仅作参考Server 同时暴露 HTTP
/rpc端点用于程序化调用(E2E 测试使用)/health端点返回 bridge 连接状态、工具列表、播放模式状态HTTP
/rpc、/sse、/mcp端点受allowedIps白名单 gate(403);WebSocket 升级路径与/ab不受限消息负载上限 4MB(maxPayload)
服务端每 ~30s ping、超时未 pong 判定失活并
terminate()断连(isAlive 心跳)日志脱敏:工具名 + 参数长度(不打印明文 payload),错误路径保留详情
config.json 不存在时首次启动自动从 template 复制生成;改完配置重启生效
进程级安全网:
uncaughtException/unhandledRejectionhandler 记日志后继续运行(不崩进程),防单个坏工具响应或未捕获 rejection 带走整个 relay(丢连接 + retryQueue + 在途调用)
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
No tool schema history has been recorded yet.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to control Unreal E…
Cloud Blender for AI agents: scenes, assets, renders, MP4, STL, GLB — over hosted remote MCP.
Shared memory and actions for Claude, Kiro, OpenAI, Cursor, and other MCP-compatible AI clients.
1Nifty's MCP server — exposes tasks, projects, messages, and files as tools for AI agents.
Related MCP Servers
- AlicenseBqualityDmaintenanceControl Unity Editor from AI agents. 200+ MCP tools for GameObjects, Scenes, Assets, Materials, Prefabs, Terrain, Physics, Lighting, and more. Works with Claude, Cursor, Windsurf, VS Code Copilot — any MCP client. Zero config: just npx and go.6213MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to control the Unity Editor through MCP, allowing scene building, runtime scripting, visual QA, and more.4Apache 2.0
- FlicenseNot gradedqualityDmaintenanceConnects Claude Code to the Unity Editor via MCP, enabling AI-driven control of scenes, assets, components, UI, animations, and more through 91 tools.2-
- AlicenseNot gradedqualityAmaintenanceEnables AI assistants to control the Unity Editor via MCP, allowing scene manipulation, asset management, compilation, and testing through natural language.MIT
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/redcool/SimpleMCPServer'
If you have feedback or need assistance with the MCP directory API, please join our Discord server