Unity MCP server

Enables real-time interaction with Unity projects for tasks like automated level design, asset management, and debugging assistance through C# command execution and editor state retrieval.
Back to servers
Setup instructions
Provider
Arodoid
Release date
Jan 15, 2025
Language
TypeScript
Stats
453 stars

UnityMCP is a powerful Unity Editor plugin that implements the Model Context Protocol (MCP), enabling seamless integration between Unity and AI assistants. It provides real-time editor state monitoring, remote command execution, and comprehensive logging capabilities through a WebSocket connection.

Installation

Prerequisites

  • Unity 2022.3 or later
  • Node.js 18 or later
  • npm 9 or later

Installing via Smithery

The simplest way to install UnityMCP for Claude Desktop is automatically via Smithery:

npx -y @smithery/cli install @Arodoid/unitymcp --client claude

Manual Setup

Unity Plugin Setup

  1. Copy the UnityMCPPlugin folder to your Unity project's Assets directory
  2. Open Unity Editor
  3. Access the plugin through Unity's top menu bar > UnityMCP > Debug Window

MCP Server Setup

cd unity-mcp-server
npm install
npm run build

Usage

Starting the Server

To start the MCP server, run:

cd unity-mcp-server
node build/index.js

Connecting from Unity

  1. Open your Unity project
  2. Open the UnityMCP Debug Window (Window > UnityMCP > Debug Window)
  3. The plugin will automatically attempt to connect to the MCP server
  4. Monitor connection status and logs in the debug window

Available Tools

Getting Editor State

The get_editor_state tool retrieves the current Unity Editor state, including:

  • Active GameObjects
  • Selection state
  • Play mode status
  • Scene hierarchy
  • Project structure

The tool supports different output formats:

  • Raw (complete state)
  • Scripts only
  • No scripts

Executing Editor Commands

The execute_editor_command tool lets you run C# code directly in the Unity Editor with:

  • Full access to UnityEngine and UnityEditor APIs
  • Real-time execution with comprehensive error handling
  • Command timeout protection

Example Commands

// Center the selected object
Selection.activeGameObject.transform.position = Vector3.zero;

// Toggle play mode
EditorApplication.isPlaying = !EditorApplication.isPlaying;

// Create a new cube
GameObject.CreatePrimitive(PrimitiveType.Cube);

Accessing Logs

The get_logs tool retrieves and filters Unity Editor logs with options for:

  • Filtering by type, content, and timestamp
  • Customizable output fields
  • Buffer management for optimal performance

Technical Details

Communication Protocol

The system uses:

  • WebSocket-based communication on port 8080
  • Bidirectional real-time updates
  • JSON message format for all communications
  • Automatic reconnection handling

Security Features

UnityMCP implements:

  • Command execution timeout protection
  • Error handling and validation
  • Log buffer management
  • Connection state monitoring

Error Handling

The system provides comprehensive error handling for:

  • Connection issues
  • Command execution failures
  • Compilation errors
  • Runtime exceptions
  • Timeout scenarios

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "unitymcp" '{"command":"npx","args":["-y","@smithery/cli","install","@Arodoid/unitymcp","--client","claude"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "unitymcp": {
            "command": "npx",
            "args": [
                "-y",
                "@smithery/cli",
                "install",
                "@Arodoid/unitymcp",
                "--client",
                "claude"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "unitymcp": {
            "command": "npx",
            "args": [
                "-y",
                "@smithery/cli",
                "install",
                "@Arodoid/unitymcp",
                "--client",
                "claude"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later