agentleFS
CoplayDevCoplayDev/unity-mcp/CLAUDE.md

unity-mcp

CLAUDE.md15k starsChanged 11 months agoMITView on GitHub

MCP for Unity is a bridge that lets AI assistants (Claude, Cursor, Windsurf, etc.) control the Unity Editor through the Model Context Protocol (MCP). It enables AI-driven game development workflows - creating GameObjects, editing scripts, managing assets, running tests, and more. Two codebases, one system: - Server/ - Python MCP server using FastMCP - MCPForUnity/ - Unity C# Editor package The Python server has three distinct layers. These are not auto-generated from each other: MCP tools call Unity via WebSocket…

Trending

Less talk lately.about the whole repository

Dec 2025: 0 mentionsJan 2026: 4 mentionsFeb 2026: 1 mentionMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 2 mentionsJun 2026: 1 mentionJul 2026: 6 mentionsAug 2026: 4 mentionsSep 2026: 1 mentionOct 2026: 1 mentionNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the CoplayDev/unity-mcp repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about CoplayDev/unity-mcp

The biggest 5 of 24 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 24

Talked about on GitHub, Bluesky and Hacker News (24 times).

On GitHub · 21

16 more on GitHub

On Hacker News · 1

The file

Show its rules and text

We split this CLAUDE.md into the rules it gives an agent

21 rules. About 0 are common, 9 are distinctive, and 12 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈9

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 12

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Avoid premature abstraction.

    line 50
  2. Very specific:

    When removing functionality, delete it completely.

    line 53
  3. Distinctive:

    Every new feature needs tests.

    line 56
  4. Distinctive:

    Keep them smart and focused rather than "read everything" type resources.

    line 62
  5. Very specific:

    Use ToolParams for consistent parameter validation:

    line 122
  6. Distinctive:

    Always page results that could be large (hierarchies, components, search results):

    line 133
  7. Very specific:

    Use page_size and cursor parameters

    line 134
  8. Very specific:

    Use CommandRegistry.InvokeCommandAsync to call other tools from within a handler:

    line 138
  9. Very specific:

    When you touch a shim or anything else gated by #if UNITY_*_OR_NEWER, run tools/check-unity-versions.sh to compile-check across the CI …

    line 148
  10. Very specific:

    Use mcp_source.py to switch Unity package sources

    line 190
  11. Distinctive:

    Test on Windows and Mac if possible, and multiple clients (Claude Desktop and Claude Code are tricky for configuration as of this writing)

    line 191
  12. Very specific:

    Add Python MCP tool in Server/src/services/tools/manage_<domain>.py using @mcp_for_unity_tool

    line 194
  13. Very specific:

    Add Python CLI commands in Server/src/cli/commands/<domain>.py using Click

    line 195
  14. Very specific:

    Add C# implementation in MCPForUnity/Editor/Tools/Manage<Domain>.cs with [McpForUnityTool]

    line 196
  15. Very specific:

    Add Python tests in Server/tests/test_manage_<domain>.py

    line 197
  16. Very specific:

    Add Unity tests in TestProjects/UnityMCPTests/Assets/Tests/

    line 198
  17. Distinctive:

    Don't add features without tests

    line 202
  18. Distinctive:

    Don't create helper functions for one-time operations

    line 203
  19. Distinctive:

    Don't add error handling for scenarios that can't happen

    line 204
  20. Very specific:

    Don't commit to main directly - branch off beta for PRs

    line 205
  21. Distinctive:

    Don't add docstrings/comments to code you didn't change

    line 206

≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

What This Project Is

MCP for Unity is a bridge that lets AI assistants (Claude, Cursor, Windsurf, etc.) control the Unity Editor through the Model Context Protocol (MCP). It enables AI-driven game development workflows - creating GameObjects, editing scripts, managing assets, running tests, and more.

Architecture

AI Assistant (Claude/Cursor)
        ↓ MCP Protocol (stdio/HTTP)
Python Server (Server/src/)
        ↓ WebSocket + HTTP
Unity Editor Plugin (MCPForUnity/)
        ↓ Unity Editor API
Scene, Assets, Scripts

Two codebases, one system:

  • Server/ - Python MCP server using FastMCP
  • MCPForUnity/ - Unity C# Editor package

