Go to file
whatevertogo 300a745bf2
feat: Prefab Feature Updates (#611)
* feat: Add prefab read operations (get_info, get_hierarchy, list_prefabs)

- Add get_info: retrieve prefab metadata (GUID, type, components, child count, variant info)
- Add get_hierarchy: get prefab internal structure with pagination support
- Add list_prefabs: search prefabs in project with optional name filtering
- Extract PrefabUtilityHelper class for reusable prefab utility methods
- Update Python tool descriptions and parameter documentation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix: Use correct API to save prefab stage changes

Replace PrefabUtility.SaveAsPrefabAsset (for creating new prefabs) with
EditorSceneManager.SaveScene to properly save stage modifications.

This fixes the issue where component additions were lost after closing
the prefab stage.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* refactor: improve code quality and error handling

- Add pagination constants (DefaultPageSize, MaxPageSize)
- Extract SaveAndRefreshStage helper to reduce duplication
- Change all user-facing messages to English
- Add REQUIRED_PARAMS validation in Python
- Split path parameter into prefab_path and folder_path for clarity
- Improve error handling with specific exception types

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* feat: Remove list_prefabs action and update related documentation

* feat: Enhance prefab management with detailed parameter descriptions and new unlinking option

* feat: Simplify prefab creation logic and unify logging for asset replacement

* feat: Update SaveStagePrefab method to use SetDirty and SaveAssets for prefab stage saving

* feat: Add PrefabUtilityHelper class with utility methods for prefab asset management

* feat: Refactor action constants and enhance parameter validation in prefab management

* feat: Update ValidateSourceObjectForPrefab method to remove replaceExisting parameter and simplify validation logic

* fix: Fix searchInactive parameter and improve prefab management

- Fix searchInactive not working correctly for child objects
- Improve error message accuracy for object not found
- Use Application.dataPath for reliable directory path resolution

* feat: Add path validation and security checks for prefab operations

* feat: Remove pagination from GetHierarchy method and simplify prefab retrieval

* feat: Remove mode parameter from prefab management functions to simplify usage

* fix: Improve path validation and replace logic in prefab management

* feat: Enhance prefab management by adding nesting depth and parent prefab path retrieval

* fix: resolve Unknown pseudo class last-child USS warnings

Unity UI Toolkit does not support the :last-child pseudo-class. Replace
it with a .section-last class that is applied programmatically to the
last section in each .section-stack container.

Also moves the Configure All Detected Clients button to the bottom
of the Client Configuration section and makes it auto-width.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix: improve prefab stage save for automated workflows

- Add force parameter to save_open_stage for automated workflows
  where isDirty may not be correctly set
- Use PrefabUtility.SaveAsPrefabAsset for dialog-free saving
- Mark prefab stage scene dirty when modifying GameObjects in prefab mode
- Skip save when no changes and force=false (prevents false dirty flag)

The force parameter ensures reliable saving in CI/automation scenarios
where Unity dirty tracking may be inconsistent with programmatic changes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Update prefab.py

* refactor: remove unnecessary blank line before create function

* feat: add info and hierarchy commands to prefab CLI for enhanced prefab management

* feat: enhance prefab management with comprehensive CRUD tests and ensure dirty state tracking

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: David Sarno <david@lighthaus.us>
2026-01-25 16:36:29 -08:00
.claude v9 pre-release pruning (#528) 2026-01-07 18:51:51 -04:00
.github docs: change README installation examples from fixed version to beta branch 2026-01-23 01:14:54 -04:00
CustomTools/RoslynRuntimeCompilation [FEATURE] Custom Tool Fix and Add inspection window for all the tools (#414) 2025-12-07 19:38:32 -05:00
MCPForUnity feat: Prefab Feature Updates (#611) 2026-01-25 16:36:29 -08:00
Server feat: Prefab Feature Updates (#611) 2026-01-25 16:36:29 -08:00
TestProjects feat: Prefab Feature Updates (#611) 2026-01-25 16:36:29 -08:00
docs fix: improve manage_scene screenshot capture (#600) 2026-01-24 17:07:08 -05:00
scripts Improved ci prompt testing suite (#270) 2025-09-07 15:47:56 -07:00
tools docs: change README installation examples from fixed version to beta branch 2026-01-23 01:14:54 -04:00
.dockerignore HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
.gitignore feat: add test coverage tracking with pytest-cov (#512) 2026-01-08 17:32:44 -04:00
.mcpbignore feat: Add MCPB bundle for Claude Desktop installation (#580) 2026-01-22 15:46:35 -04:00
LICENSE chore: update package metadata and license to CoplayDev organization 2025-08-08 15:54:43 -04:00
README.md [FEATURE] Procedural Texture2D/Sprite Generation (#621) 2026-01-24 17:09:07 -05:00
claude_skill_unity.zip Claude Skill Example Upload (#380) 2025-12-02 00:43:22 -05:00
deploy-dev.bat [FEATURE] Camera Capture (#449) 2025-12-09 19:00:30 -05:00
docker-compose.yml HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
manifest.json chore: bump version to 9.2.0 2026-01-23 05:34:19 +00:00
mcp.json fix: Rider config path and add MCP registry manifest (#604) 2026-01-21 13:02:13 -08:00
mcp_source.py HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
prune_tool_results.py Add CLI (#606) 2026-01-21 20:53:13 -04:00
restore-dev.bat HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
test_unity_socket_framing.py Autoformat (#297) 2025-09-30 16:25:33 -04:00

README.md

MCP for Unity
English 简体中文

Proudly sponsored and maintained by Coplay -- the best AI assistant for Unity.

Discord Unity Asset Store python

Create your Unity apps with LLMs! MCP for Unity bridges AI assistants (Claude, Cursor, VS Code, etc.) with your Unity Editor via the Model Context Protocol. Give your LLM the tools to manage assets, control scenes, edit scripts, and automate tasks.

MCP for Unity building a scene

Quick Start

Prerequisites

1. Install the Unity Package

In Unity: Window > Package Manager > + > Add package from git URL...

[!TIP]

https://github.com/CoplayDev/unity-mcp.git?path=/MCPForUnity

Want the latest beta? Use the beta branch:

https://github.com/CoplayDev/unity-mcp.git?path=/MCPForUnity#beta
Other install options (Asset Store, OpenUPM)

Unity Asset Store:

  1. Visit MCP for Unity on the Asset Store
  2. Click Add to My Assets, then import via Window > Package Manager

OpenUPM:

openupm add com.coplaydev.unity-mcp

2. Start the Server & Connect

  1. In Unity: Window > MCP for Unity
  2. Click Start Server (launches HTTP server on localhost:8080)
  3. Select your MCP Client from the dropdown and click Configure
  4. Look for 🟢 "Connected ✓"
  5. Connect your client: Some clients (Cursor, Windsurf, Antigravity) require enabling an MCP toggle in settings, while others (Claude Desktop, Claude Code) auto-connect after configuration.

That's it! Try a prompt like: "Create a red, blue and yellow cube" or "Build a simple player controller"


Features & Tools

Key Features

  • Natural Language Control — Instruct your LLM to perform Unity tasks
  • Powerful Tools — Manage assets, scenes, materials, scripts, and editor functions
  • Automation — Automate repetitive Unity workflows
  • Extensible — Works with various MCP Clients

Available Tools

manage_assetmanage_editormanage_gameobjectmanage_componentsmanage_materialmanage_prefabsmanage_scenemanage_scriptmanage_scriptable_objectmanage_shadermanage_vfxmanage_texturebatch_executefind_gameobjectsfind_in_fileread_consolerefresh_unityrun_testsget_test_jobexecute_menu_itemapply_text_editsscript_apply_editsvalidate_scriptcreate_scriptdelete_scriptget_sha

Available Resources

custom_toolsunity_instancesmenu_itemsget_testsgameobjectgameobject_componentseditor_stateeditor_selectioneditor_prefab_stageproject_infoproject_tagsproject_layers

Performance Tip: Use batch_execute for multiple operations — it's 10-100x faster than individual calls!

Manual Configuration

If auto-setup doesn't work, add this to your MCP client's config file:

HTTP (default — works with Claude Desktop, Cursor, Windsurf):

{
  "mcpServers": {
    "unityMCP": {
      "url": "http://localhost:8080/mcp"
    }
  }
}

VS Code:

{
  "servers": {
    "unityMCP": {
      "type": "http",
      "url": "http://localhost:8080/mcp"
    }
  }
}
Stdio configuration (legacy)

macOS/Linux:

{
  "mcpServers": {
    "unityMCP": {
      "command": "uv",
      "args": ["run", "--directory", "/Users/YOUR_USERNAME/Library/AppSupport/UnityMCP/UnityMcpServer/src", "server.py", "--transport", "stdio"]
    }
  }
}

Windows:

{
  "mcpServers": {
    "unityMCP": {
      "command": "C:/Users/YOUR_USERNAME/AppData/Local/Microsoft/WinGet/Links/uv.exe",
      "args": ["run", "--directory", "C:/Users/YOUR_USERNAME/AppData/Local/UnityMCP/UnityMcpServer/src", "server.py", "--transport", "stdio"]
    }
  }
}
Multiple Unity Instances

MCP for Unity supports multiple Unity Editor instances. To target a specific one:

  1. Ask your LLM to check the unity_instances resource
  2. Use set_active_instance with the Name@hash (e.g., MyProject@abc123)
  3. All subsequent tools route to that instance
Roslyn Script Validation (Advanced)

For Strict validation that catches undefined namespaces, types, and methods:

  1. Install NuGetForUnity
  2. Window > NuGet Package Manager → Install Microsoft.CodeAnalysis v4.14.0
  3. Also install SQLitePCLRaw.core and SQLitePCLRaw.bundle_e_sqlite3
  4. Add USE_ROSLYN to Player Settings > Scripting Define Symbols
  5. Restart Unity
Manual DLL installation (if NuGetForUnity isn't available)
  1. Download Microsoft.CodeAnalysis.CSharp.dll and dependencies from NuGet
  2. Place DLLs in Assets/Plugins/ folder
  3. Ensure .NET compatibility settings are correct
  4. Add USE_ROSLYN to Scripting Define Symbols
  5. Restart Unity
Troubleshooting
  • Unity Bridge Not Connecting: Check Window > MCP for Unity status, restart Unity
  • Server Not Starting: Verify uv --version works, check the terminal for errors
  • Client Not Connecting: Ensure the HTTP server is running and the URL matches your config

Detailed setup guides:

Still stuck? Open an Issue or Join Discord

Contributing

See README-DEV.md for development setup. For custom tools, see CUSTOM_TOOLS.md.

  1. Fork → Create issue → Branch (feature/your-idea) → Make changes → PR
Telemetry & Privacy

Anonymous, privacy-focused telemetry (no code, no project names, no personal data). Opt out with DISABLE_TELEMETRY=true. See TELEMETRY.md.


License: MIT — See LICENSE | Need help? Discord | Issues


Star History

Star History Chart

Citation for Research If you are working on research that is related to Unity-MCP, please cite us!
@inproceedings{10.1145/3757376.3771417,
author = {Wu, Shutong and Barnett, Justin P.},
title = {MCP-Unity: Protocol-Driven Framework for Interactive 3D Authoring},
year = {2025},
isbn = {9798400721366},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
url = {https://doi.org/10.1145/3757376.3771417},
doi = {10.1145/3757376.3771417},
series = {SA Technical Communications '25}
}

Unity AI Tools by Coplay

Coplay offers 3 AI tools for Unity:

  • MCP for Unity is available freely under the MIT license.
  • Coplay is a premium Unity AI assistant that sits within Unity and is more than the MCP for Unity.
  • Coplay MCP a free-for-now MCP for Coplay tools.

(These tools have different tech stacks. See this blog post comparing Coplay to MCP for Unity.)

Coplay

Disclaimer

This project is a free and open-source tool for the Unity Editor, and is not affiliated with Unity Technologies.