# UnityMCPServer **Repository Path**: unreal2012/unity-mcp-server ## Basic Information - **Project Name**: UnityMCPServer - **Description**: No description available - **Primary Language**: C# - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2026-04-04 - **Last Updated**: 2026-09-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: Unity, MCP ## README # Unity MCP Server English | [简体中文](README.md) **Let your AI assistant control Unity Editor** Connect Claude, Cursor, CodeBuddy, and other AI IDEs directly to Unity Editor via MCP (Model Context Protocol) — create objects, add components, write scripts, and trigger builds, all with natural language. --- ## 🚀 Quick Start (3 Steps) ### 1. Install the Unity Package **Via Git URL (recommended):** ``` Unity → Window → Package Manager → + → Add package from git URL https://gitee.com/unreal2012/unity-mcp-server.git?path=/Unity ``` **Or install locally:** First clone the repository: ```bash git clone https://gitee.com/unreal2012/unity-mcp-server.git ``` Then add the local package: ``` Unity → Window → Package Manager → + → Add package from disk /absolute/path/to/unity-mcp-server/Unity/package.json ``` After installation, Unity will automatically start the MCP service on port 8080. --- ### 2. Clone the Repository (if not done in Step 1) ```bash git clone https://gitee.com/unreal2012/unity-mcp-server.git ``` --- ### 3. Configure Your AI IDE #### Option A: Use the Startup Script (Recommended) Point your MCP config at the startup script — **no manual install or build needed**. The script handles everything automatically. **CodeBuddy** — edit `~/.workbuddy/mcp.json`: ```json { "mcpServers": { "unity-mcp-server": { "command": "/absolute/path/to/unity-mcp-server/mcp-start.sh" } } } ``` **Cursor** — edit `.cursor/mcp.json`: ```json { "mcpServers": { "unity-mcp-server": { "command": "/absolute/path/to/unity-mcp-server/mcp-start.sh" } } } ``` **Claude Code**: ```bash claude mcp add unity-mcp-server /absolute/path/to/unity-mcp-server/mcp-start.sh ``` > **Windows users**: replace `mcp-start.sh` with `mcp-start.bat` > > **Mac users**: grant execute permission before first run: > ```bash > chmod +x /path/to/unity-mcp-server/mcp-start.sh > ``` #### Option B: Manual Build (Advanced) For users who want to modify the TypeScript source: ```bash cd unity-mcp-server npm install npm run build ``` Then update your IDE config to point at the compiled output: ```json { "mcpServers": { "unity-mcp-server": { "command": "node", "args": ["/absolute/path/to/unity-mcp-server/dist/index.js"] } } } ``` > After updating the code or pulling a new version, run `npm run build` again. --- ## 💬 Usage Once configured, use natural language in your AI chat to control Unity: ``` "Create a Cube at (0, 1, 0)" "Move Main Camera to (0, 5, -10)" "List all objects in the scene" "Add a Rigidbody to Player" "Add GameManager script to GameManager" "Remove BoxCollider from Cube" "Play the game" "Take a screenshot" ``` --- ## ⚙️ Configuration The MCP Server connects to Unity Editor via TCP. Priority order: **env vars > config file > defaults** | Method | Description | |--------|-------------| | `UNITY_HOST` env var | Unity host address, default `127.0.0.1` | | `UNITY_PORT` env var | Port number, default `8080` | | `.mcp-config.json` | Auto-generated in project root on first connect | ### Local Connection (Default) No extra configuration needed — connects to `127.0.0.1:8080` automatically. To use a custom port: ```json { "mcpServers": { "unity-mcp-server": { "command": "/absolute/path/to/unity-mcp-server/mcp-start.sh", "env": { "UNITY_PORT": "9000" } } } } ``` ### LAN Connection (Cross-Machine, Not Yet Implemented) When Unity and the AI IDE are on different machines, set `UNITY_HOST` to the Unity machine's LAN IP: ```json { "mcpServers": { "unity-mcp-server": { "command": "/absolute/path/to/unity-mcp-server/mcp-start.sh", "env": { "UNITY_HOST": "192.168.1.20", "UNITY_PORT": "8080" } } } } ``` --- ## 🎮 Supported Operations (29 Tools) ### Connection | Tool | Description | |------|-------------| | `unity_connect` | Connect to Unity Editor | ### Scene Management | Tool | Description | |------|-------------| | `unity_get_scene_info` | Get scene information | | `unity_save_scene` | Save the current scene | | `unity_load_scene` | Load a scene | | `unity_new_scene` | Create a new scene | ### GameObject | Tool | Description | |------|-------------| | `unity_create_gameobject` | Create an object (primitives, with parent support) | | `unity_list_gameobjects` | List direct children (depth=1, non-recursive), with duplicate name detection | | `unity_tree_gameobjects` | Get full recursive tree structure (with maxDepth support) | | `unity_find_gameobject` | Find an object by name/path | | `unity_delete_gameobject` | Delete an object | | `unity_duplicate_gameobject` | Duplicate an object | | `unity_rename_gameobject` | Rename an object | | `unity_reparent_gameobject` | Reparent an object (with worldPositionStays) | ### Transform | Tool | Description | |------|-------------| | `unity_get_transform` | Get position / rotation / scale | | `unity_set_transform` | Set position / rotation / scale | ### Component Management | Tool | Description | |------|-------------| | `unity_manage_component` | Manage components (add / get / set_property / remove) | Built-in components: Rigidbody, BoxCollider, SphereCollider, CapsuleCollider, MeshCollider, MeshFilter, MeshRenderer, Light, AudioSource, Camera, Animator, ParticleSystem, NavMeshAgent, CharacterController, and any custom MonoBehaviour scripts. ### UI Elements | Tool | Description | |------|-------------| | `unity_manage_uielement` | Manage UI elements (create / delete / set_property) | Supported UI types: | uiType | Description | |--------|-------------| | `canvas` | Canvas + CanvasScaler + GraphicRaycaster (auto-created if missing) | | `panel` | Panel (semi-transparent background, stretch fullscreen) | | `button` | Button (Image + Button + child Text) | | `text` | Text label | | `image` | Image | | `raw_image` | RawImage | | `input_field` | Input field (with Placeholder) | | `toggle` | Toggle (with Background/Checkmark/Label) | | `slider` | Slider (with Fill/Handle) | | `scrollbar` | Scrollbar | | `dropdown` | Dropdown (with Template/Item/Arrow) | | `scroll_rect` | Scroll Rect (with Viewport/Content) | Configurable UI properties: `color`, `text`, `fontSize`, `width`/`height`, `anchor` (center/top/bottom/stretch, etc.), `sprite`, `interactable`, `raycastTarget` ### Prefab | Tool | Description | |------|-------------| | `unity_instantiate_prefab` | Instantiate a prefab | | `unity_create_prefab` | Create a prefab from a GameObject | ### Asset Management | Tool | Description | |------|-------------| | `unity_get_assets` | Get project asset list | | `unity_import_asset` | Import an asset | ### Script Management | Tool | Description | |------|-------------| | `unity_manage_script` | Manage script files (create / read / update / delete) | | `unity_compile_scripts` | Compile all scripts | ### Build Management | Tool | Description | |------|-------------| | `unity_manage_build` | Build for Android/iOS, check build status | ### Editor Control | Tool | Description | |------|-------------| | `unity_play` / `unity_pause` / `unity_stop` | Playmode control | | `unity_get_editor_state` | Get editor state | | `unity_take_screenshot` | Capture a screenshot | --- ## 🔒 Security - Binds to `127.0.0.1` by default (localhost only) - LAN mode restricts to the local subnet; external IPs are rejected --- ## Requirements - Unity 2020.3+ - Node.js 18+ --- **Turn your AI assistant into a remote control for Unity!** 🎮