Three Layers on the Python Side

The Python server has three distinct layers. These are not auto-generated from each other:

LayerLocationFrameworkPurpose
MCP ToolsServer/src/services/tools/FastMCP (@mcp_for_unity_tool)Exposed to AI assistants via MCP protocol
CLI CommandsServer/src/cli/commands/Click (@click.command)Terminal interface for developers
ResourcesServer/src/services/resources/FastMCP (@mcp_for_unity_resource)Read-only state exposed to AI assistants

MCP tools call Unity via WebSocket (send_with_unity_instance). CLI commands call Unity via HTTP (run_command). Both route to the same C# HandleCommand methods.

Transport Modes

  • Stdio: Single-agent only. Separate Python process per client. Legacy TCP bridge to Unity. New connections stomp old ones.
  • HTTP: Multi-agent ready. Single shared Python server. WebSocket hub at /hub/plugin. Session isolation via client_id.

Code Philosophy

1. Domain Symmetry

Python MCP tools mirror C# Editor tools. Each domain exists in both:

  • Server/src/services/tools/manage_material.py ↔ MCPForUnity/Editor/Tools/ManageMaterial.cs
  • CLI commands (Server/src/cli/commands/) also mirror these but are a separate implementation.

2. Minimal Abstraction

Avoid premature abstraction. Three similar lines of code is better than a helper that's used once. Only abstract when you have 3+ genuine use cases.

3. Delete Rather Than Deprecate

When removing functionality, delete it completely. No _unused renames, no // removed comments, no backwards-compatibility shims for internal code.

4. Test Coverage Required

Every new feature needs tests. Run them before PRs.

5. Keep Tools Focused

Each MCP tool does one thing well. Resist the urge to add "convenient" parameters that bloat the API surface.

6. Use Resources for Reading

Keep them smart and focused rather than "read everything" type resources. Resources should be quick and LLM-friendly.

Key Patterns

Python MCP Tool Registration

Tools in Server/src/services/tools/ are auto-discovered. Use the @mcp_for_unity_tool decorator:

from services.registry import mcp_for_unity_tool

@mcp_for_unity_tool(
    description="Does something in Unity.",
    group="core",  # core (default), vfx, animation, ui, scripting_ext, testing, probuilder, profiling, docs, asset_gen
)
async def manage_something(
    ctx: Context,
    action: Annotated[Literal["create", "delete"], "Action to perform"],
) -> dict[str, Any]:
    unity_instance = await get_unity_instance_from_context(ctx)
    params = {"action": action}
    response = await send_with_unity_instance(async_send_command_with_retry, unity_instance, "manage_something", params)
    return response

The group parameter controls tool visibility. Only "core" is enabled by default. Non-core groups (vfx, animation, etc.) start disabled and are toggled via manage_tools.

Python CLI Error Handling

CLI commands (not MCP tools) use the @handle_unity_errors decorator:

@handle_unity_errors
async def my_command(ctx, ...):
    result = await call_unity_tool(...)

C# Tool Registration

Tools are auto-discovered by CommandRegistry via reflection. Use the [McpForUnityTool] attribute:

[McpForUnityTool("manage_something", AutoRegister = false, Group = "core")]
public static class ManageSomething
{
    // Sync handler (most tools):
    public static object HandleCommand(JObject @params)
    {
        var p = new ToolParams(@params);
        // ...
        return new SuccessResponse("Done.", new { data = result });
    }

    // OR async handler (for long-running operations like play-test, refresh, batch):
    public static async Task<object> HandleCommand(JObject @params)
    {
        // CommandRegistry detects Task return type automatically
        await SomeAsyncOperation();
        return new SuccessResponse("Done.");
    }
}

Async handlers use EditorApplication.update polling with TaskCompletionSource — see RefreshUnity.cs for the canonical pattern.

C# Parameter Handling

Use ToolParams for consistent parameter validation:

var p = new ToolParams(parameters);
var pageSize = p.GetInt("page_size", "pageSize") ?? 50;
var name = p.RequireString("name");

C# Resources

Resources use [McpForUnityResource] and follow the same HandleCommand pattern as tools. They provide read-only state to AI assistants.

Paging Large Results

Always page results that could be large (hierarchies, components, search results):

  • Use page_size and cursor parameters
  • Return next_cursor when more results exist

