unity-mcp/Server
Marcus Sanatan 2649d9c379
Move Get commands to editor resources + Run Python tests every update (#368)
* Add a function to reload the domain

Closes #357

* feat: restructure server instructions into workflow-focused format

- Reorganized instructions from flat bullet list into categorized workflow sections
- Emphasized critical script management workflow with numbered steps
- Improved readability and scannability for AI agents using the MCP server

It doesn't make sense to repeat the fucnction tools, they're already parsed

* docs: reorder tool list alphabetically in README + add reload_domain tool

* feat: add Unity editor state and project info resources

- Implemented resources for querying active tool, editor state, prefab stage, selection, and open windows
- Added project configuration resources for layers and project metadata
- Organized new resources into Editor and Project namespaces for better structure

* feat: clarify script management workflow in system prompt

- Expanded guidance to include scripts created by any tool, not just manage_script
- Added "etc" to tools examples for better clarity

* refactor: remove reload_domain tool and update script management workflow

- Removed reload_domain tool as Unity automatically recompiles scripts when modified
- Updated script management instructions to rely on editor_state polling and console checking instead of manual domain reload
- Simplified workflow by removing unnecessary manual recompilation step

* Change name of menu items resource as the LLM seems it

* refactor: reorganize tests into src/tests/integration directory

- Moved all test files from root tests/ to MCPForUnity/UnityMcpServer~/src/tests/integration/ for better organization
- Added conftest.py with telemetry and dependency stubs to simplify test setup
- Removed redundant path manipulation and module loading code from individual test files

* feat: expand Unity test workflow triggers

- Run tests on all branches instead of only main
- Add pull request trigger to catch issues before merge
- Maintain path filtering to run only when relevant files change

* chore: add GitHub Actions workflow for Python tests

- Configured automated testing on push and pull requests using pytest
- Set up uv for dependency management and Python 3.10 environment
- Added test results artifact upload for debugging failed runs

* refactor: update import path for fastmcp Context

* docs: update development setup instructions to use uv

- Changed installation commands from pip to uv pip for better dependency management
- Updated test running instructions to use uv run pytest
- Added examples for running integration and unit tests separately

* Formatting [skip ci]

* refactor: optimize CI workflow with path filters and dependency installation

- Added path filters to only trigger tests when Python source or workflow files change
- Split dependency installation into sync and dev install steps for better clarity
- Fixed YAML indentation for improved readability

* Update .github/workflows/python-tests.yml

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fix: standardize test mode values to match Unity's naming convention

- Changed default mode from "edit" to "EditMode" in C# code
- Updated Python tool to use "EditMode" and "PlayMode" instead of lowercase variants

* refactor: convert test imports to relative imports

- Changed absolute imports to relative imports in integration tests for better package structure
- Removed test packages from pyproject.toml package list

* refactor: use Field with default_factory for mutable default in TagsResponse

* refactor: remove duplicate PrefabStageUtility call

* Update this as well [skip ci]

* Update MCPForUnity/UnityMcpServer~/src/tests/integration/test_script_tools.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* chore: remove pull_request triggers from test workflows [skip ci]

It's already covered by pushes

* refactor: update resource function return types to include MCPResponse union

* refactor: remove manual domain reload tool

- Removed reload_domain tool as Unity handles script recompilation automatically
- Updated documentation to reflect automatic compilation workflow
- Simplified script management workflow instructions in server description

* refactor: add context support to resource handlers

- Updated all resource handlers to accept Context parameter for Unity instance routing
- Replaced direct async_send_command_with_retry calls with async_send_with_unity_instance wrapper
- Added imports for get_unity_instance_from_context and async_send_with_unity_instance helpers

* fix: correct grammar in menu items documentation

* docs: update README with expanded tools and resources documentation

- Added new tools: manage_prefabs, create_script, delete_script, get_sha
- Added new resources: editor state, windows, project info, layers, and tags
- Clarified manage_script as compatibility router with recommendation to use newer edit tools
- Fixed run_test to run_tests for consistency

* refactor: convert unity_instances function to async [skip ci]

- Changed function signature from synchronous to async
- Added await keywords to ctx.info() and ctx.error() calls to properly handle async context methods

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-11-05 16:06:48 -04:00
..
registry Copy the MCP server to the top level (#354) 2025-10-25 00:53:53 -04:00
resources Move Get commands to editor resources + Run Python tests every update (#368) 2025-11-05 16:06:48 -04:00
tools Move Get commands to editor resources + Run Python tests every update (#368) 2025-11-05 16:06:48 -04:00
Dockerfile Copy the MCP server to the top level (#354) 2025-10-25 00:53:53 -04:00
README.md feat: lower minimum Python requirement to 3.10+ (#362) 2025-10-31 15:44:10 -04:00
__init__.py Copy the MCP server to the top level (#354) 2025-10-25 00:53:53 -04:00
config.py Copy the MCP server to the top level (#354) 2025-10-25 00:53:53 -04:00
models.py Feature/session based instance routing (#369) 2025-11-05 09:43:36 -08:00
module_discovery.py Copy the MCP server to the top level (#354) 2025-10-25 00:53:53 -04:00
port_discovery.py Feature/session based instance routing (#369) 2025-11-05 09:43:36 -08:00
pyproject.toml Feature/session based instance routing (#369) 2025-11-05 09:43:36 -08:00
pyrightconfig.json Copy the MCP server to the top level (#354) 2025-10-25 00:53:53 -04:00
reload_sentinel.py Copy the MCP server to the top level (#354) 2025-10-25 00:53:53 -04:00
server.py Move Get commands to editor resources + Run Python tests every update (#368) 2025-11-05 16:06:48 -04:00
server_version.txt Copy the MCP server to the top level (#354) 2025-10-25 00:53:53 -04:00
telemetry.py Copy the MCP server to the top level (#354) 2025-10-25 00:53:53 -04:00
telemetry_decorator.py Copy the MCP server to the top level (#354) 2025-10-25 00:53:53 -04:00
test_telemetry.py Revert "Server: Robust shutdown on stdio detach (signals, stdin/parent monitor, forced exit) (#363)" (#364) 2025-11-01 09:17:04 -07:00
unity_connection.py Feature/session based instance routing (#369) 2025-11-05 09:43:36 -08:00
unity_instance_middleware.py Feature/session based instance routing (#369) 2025-11-05 09:43:36 -08:00
uv.lock feat: lower minimum Python requirement to 3.10+ (#362) 2025-10-31 15:44:10 -04:00

README.md

MCP for Unity Server

MCP python License Discord

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.


Installation

Run directly from GitHub without installation:

uvx --from git+https://github.com/CoplayDev/unity-mcp@v6.3.0#subdirectory=Server mcp-for-unity

MCP Client Configuration:

{
  "mcpServers": {
    "UnityMCP": {
      "command": "uvx",
      "args": [
        "--from",
        "git+https://github.com/CoplayDev/unity-mcp@v6.3.0#subdirectory=Server",
        "mcp-for-unity"
      ]
    }
  }
}

Option 2: Using uv (Local Installation)

For local development or custom installations:

# Clone the repository
git clone https://github.com/CoplayDev/unity-mcp.git
cd unity-mcp/Server

# Run with uv
uv run server.py

MCP Client Configuration:

Windows:

{
  "mcpServers": {
    "UnityMCP": {
      "command": "uv",
      "args": [
        "run",
        "--directory",
        "C:\\path\\to\\unity-mcp\\Server",
        "server.py"
      ]
    }
  }
}

macOS/Linux:

{
  "mcpServers": {
    "UnityMCP": {
      "command": "uv",
      "args": [
        "run",
        "--directory",
        "/path/to/unity-mcp/Server",
        "server.py"
      ]
    }
  }
}

Option 3: Using Docker

docker build -t unity-mcp-server .
docker run unity-mcp-server

MCP Client Configuration:

{
  "mcpServers": {
    "UnityMCP": {
      "command": "docker",
      "args": ["run", "-i", "unity-mcp-server"]
    }
  }
}

Configuration

The server connects to Unity Editor automatically when both are running. No additional configuration needed.

Environment Variables:

  • DISABLE_TELEMETRY=true - Opt out of anonymous usage analytics
  • LOG_LEVEL=DEBUG - Enable detailed logging (default: INFO)

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:

📖 Full Documentation


Requirements

  • Python: 3.11 or newer
  • Unity Editor: 2021.3 LTS or newer
  • uv: Python package manager (Installation Guide)

License

MIT License - See LICENSE