A bidirectional bridge connecting MCP clients (e.g., Claude, Cursor) to the Unity Editor, enabling AI-driven control over scenes, objects, and scripts.
Unity MCP is a dual-end architecture tool built with C# and Python, enabling direct interaction between AI coding assistants and the Unity Editor through the Model Context Protocol (MCP).
Core Architecture#
Dual-layer architecture design:
- Unity Editor Side: TCP server implemented in C#, listening on port 6400, auto-starts bridge service using
[InitializeOnLoad] - Python Side: MCP server based on FastMCP framework, communicates with AI clients via stdio and connects to Unity via TCP
Key Features#
Editor Control#
- Execute editor actions: PLAY, PAUSE, STOP, BUILD, SAVE
- Read and filter Unity Console logs
Scene Management#
- Get scene list and current scene info
- Open/save/create/switch scenes
Object Management#
- Create/delete objects (Cube, Sphere, Camera, Empty, etc.)
- Set Transform position/rotation/scale
- Add/remove components
- Find objects by name, get hierarchy structure
Script Management#
- Create/view/update script files
- Attach scripts to game objects
- Support custom namespaces and templates
Assets & Materials#
- Import assets, instantiate/create/apply Prefabs
- Set object materials with RGB color parameters
- Get project asset list
Requirements#
- Unity 2022.3+
- Python >=3.12
- Dependencies: httpx>=0.28.1, mcp[cli]>=1.4.1
Installation#
- Import package
com.justinpbarnett.unity-mcpvia Unity Package Manager - Install Python dependencies:
pip install httpx mcp[cli]oruv sync - Start Python server:
python Python/server.py - Configure MCP client connection
Extension Development#
Supports custom tool addition: Register command handlers in C#, define tool functions in Python using @mcp.tool() decorator.