Composing Tools Internally (C#)

Use CommandRegistry.InvokeCommandAsync to call other tools from within a handler:

var result = await CommandRegistry.InvokeCommandAsync("read_console", consoleParams);

Unity API Compatibility Shims

We support a wide Unity version range (2021+ → 6.x → CoreCLR 6.8). When an API is renamed, deprecated, or removed across versions, don't sprinkle #if UNITY_x_y_OR_NEWER at every call site — add a shim in MCPForUnity/Runtime/Helpers/Unity*Compat.cs and route every caller through it.

The catalog of active shims, the policy for when to add one, what does NOT belong in a shim, and the reflection-cache pattern all live in MCPForUnity/Runtime/Helpers/UnityCompatShims.cs — the XML doc on that empty marker class is the source of truth and ships inside the UPM package, so end-users can F12/Go-to-definition into it. Sources for current deprecations: Unity 6.x upgrade guides and the CoreCLR 2026 thread.

When you touch a shim or anything else gated by #if UNITY_*_OR_NEWER, run tools/check-unity-versions.sh to compile-check across the CI matrix locally before committing — the matrix lives in tools/unity-versions.json.

Commands

Running Tests

# Python (all tests)
cd Server && uv run pytest tests/ -v

# Python (single test file)
cd Server && uv run pytest tests/test_manage_material.py -v

# Python (single test by name)
cd Server && uv run pytest tests/ -k "test_create_material" -v

# Unity - open TestProjects/UnityMCPTests in Unity, use Test Runner window

# Local multi-version compile check (parity with CI matrix, see tools/unity-versions.json)
tools/check-unity-versions.sh           # compile-only across installed Unity Hub editors
tools/check-unity-versions.sh --full    # full EditMode test run

# License-free Roslyn compile of MCPForUnity, the same gate compile-check.yml runs on every PR.
# No Editor launch, ~1 min per version. EXTRA_REFS must hold Newtonsoft.Json.dll and
# nunit.framework.dll (copy them from TestProjects/UnityMCPTests/Library/PackageCache);
# the script header has the full recipe, including the Windows/Git Bash form.
UNITY_DATA=/path/to/Editor/Data UNITY_VERSION=2021.3.45f2 EXTRA_REFS=/path/to/refs tools/compile-check.sh

Local headless test harness

One command boots a headless Hub-licensed Editor against TestProjects/UnityMCPTests and runs the smoke + EditMode + PlayMode legs over the bridge — the same entrypoint CI uses (.github/workflows/e2e-bridge.yml):

python tools/local_harness.py

Key flags: --legs smoke,editmode,playmode (subset to run), --project-path (target project, default TestProjects/UnityMCPTests), --reuse (attach to an already-resident bridge instead of booting one), --keep-alive (leave the Editor running after the legs), --no-warmup (skip the warm-up import phase).

Exit codes: 0 pass, 1 blocking-leg regression, 2 bridge unreachable / setup failure, 3 project does not compile, 4 no Unity license / Hub seat, 5 Editor binary/version not found. Requires a Hub-activated Editor locally (no ULF/serial).

Local Development

  1. Set Server Source Override in MCP for Unity Advanced Settings to your local Server/ path
  2. Enable Dev Mode checkbox to force fresh installs
  3. Use mcp_source.py to switch Unity package sources
  4. Test on Windows and Mac if possible, and multiple clients (Claude Desktop and Claude Code are tricky for configuration as of this writing)

Adding a New Tool

  1. Add Python MCP tool in Server/src/services/tools/manage_<domain>.py using @mcp_for_unity_tool
  2. Add Python CLI commands in Server/src/cli/commands/<domain>.py using Click
  3. Add C# implementation in MCPForUnity/Editor/Tools/Manage<Domain>.cs with [McpForUnityTool]
  4. Add Python tests in Server/tests/test_manage_<domain>.py
  5. Add Unity tests in TestProjects/UnityMCPTests/Assets/Tests/

What Not To Do

  • Don't add features without tests
  • Don't create helper functions for one-time operations
  • Don't add error handling for scenarios that can't happen
  • Don't commit to main directly - branch off beta for PRs
  • Don't add docstrings/comments to code you didn't change

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.