Go to file
dsarno cb08b0c59b
fix: Claude Code registration, thread-safety, and auto-detect beta server (#664) (#667)
* Fix Git URL in README for package installation

Updated the Git URL for adding the package to include the branch name.

* fix: Clean up Claude Code config from all scopes to prevent stale config conflicts (#664)

- Add RemoveFromAllScopes helper to remove from local/user/project scopes
- Use explicit --scope local when registering
- Update manual snippets to show multi-scope cleanup
- Handle legacy 'unityMCP' naming in all scopes

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

* fix: Make Claude Code status check thread-safe (#664)

The background thread status check was accessing main-thread-only Unity
APIs (Application.platform, EditorPrefs via HttpEndpointUtility and
AssetPathUtility), causing "GetString can only be called from main thread"
errors.

Now all main-thread-only values are captured before Task.Run() and passed
as parameters to CheckStatusWithProjectDir().

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

* fix: Persist client dropdown selection and remove dead IO code

- Remember last selected client in EditorPrefs so it restores on window
  reopen (prevents hiding config issues by defaulting to first client)
- Remove dead Outbound class, _outbox BlockingCollection, and writer
  thread that was never used (nothing ever enqueued to outbox)
- Keep only failure IO logs, remove verbose success logging

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

* feat: Auto-detect beta package to enable UseBetaServer + workflow updates

- Add IsPreReleaseVersion() helper to detect beta/alpha/rc package versions
- UseBetaServer now defaults to true only for prerelease package versions
- Main branch users get false default, beta branch users get true default
- Update beta-release.yml to set Unity package version with -beta.1 suffix
- Update release.yml to merge beta → main and strip beta suffix
- Fix CodexConfigHelperTests to explicitly set UseBetaServer for determinism
- Use EditorConfigurationCache consistently for UseBetaServer access

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

* fix: Address code review feedback for thread-safety and validation

- Add thread-safe overloads for GetBetaServerFromArgs/List that accept
  pre-captured useBetaServer and gitUrlOverride parameters
- Use EditorConfigurationCache.SetUseBetaServer() in McpAdvancedSection
  for atomic cache + EditorPrefs update
- Add semver validation guard in beta-release.yml before version arithmetic
- Add semver validation guard in release.yml after stripping prerelease suffix

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

* fix: Complete thread-safety for GetBetaServerFromArgs overloads

- Add packageSource parameter to thread-safe overloads to avoid calling
  GetMcpServerPackageSource() (which uses EditorPrefs) from background threads
- Apply quoteFromPath logic to gitUrlOverride and packageSource paths to
  handle local paths with spaces correctly

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

* fix: Patch legacy connection pool in transport tests to prevent real Unity discovery

The auto-select tests were failing because they only patched PluginHub
but not the fallback legacy connection pool discovery. When PluginHub
returns no results, the middleware falls back to discovering instances
via get_unity_connection_pool(), which found the real running Unity.

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

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 15:35:01 -08:00
.claude Large Cleanup and Refactor + Many new Tests added (#642) 2026-01-29 02:47:36 -08:00
.github fix: Claude Code registration, thread-safety, and auto-detect beta server (#664) (#667) 2026-02-02 15:35:01 -08: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 fix: Claude Code registration, thread-safety, and auto-detect beta server (#664) (#667) 2026-02-02 15:35:01 -08:00
Server fix: Claude Code registration, thread-safety, and auto-detect beta server (#664) (#667) 2026-02-02 15:35:01 -08:00
TestProjects fix: Claude Code registration, thread-safety, and auto-detect beta server (#664) (#667) 2026-02-02 15:35:01 -08:00
docs Remote server auth (#644) 2026-01-30 18:39:21 -04:00
scripts Improved ci prompt testing suite (#270) 2025-09-07 15:47:56 -07:00
tools Add manual scripts to update pypi and docker in case things go bad! 2026-01-31 09:20:57 -04:00
.dockerignore HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
.gitignore Large Cleanup and Refactor + Many new Tests added (#642) 2026-01-29 02:47:36 -08:00
.mcpbignore feat: Add MCPB bundle for Claude Desktop installation (#580) 2026-01-22 15:46:35 -04:00
CLAUDE.md Clarify resource handling guidelines in CLAUDE.md 2026-01-29 03:29:25 -08:00
LICENSE chore: update package metadata and license to CoplayDev organization 2025-08-08 15:54:43 -04:00
README.md Fix Git URL in README for MCPForUnity package 2026-02-01 08:16:17 -08: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.3.1 2026-01-31 08:56:15 -04:00
mcp_source.py Large Cleanup and Refactor + Many new Tests added (#642) 2026-01-29 02:47:36 -08: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#main

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_componentsprefab_apiprefab_infoprefab_hierarchyeditor_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 (uvx)

macOS/Linux:

{
  "mcpServers": {
    "unityMCP": {
      "command": "uvx",
      "args": ["--from", "mcpforunityserver", "mcp-for-unity", "--transport", "stdio"]
    }
  }
}

Windows:

{
  "mcpServers": {
    "unityMCP": {
      "command": "C:/Users/YOUR_USERNAME/AppData/Local/Microsoft/WinGet/Links/uvx.exe",
      "args": ["--from", "mcpforunityserver", "mcp-for-unity", "--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 v5.0
  3. Also install SQLitePCLRaw.core and SQLitePCLRaw.bundle_e_sqlite3 v3.0.2
  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.