GitHub - CoderGamester/mcp-unity: MCP Server to integrate Unity Editor game engine with different AI Model clients (e.g. Claude Desktop, Windsurf, Cursor) (original) (raw)

MCP Unity Editor (Game Engine)

smithery badge

English ๐Ÿ‡จ๐Ÿ‡ณ็ฎ€ไฝ“ไธญๆ–‡ ๐Ÿ‡ฏ๐Ÿ‡ตๆ—ฅๆœฌ่ชž
                              ,/(/.   *(/,                                  
                          */(((((/.   *((((((*.                             
                     .*((((((((((/.   *((((((((((/.                         
                 ./((((((((((((((/    *((((((((((((((/,                     
             ,/(((((((((((((/*.           */(((((((((((((/*.                
            ,%%#((/((((((*                    ,/(((((/(#&@@(                
            ,%%##%%##((((((/*.             ,/((((/(#&@@@@@@(                
            ,%%######%%##((/(((/*.    .*/(((//(%@@@@@@@@@@@(                
            ,%%####%#(%%#%%##((/((((((((//#&@@@@@@&@@@@@@@@(                
            ,%%####%(    /#%#%%%##(//(#@@@@@@@%,   #@@@@@@@(                
            ,%%####%(        *#%###%@@@@@@(        #@@@@@@@(                
            ,%%####%(           #%#%@@@@,          #@@@@@@@(                
            ,%%##%%%(           #%#%@@@@,          #@@@@@@@(                
            ,%%%#*              #%#%@@@@,             *%@@@(                
            .,      ,/##*.      #%#%@@@@,     ./&@#*      *`                
                ,/#%#####%%#/,  #%#%@@@@, ,/&@@@@@@@@@&\.                    
                 `*#########%%%%###%@@@@@@@@@@@@@@@@@@&*ยด                   
                    `*%%###########%@@@@@@@@@@@@@@&*ยด                        
                        `*%%%######%@@@@@@@@@@&*ยด                            
                            `*#%%##%@@@@@&*ยด                                 
                               `*%#%@&*ยด                                     
                                                       
     โ–ˆโ–ˆโ–ˆโ•—   โ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—         โ–ˆโ–ˆโ•—   โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ•—   โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•—   โ–ˆโ–ˆโ•—
     โ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—        โ–ˆโ–ˆโ•‘   โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘โ•šโ•โ•โ–ˆโ–ˆโ•”โ•โ•โ•โ•šโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•”โ•
     โ–ˆโ–ˆโ•”โ–ˆโ–ˆโ–ˆโ–ˆโ•”โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘     โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•        โ–ˆโ–ˆโ•‘   โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘   โ–ˆโ–ˆโ•‘    โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ• 
     โ–ˆโ–ˆโ•‘โ•šโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘     โ–ˆโ–ˆโ•”โ•โ•โ•โ•         โ–ˆโ–ˆโ•‘   โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘โ•šโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘   โ–ˆโ–ˆโ•‘     โ•šโ–ˆโ–ˆโ•”โ•  
     โ–ˆโ–ˆโ•‘ โ•šโ•โ• โ–ˆโ–ˆโ•‘โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘             โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ•‘ โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘   โ–ˆโ–ˆโ•‘      โ–ˆโ–ˆโ•‘   
     โ•šโ•โ•     โ•šโ•โ• โ•šโ•โ•โ•โ•โ•โ•โ•šโ•โ•              โ•šโ•โ•โ•โ•โ•โ• โ•šโ•โ•  โ•šโ•โ•โ•โ•โ•šโ•โ•   โ•šโ•โ•      โ•šโ•โ•   

MCP Unity is an implementation of the Model Context Protocol for Unity Editor, allowing AI assistants to interact with your Unity projects. This package provides a bridge between Unity and a Node.js server that implements the MCP protocol, enabling AI agents like Claude, Windsurf, and Cursor to execute operations within the Unity Editor.

Features

Unity MCP server

IDE Integration - Package Cache Access

MCP Unity provides automatic integration with VSCode-like IDEs (Visual Studio Code, Cursor, Windsurf) by adding the Unity Library/PackedCache folder to your workspace. This feature:

MCP Server Tools

MCP Server Resources

Requirements

Installation

Installing this MCP Unity Server is a multi-step process:

Step 1: Install Unity MCP Server package via Unity Package Manager

  1. Open the Unity Package Manager (Window > Package Manager)
  2. Click the "+" button in the top-left corner
  3. Select "Add package from git URL..."
  4. Enter: https://github.com/CoderGamester/mcp-unity.git
  5. Click "Add"

package manager

Step 2: Install Node.js

To run MCP Unity server, you'll need to have Node.js 18 or later installed on your computer:

Windows

  1. Visit the Node.js download page
  2. Download the Windows Installer (.msi) for the LTS version (recommended)
  3. Run the installer and follow the installation wizard
  4. Verify the installation by opening PowerShell and running: macOS
  5. Visit the Node.js download page
  6. Download the macOS Installer (.pkg) for the LTS version (recommended)
  7. Run the installer and follow the installation wizard
  8. Alternatively, if you have Homebrew installed, you can run:
  9. Verify the installation by opening Terminal and running:

Step 3: Configure AI LLM Client

Option 1: Configure using Unity Editor

  1. Open the Unity Editor
  2. Navigate to Tools > MCP Unity > Server Window
  3. Click on the "Configure" button for your AI LLM client as shown in the image below

image

  1. Confirm the configuration installation with the given popup

image

Option 2: Configure Manually

Open the MCP configuration file of your AI client (e.g. claude_desktop_config.json in Claude Desktop) and copy the following text:

Replace ABSOLUTE/PATH/TO with the absolute path to your MCP Unity installation or just copy the text from the Unity Editor MCP Server window (Tools > MCP Unity > Server Window).

{ "mcpServers": { "mcp-unity": { "command": "node", "args": [ "ABSOLUTE/PATH/TO/mcp-unity/Server/build/index.js" ] } } }

Start Unity Editor MCP Server

  1. Open the Unity Editor
  2. Navigate to Tools > MCP Unity > Server Window
  3. Click "Start Server" to start the WebSocket server
  4. Open Claude Desktop or your AI Coding IDE (e.g. Cursor IDE, Windsurf IDE, etc.) and start executing Unity tools

connect

When the AI client connects to the WebSocket server, it will automatically show in the green box in the window

Optional: Set WebSocket Port

By default, the WebSocket server runs on port 8090. You can change this port in two ways:

Option 1: Using the Unity Editor

  1. Open the Unity Editor
  2. Navigate to Tools > MCP Unity > Server Window
  3. Change the "WebSocket Port" value to your desired port number
  4. Unity will setup the system environment variable UNITY_PORT to the new port number
  5. Restart the Node.js server
  6. Click again on "Start Server" to reconnect the Unity Editor web socket to the Node.js MCP Server Option 2: Using the terminal
  7. Set the UNITY_PORT environment variable in the terminal
    • Powershell
    • Command Prompt/Terminal
  8. Restart the Node.js server
  9. Click again on "Start Server" to reconnect the Unity Editor web socket to the Node.js MCP Server

Optional: Set Timeout

By default, the timeout between the MCP server and the WebSocket is 10 seconds. You can change depending on the OS you are using:

Option 1: Windows OS

  1. Open the Unity Editor
  2. Navigate to Tools > MCP Unity > Server Window
  3. Change the "Request Timeout (seconds)" value to your desired timeout seconds
  4. Unity will setup the system environment variable UNITY_REQUEST_TIMEOUT to the new timeout value
  5. Restart the Node.js server
  6. Click again on "Start Server" to reconnect the Unity Editor web socket to the Node.js MCP Server Option 2: Non-Windows OS

For non-Windows OS, you need to configure two places:

In Editor Process Timeout

  1. Open the Unity Editor
  2. Navigate to Tools > MCP Unity > Server Window
  3. Change the "Request Timeout (seconds)" value to your desired timeout seconds

WebSocket Timeout

  1. Set the UNITY_REQUEST_TIMEOUT environment variable in the terminal
    • Powershell
      $env:UNITY_REQUEST_TIMEOUT = "300"
    • Command Prompt/Terminal
      set UNITY_REQUEST_TIMEOUT=300
  2. Restart the Node.js server
  3. Click again on "Start Server" to reconnect the Unity Editor web socket to the Node.js MCP Server

Tip

The timeout between your AI Coding IDE (e.g., Claude Desktop, Cursor IDE, Windsurf IDE) and the MCP Server depends on the IDE.

Debugging the Server

Building the Node.js Server

The MCP Unity server is built using Node.js . It requires to compile the TypeScript code to JavaScript in the build directory. To build the server, open a terminal and:

  1. Navigate to the Server directory:
    cd ABSOLUTE/PATH/TO/mcp-unity/Server
  2. Install dependencies:
  3. Build the server:
  4. Run the server: Debugging with MCP Inspector

Debug the server with @modelcontextprotocol/inspector:

npx @modelcontextprotocol/inspector node Server/build/index.js

npx @modelcontextprotocol/inspector node Server/build/index.js

Don't forget to shutdown the server with Ctrl + C before closing the terminal or debugging it with the MCP Inspector.

Enable Console Logs

  1. Enable logging on your terminal or into a log.txt file:
    • Powershell
      $env:LOGGING = "true"
      $env:LOGGING_FILE = "true"
    • Command Prompt/Terminal
      set LOGGING=true
      set LOGGING_FILE=true

Troubleshooting

Connection Issues

The run_tests tool returns the following response:

Error:
Connection failed: Unknown error

This error occurs because the bridge connection is lost when the domain reloads upon switching to Play Mode.
The workaround is to turn off Reload Domain in Edit > Project Settings > Editor > "Enter Play Mode Settings".

Support & Feedback

If you have any questions or need support, please open an issue on this repository.

Alternative you can reach out on:

Contributing

Contributions are welcome! Please feel free to submit a Pull Request or open an Issue with your request.

Commit your changes following the Conventional Commits format.

License

This project is under MIT License

Acknowledgements