Unity MCP
MCP server: Unity MCP
Installation
npx unity-mcpAsk AI about Unity MCP
Powered by Claude ยท Grounded in docs
I know everything about Unity MCP. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
Unity MCP โจ
Create your Unity apps with LLMs!
Unity MCP is an end-to-end toolchain that lets AI assistants (e.g., Claude, Cursor, Windsurf, VS Code) interact with the Unity Editor through the Model Context Protocol (MCP). Give your LLM tools to manage assets, control scenes, edit scripts, and automate workflows directly inside the Unity Editor.
๐ฌ What is this repository?
This repo contains:
- A Unity Editor package that runs a local HTTP bridge inside the Editor
- A TypeScript-based MCP Server that exposes Unity operations as MCP tools (stdio)
- A TypeScript sample MCP Client for quick smoke testing
[LLM / MCP Client] โ [MCP Server (Node/TypeScript)] โ [Unity Bridge (Unity Editor)]
Key Features ๐
- ๐ฃ๏ธ Natural Language Control โ Ask your LLM to perform Unity tasks
- ๐ ๏ธ Powerful Tools โ Assets, scenes, game objects, components, editor utilities, packages, play mode, and more
- ๐ค Automation โ Script repetitive or multi-step Editor tasks
- ๐จ Visual Scripting Integration โ Create Unity Visual Scripting graphs from MCP operations with pre-built templates
- ๐ Automatic Console Verification โ Every tool operation automatically checks Unity console for errors/warnings
- โ Enhanced Error Handling โ Immediate feedback with console context when operations fail
- ๐ฎ Smart Play Mode Control โ Prevents play mode when compilation errors exist
- ๐งฉ Extensible โ Add new Unity endpoints and MCP tools as your workflow grows
Available Tools
Tools are exposed with underscore names only. Selected highlights:
- unity_console โ Read or clear Unity console
- unity_play โ Start/stop/pause/resume Play Mode
- unity_packages โ UPM list/install/remove
- unity_assets โ AssetDatabase list/find/refresh
- unity_selection โ Get/set selection
- unity_gameObject โ Create/get/set/delete hierarchy items
- unity_component โ Add/update/get/destroy components
- unity_editor โ State, info, notify, buildTarget, prefs, invoke
- unity_scene โ open/save/saveAs/getLoaded/create/createClean/unload/clear
- unity_prefab โ apply/revert prefab instances
- unity_bake โ Start lighting bake
- unity_profiler โ Memory snapshot
- unity_import โ Common texture importer setup
- unity_menu โ Execute Editor menu items
- unity_asset โ Instantiate assets into the scene
- unity_tests โ Run EditMode/PlayMode tests
- unity_rendering โ Create light/camera/material, set properties
- unity_gameplay โ Rigidbody/Collider helpers, tag/layer
- unity_code โ Write files, create scripts, attach scripts, compile
- unity_visualscripting โ Create visual scripts, add nodes, connect workflows
- unity_visualscripting_templates โ Browse, search, and apply workflow templates
- unity_import - Import .unitypackages or copy external files to unity project.
How It Works ๐ค
- Unity Bridge โ Editor-only package hosting a local HTTP API and SSE logs (127.0.0.1:58888)
- MCP Server โ Node/TypeScript process that translates MCP tool calls to Unity Bridge endpoints
- MCP Client โ Your LLM IDE or agent that speaks MCP over stdio
Installation โ๏ธ
Note: Unity 2022.3+ and Node.js 18+ are required.
1) Install Unity Bridge Package
- In Unity, open Package Manager โ
+โ Add package from disk... - Select
PathToFile/UnityBridge/Packages/com.example.mcp.unitybridge/package.json - Let Unity load, then enter Play Mode once (or wait for scripts to finish compiling)
When the bridge is running you should see in the Console:
UnityMcpBridge running at http://127.0.0.1:58888/
2) Install MCP Server dependencies
cd MCP/server
npm install
Optional (sample client):
cd MCP/client
npm install
3) Build the MCP Server
cd MCP/server
npm run build
You can also run in dev with TypeScript directly:
cd MCP/server
npm run dev
Configure Your MCP Client (Cursor, VS Code, Claude Code, etc.)
Add a server entry to your MCP client configuration pointing to the built server. Use underscore tool names only.
Example configuration (JSON):
{
"unity-mcp": {
"command": "node",
"args": [
"PathToFile/MCP/server/dist/index.js"
],
"env": {
"UNITY_BRIDGE_URL": "http://127.0.0.1:58888"
}
}
}
Console Verification Configuration
The server includes automatic console verification. Configure with environment variables:
{
"unity-mcp": {
"command": "node",
"args": ["PathToFile/server/dist/index.js"],
"env": {
"UNITY_BRIDGE_URL": "http://127.0.0.1:58888",
"UNITY_CONSOLE_VERIFICATION": "true",
"UNITY_CONSOLE_CHECK_DELAY_MS": "500"
}
}
}
Environment Variables:
UNITY_BRIDGE_TOKENโ Security token (set same value in Unity and server)UNITY_CONSOLE_VERIFICATIONโ Enable automatic console checking (default: true)UNITY_CONSOLE_CHECK_DELAY_MSโ Delay before checking console (default: 500ms)UNITY_COMPILE_TIMEOUT_MSโ Script compilation timeout (default: 120000ms)
Notes:
- The server communicates over stdio; your client should launch it as a stdio tool
- Console verification provides immediate feedback on operation success/failure
- Every tool operation automatically checks Unity console for errors and warnings
Usage โถ๏ธ
- Open your Unity project with the bridge package installed
- Start your MCP Client; it should launch the Node server via stdio
- Use tools by name (e.g.,
unity_gameObjectwith actioncreate)
Sample smoke test (optional):
cd MCP/client
# Use tsx for both client and server
set MCP_USE_TSX=1 # Windows (PowerShell: $env:MCP_USE_TSX="1")
npm run dev
You should see:
- Tool discovery
- Editor state/info/notify
- Console read/clear
- Create/update/delete a GameObject, component operations
- Play/pause/resume/stop
- Scene save/saveAs
- Package list
Visual Scripting Integration ๐จ
Unity MCP Bridge now includes powerful Visual Scripting integration that allows you to create Unity Visual Scripting graphs from MCP operations and natural language commands.
Key Features
- Template System: Pre-built workflow templates for common game development patterns
- MCP to Visual Script Conversion: Transform MCP operations into visual script nodes
- Node-Based Workflows: Design complex workflows using visual nodes
- Automated Connections: Intelligent node connection and flow management
Quick Examples
// Apply a player setup template
await client.callTool("unity_visualscripting_templates", {
action: "apply",
templateName: "create_player_setup",
gameObjectPath: "Player"
});
// Generate visual script from MCP operations
await client.callTool("unity_visualscripting", {
action: "generateFromMcp",
gameObjectPath: "GameManager",
operations: [
{ tool: "unity_console", action: "clear", description: "Clear console", order: 1 },
{ tool: "unity_scene", action: "save", description: "Save scene", order: 2 }
],
autoConnect: true
});
Available Templates
- Player Management: Complete player setup with components
- Scene Management: Scene transitions and optimization
- Asset Management: Asset optimization and validation workflows
- Testing & QA: Automated testing pipelines
- Build & Deploy: Complete build and deployment processes
For detailed documentation, see Visual Scripting Integration Guide.
Security ๐
- Bridge binds to 127.0.0.1 and supports optional
X-Unity-Bridge-Token - Set
UNITY_BRIDGE_TOKENin both Unity and the MCP server environment for authentication
Troubleshooting โ
- ECONNREFUSED/timeout โ Ensure Unity Editor is open, package installed, and Console shows the bridge is running
- 401 Unauthorized โ Set
UNITY_BRIDGE_TOKENin both server and Unity (EditorPrefs keyMCP_UnityBridge_Tokenalso supported) - Port in use โ Another service is using 58888; close it or adjust environment
- Scene/asset paths โ Use project-relative
Assets/...paths - Compiling domain reload โ The bridge restarts its listener on reload; retry after compile completes
For Developers ๐ ๏ธ
- Server: TypeScript (ESM) with
@modelcontextprotocol/sdk, axios, eventsource - Client: TypeScript sample that exercises most tools and prints Unity console deltas
- Unity Bridge: C# Editor-only package (HttpListener + SSE + main-thread queue)
Build/test commands:
# Server
cd MCP/server
npm run dev # tsx
npm run build # tsc
node dist/index.js
# Client (optional)
cd MCP/client
npm run dev # tsx
