Unity MCP Server logo

Unity MCP Server

by GrandMasterK414

The Unity MCP Server bridges AI assistants with Unity projects, offering tools to interact with the Unity engine in batch mode. It enables AI to read files, parse scenes, analyze code, run tests, and generate scripts.

View on GitHub

Last updated: N/A

Unity MCP Server

A Model Context Protocol (MCP) server for Unity game development, enabling AI assistants to interact with Unity projects through a set of specialized tools.

Overview

The Unity MCP Server provides a bridge between AI assistants (like Cursor AI or Claude) and Unity projects. It offers tools for:

  • Reading and searching files in Unity projects
  • Parsing Unity scenes and prefabs
  • Analyzing C# code and detecting errors
  • Running automated tests in batch mode
  • Generating scripts from templates
  • Validating shaders
  • And more...

The server is designed to run with Unity in batch mode, allowing for operations that require the Unity engine without needing the Editor GUI.

Installation

Prerequisites

  • Node.js 16+
  • Unity 2022.3 LTS or newer (recommended)

Setup

  1. Clone this repository:

    git clone https://github.com/GrandMasterK414/unity-smithery-mcp.git
    cd unity-smithery-mcp
    
  2. Install dependencies:

    npm install
    
  3. Build the project:

    npm run build
    

Configuration

The server uses the config package for configuration. Edit config/default.json to adjust settings:

{
  "server": {
    "port": 3000,
    "host": "0.0.0.0"
  },
  "unity": {
    "unityPath": "/path/to/Unity/Editor/Unity",
    "projectPath": "/path/to/your/unity/project",
    "timeoutMs": 60000,
    "batchMode": true
  },
  "logging": {
    "level": "info",
    "file": "logs/mcp-server.log",
    "maxSize": 5242880,
    "maxFiles": 5
  },
  "security": {
    "allowedPaths": ["Assets", "ProjectSettings", "Packages"],
    "disallowedCommands": ["rm", "del", "format", "shutdown"]
  }
}

Usage

Starting the Server

npm start

To run in Smithery mode:

npm run smithery:start

Using with AI Assistants

This server is primarily designed to work with AI assistants through tools defined in the MCP specification. For Cursor or Smithery.ai integration, follow their documentation to connect to this MCP server.

Available Tools

| Tool Name | Description | |-----------|-------------| | open_file | Reads the contents of a file in the Unity project | | search_files | Searches for text patterns in project files | | list_assets | Lists project assets of a certain type or in a folder | | get_project_info | Gets high-level information about the Unity project | | parse_scene | Parses a Unity scene file to extract game objects hierarchy | | parse_prefab | Parses a Unity prefab file to extract components | | find_in_scenes | Finds scenes containing a specific GameObject or component | | analyze_cs_code | Compiles C# code to find compiler errors | | find_references | Finds references to a C# class or method | | generate_script | Creates a new C# script file from a template | | validate_shader | Compiles a shader and reports errors | | inspect_yaml | Inspects a YAML asset file | | run_tests | Runs Unity's automated tests in batch mode | | simulate_playmode | Experimental - runs a scene in play mode for a short duration |

Docker Support

A Dockerfile is included for containerized deployment. Build the Docker image:

docker build -t unity-mcp-server .

Run the container:

docker run -p 3000:3000 -v /path/to/unity/project:/project unity-mcp-server

Smithery.ai Integration

This server can be deployed on Smithery.ai using the provided smithery.yaml configuration.

License

MIT

Contributing

Contributions are welcome! Please open an issue or submit a pull request.