>_ DevTrendsen

Language

Home

Languages

Sections

Frontend Backend Mobile DevOps AI / ML GameDev Blockchain Embedded Security
C-sharp

How to Connect Claude and Cursor Directly to Unity via MCP

https://github.com/IvanMurzak/Unity-MCP/raw/main/docs/img/promo/ai-developer-banner.jpg

Most developers are used to treating neural networks as a smart clipboard. We copy an error from the console into a chat with a model, get a fixed C# script back, and paste it into the project. But when you need to do more than just rewrite a class—when you need to place thirty prefabs in a circle, create a dozen materials, or quickly run tests directly in the editor—such ping-pong starts eating up too much time.

The Unity-MCP repository solves this routine fundamentally. The project connects Unity with popular assistants via the Model Context Protocol. This is an open standard from Anthropic that turns a language model from a passive advisor into an active executor inside your development environment.

https://github.com/IvanMurzak/Unity-MCP/blob/main/docs/img/editor/ai-game-developer-windows.png?raw=true

What Unity and MCP Can Do Together

The repository includes over 70 ready-made tools, organized into logical groups. The assistant gets access to the file structure, scene hierarchy, Roslyn compiler, and even the profiler.

You can write in Cursor or Claude Code a simple phrase: "Create three spheres stacked on top of each other and apply a golden metallic material to them." The model will call the necessary APIs on its own, create the material asset, configure the shader parameters, and add the objects to the scene.

https://github.com/IvanMurzak/Unity-MCP/blob/main/docs/img/editor/setup-skills.jpg?raw=true

Here are the main groups of operations the plugin handles:

  • Managing assets and packages via UPM
  • Manipulating GameObjects, components, and prefabs
  • Running tests in EditMode and PlayMode with report delivery back to the chat
  • Dynamic C# code execution via Roslyn without lengthy recompilation
  • Capturing screenshots from the camera or Scene View for visual result evaluation
  • Collecting performance and memory metrics through the built-in profiler

Reflection support is particularly nice. The neural network can find methods in the codebase and call them with the required arguments, even if those methods are private or located in external DLLs.

How the Server and Data Exchange Work

The architecture consists of two parts: a C# plugin for Unity and a separate MCP server that runs as a binary or Docker container. The client (for example, Claude Desktop or VS Code) communicates with the server via the stdio or HTTP protocol, and the server passes commands into the running Unity instance.

https://github.com/IvanMurzak/Unity-MCP/raw/main/docs/img/ai-connector-window.gif

Quick Start via CLI

The project includes a convenient CLI package that automates plugin installation and skill generation for models:

npm install -g unity-mcp-cli
unity-mcp-cli install-plugin ./MyUnityProject
unity-mcp-cli open ./MyUnityProject

If CLI isn't your thing, you can download a ready-made .unitypackage from GitHub releases or add the package via OpenUPM.

Note the strict path requirement. The path to your Unity project must not contain spaces, otherwise the local server will simply refuse to work.

Creating Custom Tools

The plugin is easy to extend. To give the neural network access to your game's specific logic, you just need to write a regular C# method and mark it with the AiToolType and AiTool attributes.

Any calls to the Unity API need to be wrapped in main thread execution, because incoming requests from the server arrive on a background thread:

[AiToolType]
public class LevelBuildingTools
{
    [AiTool("spawn-enemy-wave", Title = "Spawn Enemy Wave")]
    [Description("Спавнит волну врагов заданного типа в указанных координатах")]
    public string SpawnWave(
        [Description("Имя префаба врага")] string enemyType,
        [Description("Количество врагов")] int count
    )
    {
        return MainThread.Instance.Run(() =>
        {
            EnemySpawner.Instance.Spawn(enemyType, count);
            return $"Успешно заспавнено {count} врагов типа {enemyType}";
        });
    }
}

The Description attributes play a critical role. The model reads these descriptions to understand when to call the tool and what data types to pass as arguments.

Working in Runtime and Builds

Most similar integrations are limited to Editor mode. The Unity-MCP author went further and added a runtime client. You can embed the server directly into a built game to hand over NPC control to a language model.

Here's what initializing the runtime plugin in code looks like:

var mcpPlugin = UnityMcpPluginRuntime.Initialize(builder =>
    {
        builder.WithConfig(config =>
        {
            config.Host = "http://localhost:8080";
            config.Token = "your-token";
        });
        builder.WithToolsFromAssembly(Assembly.GetExecutingAssembly());
    })
    .Build();

await mcpPlugin.Connect();

The repository includes a chess bot example where all move logic is delegated to an external LLM. The model requests the current board state via an MCP Tool and sends back the next move.

Practical Scenarios

In practice, the tool shows its best results in three areas:

First, routine level and UI layout. Assembling a basic scene from a text description is many times faster than placing primitives manually.

Second, automated tests and bug finding. The model can run EditMode tests, read the stack trace of a failed test, open the source script, fix the error, and run the verification again.

Third, profiling. Memory and rendering tools deliver precise frame timing numbers directly into the model's context, which helps quickly locate bottlenecks.

Who Will Find This Project Useful Right Now

If you're working on prototypes solo or running a small indie project, Unity-MCP will save a lot of time on routine tasks. The entry barrier is minimal: install the CLI, pick your favorite code editor, and you immediately get a working assistant with access to the scene.

For enterprise teams with dozens of developers, the solution will require some care. You'll need to lock down configurations through project settings and monitor access rights if the server is deployed remotely in Docker. The repository is actively developed, uses the open Apache 2.0 license, and welcomes pull requests.

Related projects