mcp-unity
by: CoderGamester
MCP Unity Server to integrate Unity Editor game engine with different AI Model clients (e.g. Claude Desktop, Windsurf, Cursor)
📌Overview
Purpose: MCP Unity facilitates interaction between AI assistants and Unity projects by utilizing the Model Context Protocol.
Overview: MCP Unity is a package developed for the Unity Editor, allowing seamless communication between AI agents and Unity environments. It connects Unity to a Node.js server implementing the MCP protocol, enabling AI assistants to perform various operations directly within the Unity Editor.
Key Features:
-
execute_menu_item: Executes Unity menu items tagged with the MenuItem attribute, allowing AI to manipulate the editor.
-
select_object: Selects specified game objects within the Unity hierarchy, enabling targeted actions by AI agents.
-
package_manager: Manages Unity packages, including installation, removal, and updates, streamlining development workflows.
-
run_tests: Integrates with the Unity Test Runner to execute tests, improving testing efficiency for development.
-
notify_message: Displays customizable messages in the Unity Editor, enhancing communication and feedback during AI operations.
MCP Unity
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 to execute operations within the Unity Editor.
Features
MCP Unity provides the following tools:
- execute_menu_item: Executes Unity menu items.
- select_object: Selects game objects in the Unity hierarchy.
- package_manager: Manages packages in the Unity Package Manager.
- run_tests: Runs tests using the Unity Test Runner.
- notify_message: Displays messages in the Unity Editor.
MCP Unity also includes resources such as:
- get_menu_items: Retrieves available Unity menu items.
- get_hierarchy: Retrieves game objects in the Unity hierarchy.
- get_console_logs: Retrieves logs from the Unity console.
- get_packages: Retrieves information about installed packages.
- get_assets: Retrieves information about assets in the Asset Database.
- get_tests: Retrieves information about tests in the Unity Test Runner.
Requirements
- Unity 2022.3 or later
- Node.js 18 or later
- npm 9 or later
Installation
Installing via Unity Package Manager
- Open the Unity Package Manager.
- Click the "+" button and select "Add package from git URL...".
- Enter:
https://github.com/CoderGamester/mcp-unity.git
. - Click "Add".
Installing Node.js
- Visit the Node.js download page.
- Download and run the installer for your system.
- Verify installation by running:
node --version npm --version
Running the Server
Start Node.js Server
- Navigate to the
mcp-unity
package directory:cd ABSOLUTE/PATH/TO/mcp-unity
- Run the server using Node.js:
node Server/build/index.js
Start Unity Editor MCP Server
- Open the Unity Editor.
- Navigate to Tools > MCP Unity > Server Window.
- Click "Start Server".
Configure the WebSocket Port
By default, the WebSocket server runs on port 8080. You can change this via the Unity Editor or the terminal by setting the UNITY_PORT
environment variable.
Building and Debugging the Server
- Navigate to the Server directory:
cd ABSOLUTE/PATH/TO/mcp-unity/Server
- Install dependencies:
npm install
- Build the server:
npm run build
Troubleshooting
Connection Issues
- Ensure the WebSocket server is running.
- Check for firewall restrictions.
- Verify the port number.
Server Not Starting
- Check the Unity Console for errors.
- Ensure Node.js is installed correctly.
Menu Items Not Executing
- Check the menu item path and context.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request or open an Issue with your request. Commit changes following the Conventional Commits format.
License
This project is under MIT license.