This is a fork of Arodoid's UnityMCP modified to work with Cursor.
Unity MCP for Cursor is a powerful Unity Editor integration that implements the Model Context Protocol (MCP), enabling seamless interaction between Unity and Cursor AI. It provides real-time editor state monitoring, remote command execution, and comprehensive logging capabilities.
The project consists of two main components:
A Unity Editor package that provides:
- Debug window for connection status and monitoring
- WebSocket client for real-time communication
- C# code execution engine
- Comprehensive logging system
- Editor state tracking and serialization
A TypeScript-based MCP server that exposes Unity Editor functionality through standardized tools:
-
get_editor_state- Retrieves current Unity Editor state
- Includes active GameObjects, selection state, play mode status
- Provides scene hierarchy and project structure
- Supports different output formats (Raw, scripts only, no scripts)
-
execute_editor_command- Executes C# code directly in the Unity Editor
- Full access to UnityEngine and UnityEditor APIs
- Real-time execution with comprehensive error handling
- Command timeout protection
-
get_logs- Retrieves and filters Unity Editor logs
- Supports filtering by type, content, and timestamp
- Customizable output fields
- Buffer management for optimal performance
- Unity 2020.3 or later
- Node.js 18 or later
- npm 9 or later
- Cursor AI installed
There are two ways to install the Unity MCP package:
- In Unity, open Window > Package Manager
- Click the "+" button in the top-left corner
- Select "Add package from git URL..."
- Enter the repository URL:
https://github.com/amengol/UnityMCP-Cursor.git?path=/unity-mcp-package - Click "Add"
- Clone this repository:
git clone https://github.com/amengol/UnityMCP-Cursor.git
- In Unity, open Window > Package Manager
- Click the "+" button in the top-left corner
- Select "Add package from disk..."
- Navigate to the cloned repository and select the
unity-mcp-packagefolder - Click "Open"
- Clone this repository if you haven't already
- Install dependencies and build the server:
cd unity-mcp-server npm install npm run build
To set up the MCP server with Cursor:
- Create a
cursor-mcp.jsonfile in your project root (or use the provided one) - Configure it with the path to the built MCP server:
{
"mcpServers": {
"unity-mcp": {
"command": "node",
"args": ["PATH_TO_YOUR_REPO/unity-mcp-server/build/index.js"],
"env": {}
}
}
}- Replace
PATH_TO_YOUR_REPOwith your actual repository path
The server will be started automatically by Cursor when needed. You can also start it manually:
cd unity-mcp-server
node build/index.js- Open your Unity project
- Open the UnityMCP Debug Window (Window > UnityMCP > Debug Window)
- The plugin will automatically attempt to connect to the MCP server
- Monitor connection status and logs in the debug window
- Open your Unity project in the Unity Editor
- Open Cursor and navigate to your project directory
- Make sure the Unity Editor's UnityMCP Debug window is open and connected
- Use Cursor's AI features which will now have access to your Unity Editor state
You can use Cursor to send C# commands to Unity:
// 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);cd unity-mcp-server
npm run buildnpm run watchnpm run inspector- WebSocket-based communication on port 8080
- Bidirectional real-time updates
- JSON message format for all communications
- Automatic reconnection handling
- Command execution timeout protection
- Error handling and validation
- Log buffer management
- Connection state monitoring
The system provides comprehensive error handling for:
- Connection issues
- Command execution failures
- Compilation errors
- Runtime exceptions
- Timeout scenarios
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT license.
