* 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> |
||
|---|---|---|
| .. | ||
| src | ||
| tests | ||
| DOCKER_OVERVIEW.md | ||
| Dockerfile | ||
| LICENSE | ||
| README.md | ||
| __init__.py | ||
| pyproject.toml | ||
| pyrightconfig.json | ||
| uv.lock | ||
README.md
MCP for Unity Server
Model Context Protocol server for Unity Editor integration. Control Unity through natural language using AI assistants like Claude, Cursor, and more.
Maintained by Coplay - This project is not affiliated with Unity Technologies.
💬 Join our community: Discord Server
Required: Install the Unity MCP Plugin to connect Unity Editor with this MCP server. You also need uvx (requires uv) to run the server.
Installation
Option 1: PyPI
Install and run directly from PyPI using uvx.
Run Server (HTTP):
uvx --from mcpforunityserver mcp-for-unity --transport http --http-url http://localhost:8080
MCP Client Configuration (HTTP):
{
"mcpServers": {
"UnityMCP": {
"url": "http://localhost:8080/mcp"
}
}
}
MCP Client Configuration (stdio):
{
"mcpServers": {
"UnityMCP": {
"command": "uvx",
"args": [
"--from",
"mcpforunityserver",
"mcp-for-unity",
"--transport",
"stdio"
]
}
}
}
Option 2: From GitHub Source
Use this to run the latest released version from the repository. Change the version to main to run the latest unreleased changes from the repository.
{
"mcpServers": {
"UnityMCP": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/CoplayDev/unity-mcp@v9.3.1#subdirectory=Server",
"mcp-for-unity",
"--transport",
"stdio"
]
}
}
}
Option 3: Docker
Use Pre-built Image:
docker run -p 8080:8080 msanatan/mcp-for-unity-server:latest --transport http --http-url http://0.0.0.0:8080
Build Locally:
docker build -t unity-mcp-server .
docker run -p 8080:8080 unity-mcp-server --transport http --http-url http://0.0.0.0:8080
Configure your MCP client with "url": "http://localhost:8080/mcp".
Option 4: Local Development
For contributing or modifying the server code:
# Clone the repository
git clone https://github.com/CoplayDev/unity-mcp.git
cd unity-mcp/Server
# Run with uv
uv run src/main.py --transport stdio
Configuration
The server connects to Unity Editor automatically when both are running. Most users do not need to change any settings.
CLI options
These options apply to the mcp-for-unity command (whether run via uvx, Docker, or python src/main.py).
--transport {stdio,http}- Transport protocol (default:stdio)--http-url URL- Base URL used to derive host/port defaults (default:http://localhost:8080)--http-host HOST- Override HTTP bind host (overrides URL host)--http-port PORT- Override HTTP bind port (overrides URL port)--http-remote-hosted- Treat HTTP transport as remotely hosted- Requires API key authentication (see below)
- Disables local/CLI-only HTTP routes (
/api/command,/api/instances,/api/custom-tools) - Forces explicit Unity instance selection for MCP tool/resource calls
- Isolates Unity sessions per user
--api-key-validation-url URL- External endpoint to validate API keys (required when--http-remote-hostedis set)--api-key-login-url URL- URL where users can obtain/manage API keys (served by/api/auth/login-url)--api-key-cache-ttl SECONDS- Cache duration for validated keys (default:300)--api-key-service-token-header HEADER- Header name for server-to-auth-service authentication (e.g.X-Service-Token)--api-key-service-token TOKEN- Token value sent to the auth service for server authentication--default-instance INSTANCE- Default Unity instance to target (project name, hash, orName@hash)--project-scoped-tools- Keep custom tools scoped to the active Unity project and enable the custom tools resource--unity-instance-token TOKEN- Optional per-launch token set by Unity for deterministic lifecycle management--pidfile PATH- Optional path where the server writes its PID on startup (used by Unity-managed terminal launches)
Environment variables
UNITY_MCP_TRANSPORT- Transport protocol:stdioorhttpUNITY_MCP_HTTP_URL- HTTP server URL (default:http://localhost:8080)UNITY_MCP_HTTP_HOST- HTTP bind host (overrides URL host)UNITY_MCP_HTTP_PORT- HTTP bind port (overrides URL port)UNITY_MCP_HTTP_REMOTE_HOSTED- Enable remote-hosted mode (true,1, oryes)UNITY_MCP_DEFAULT_INSTANCE- Default Unity instance to target (project name, hash, orName@hash)UNITY_MCP_SKIP_STARTUP_CONNECT=1- Skip initial Unity connection attempt on startup
API key authentication (remote-hosted mode):
UNITY_MCP_API_KEY_VALIDATION_URL- External endpoint to validate API keysUNITY_MCP_API_KEY_LOGIN_URL- URL where users can obtain/manage API keysUNITY_MCP_API_KEY_CACHE_TTL- Cache TTL for validated keys in seconds (default:300)UNITY_MCP_API_KEY_SERVICE_TOKEN_HEADER- Header name for server-to-auth-service authenticationUNITY_MCP_API_KEY_SERVICE_TOKEN- Token value sent to the auth service for server authentication
Telemetry:
DISABLE_TELEMETRY=1- Disable anonymous telemetry (opt-out)UNITY_MCP_DISABLE_TELEMETRY=1- Same asDISABLE_TELEMETRYMCP_DISABLE_TELEMETRY=1- Same asDISABLE_TELEMETRYUNITY_MCP_TELEMETRY_ENDPOINT- Override telemetry endpoint URLUNITY_MCP_TELEMETRY_TIMEOUT- Override telemetry request timeout (seconds)
Examples
Stdio (default):
uvx --from mcpforunityserver mcp-for-unity --transport stdio
HTTP (local):
uvx --from mcpforunityserver mcp-for-unity --transport http --http-host 127.0.0.1 --http-port 8080
HTTP (remote-hosted with API key auth):
uvx --from mcpforunityserver mcp-for-unity \
--transport http \
--http-host 0.0.0.0 \
--http-port 8080 \
--http-remote-hosted \
--api-key-validation-url https://auth.example.com/api/validate-key \
--api-key-login-url https://app.example.com/api-keys
Disable telemetry:
DISABLE_TELEMETRY=1 uvx --from mcpforunityserver mcp-for-unity --transport stdio
Remote-Hosted Mode
When deploying the server as a shared remote service (e.g. for a team or Asset Store users), enable --http-remote-hosted to activate API key authentication and per-user session isolation.
Requirements:
- An external HTTP endpoint that validates API keys. The server POSTs
{"api_key": "..."}and expects{"valid": true, "user_id": "..."}or{"valid": false}in response. --api-key-validation-urlmust be provided (orUNITY_MCP_API_KEY_VALIDATION_URL). The server exits with code 1 if this is missing.
What changes in remote-hosted mode:
- All MCP tool/resource calls and Unity plugin WebSocket connections require a valid
X-API-Keyheader. - Each user only sees Unity instances that connected with their API key (session isolation).
- Auto-selection of a sole Unity instance is disabled; users must explicitly call
set_active_instance. - CLI REST routes (
/api/command,/api/instances,/api/custom-tools) are disabled. /healthand/api/auth/login-urlremain accessible without authentication.
MCP client config with API key:
{
"mcpServers": {
"UnityMCP": {
"url": "http://remote-server:8080/mcp",
"headers": {
"X-API-Key": "<your-api-key>"
}
}
}
}
For full details, see Remote Server Auth Guide and Architecture Reference.
MCP Resources
The server provides read-only MCP resources for querying Unity Editor state. Resources provide up-to-date information about your Unity project without modifying it.
Accessing Resources:
Resources are accessed by their URI (not their name). Always use ListMcpResources to get the correct URI format.
Example URIs:
mcpforunity://editor/state- Editor readiness snapshotmcpforunity://project/tags- All project tagsmcpforunity://scene/gameobject/{instance_id}- GameObject details by IDmcpforunity://prefab/{encoded_path}- Prefab info by asset path
Important: Resource names use underscores (e.g., editor_state) but URIs use slashes/hyphens (e.g., mcpforunity://editor/state). Always use the URI from ListMcpResources() when reading resources.
All resource descriptions now include their URI for easy reference. List available resources to see the complete catalog with URIs.
Example Prompts
Once connected, try these commands in your AI assistant:
- "Create a 3D player controller with WASD movement"
- "Add a rotating cube to the scene with a red material"
- "Create a simple platformer level with obstacles"
- "Generate a shader that creates a holographic effect"
- "List all GameObjects in the current scene"
Documentation
For complete documentation, troubleshooting, and advanced usage:
Requirements
- Python: 3.10 or newer
- Unity Editor: 2021.3 LTS or newer
- uv: Python package manager (Installation Guide)
License
MIT License - See LICENSE