MCP Server for Unity
A Model Context Protocol server that enables Claude to interact directly with Unity projects, providing tools for script creation, asset management, and project building.
README
MCP Server for Unity
A Model Context Protocol (MCP) server that enables Claude to interact directly with Unity projects, providing tools for script creation, asset management, and project building.
Features
Core Functionality
- Project Management: Set and validate Unity project paths
- Script Operations: Create, read, and list C# scripts with folder organization
- Asset Creation: Generate Unity scenes, materials, and prefabs
- Asset Management: List and filter project assets by type
- Project Information: Get Unity version and project statistics
Advanced Features
- Shader Support: Create shaders for Built-in, URP, and HDRP render pipelines
- Shader Graph: Generate visual shader graphs for URP and HDRP
- Editor Extensions: Create custom editor windows, inspectors, property drawers, and menu items
- ProBuilder Integration: Create 3D models and procedural meshes with ProBuilder API
- Runtime Mesh Generation: Generate and modify meshes dynamically at runtime
Automation & Efficiency
- Automatic Unity Refresh: Trigger asset database refresh and script recompilation
- Batch Operations: Queue multiple file operations for efficient single refresh
- Build Automation: Build Unity projects from command line for multiple platforms
- Package Management: Search, install, and remove Unity packages with smart search
- File System Watcher: Real-time monitoring for automatic Unity synchronization
Architecture Benefits
- Service-Oriented Architecture: Modular design for easy extension and maintenance
- Dependency Injection: Flexible service composition and testing
- Comprehensive Validation: Path traversal protection and input sanitization
- Template System: Consistent code generation with customizable templates
- Error Handling: Detailed error messages with recovery suggestions
Requirements
- Node.js 18.x or higher
- Unity 2021.3 LTS or newer (for build functionality)
- Claude Desktop
Installation
Quick Setup (Unix/Linux/macOS)
git clone https://github.com/zabaglione/mcp-server-unity.git
cd mcp-server-unity
./setup.sh
Manual Setup
- Clone the repository:
git clone https://github.com/zabaglione/mcp-server-unity.git
cd mcp-server-unity
- Install dependencies:
npm install
- Build the project:
npm run build
Configuration
Add the following to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"mcp-server-unity": {
"command": "node",
"args": ["/absolute/path/to/mcp-server-unity/build/index.js"]
}
}
}
Replace /absolute/path/to/mcp-server-unity with the actual path to your installation.
Usage Examples
Claude Desktop can understand natural language requests and convert them to the appropriate MCP tool commands. Here are some examples:
Project Setup
"Set Unity project to /Users/me/MyGame"
"Use my Unity project at /path/to/project"
"Initialize Unity project path: /Users/john/UnityProjects/MyAwesomeGame"
Creating Scripts
"Create a PlayerController script with basic movement"
"Make a new C# script called EnemyAI in the Enemies folder"
"Generate a GameManager singleton script"
Reading Scripts
"Show me the PlayerController script"
"Read the GameManager.cs file"
"What's in the EnemyAI script?"
Creating Assets
"Create a new scene called MainMenu"
"Make a material named PlayerMaterial"
"Create a URP shader called WaterShader"
"Generate a Shader Graph for HDRP called CustomLit"
Package Management
"Search for ProBuilder packages"
"What 2D packages are available?"
"Find packages for render pipelines"
"Install ProBuilder"
"Install TextMeshPro version 3.0.6"
"Remove ProBuilder package"
"Show installed packages"
"Install ProBuilder, TextMeshPro, and Cinemachine all at once"
Editor Extensions
"Create a custom editor window for level design"
"Make a custom inspector for MyComponent"
"Generate a property drawer for RangeAttribute"
ProBuilder Operations
"Create a ProBuilder cube prefab"
"Generate a mesh generator script"
"Make a ProBuilder shape creator"
Build Operations
"Build the project for Windows"
"Create a macOS build in /Users/me/Builds"
"Build for WebGL to /path/to/output"
Utility Operations
"List all scripts in the project"
"Show all shaders"
"Get project information"
"Refresh Unity"
"Start batch operations"
Tool Reference
For direct tool usage, here are the available MCP tools:
Project Management
project_setup_path- Set Unity project pathproject_read_info- Get project information
Asset Creation & Management
asset_create_script- Create C# scriptsasset_read_script- Read script contentsasset_list_scripts- List all scriptsasset_create_scene- Create Unity scenesasset_create_material- Create materialsasset_create_shader- Create shadersasset_list_shaders- List all shadersasset_list_all- List all assets by type
Editor Extensions
editor_create_script- Create editor scriptseditor_list_scripts- List editor scripts
ProBuilder/Modeling
modeling_create_script- Create ProBuilder scriptsmodeling_create_prefab- Create ProBuilder prefabsmodeling_list_scripts- List ProBuilder scripts
Package Management
package_search- Search for packagespackage_install- Install a packagepackage_install_multiple- Install multiple packagespackage_remove- Remove a packagepackage_list- List installed packages
Build Operations
build_execute_project- Build Unity project
System Operations
system_setup_refresh- Setup Unity refresh handlersystem_refresh_assets- Refresh Unity assetssystem_batch_start- Start batch modesystem_batch_end- End batch mode
Supported Build Targets
- StandaloneWindows64
- StandaloneOSX
- StandaloneLinux64
- iOS
- Android
- WebGL
Development
Scripts
npm run build- Build the TypeScript projectnpm run dev- Watch mode for developmentnpm start- Run the built servernpm run clean- Clean build directorynpm run test- Run automated tests (when implemented)npm run test:manual- Instructions for manual testing
Project Structure
mcp-server-unity/
├── src/
│ ├── server.ts # Main server implementation
│ ├── config/ # Configuration files
│ ├── services/ # Service layer (modular architecture)
│ │ ├── project-service.ts # Unity project management
│ │ ├── script-service.ts # Script operations
│ │ ├── asset-service.ts # Asset creation
│ │ ├── shader-service.ts # Shader management
│ │ ├── editor-script-service.ts # Editor extensions
│ │ ├── probuilder-service.ts # ProBuilder integration
│ │ ├── package-service.ts # Package management
│ │ ├── build-service.ts # Build automation
│ │ └── unity-refresh-service.ts # Unity refresh system
│ ├── templates/ # Code generation templates
│ ├── types/ # TypeScript type definitions
│ ├── utils/ # Utility functions
│ └── validators/ # Input validation
├── tests/
│ ├── comprehensive-test.js # Full feature test suite
│ ├── integration-test.js # Integration tests
│ └── run-manual-tests.sh # Manual test runner
├── build/ # Compiled output (gitignored)
├── package.json # Project configuration
├── tsconfig.json # TypeScript configuration
├── setup.sh # Setup script
└── REGRESSION_TEST_CASES.md # Detailed test documentation
Troubleshooting
Unity project not recognized
- Ensure the project path contains both
AssetsandProjectSettingsfolders - Check file permissions
Build command fails
- Verify Unity is installed at the expected location
- For custom Unity installations, modify the Unity path in your fork
Script not found
- Scripts are searched recursively from the Assets folder
- Ensure the file has a .cs extension
Testing
The project includes comprehensive test cases with 100% feature coverage:
Comprehensive Test Suite
# Run all feature tests (38 test cases)
node tests/comprehensive-test.js /path/to/unity/project
# Example
node tests/comprehensive-test.js /Users/me/Unity/MyProject
Automated Integration Tests
# Run integration tests with your Unity project
npm run test:integration /path/to/unity/project
# Example
npm run test:integration /Users/me/Unity/MyProject
Manual Testing
# Run guided manual tests
./tests/run-manual-tests.sh /path/to/unity/project
Test Coverage
-
38 automated test cases covering all features
-
10 test categories: Project, Scripts, Assets, Shaders, Editor, ProBuilder, Packages, Refresh, Build, Errors
-
Automatic cleanup after test execution
-
Performance metrics for each test
-
Test Cases: See REGRESSION_TEST_CASES.md for detailed test cases
-
Test Framework: Integration tests in
tests/integration-test.js
Contributing
See CONTRIBUTING.md for development setup and contribution guidelines.
Repository
Recommended repository name: mcp-server-unity
This follows the MCP ecosystem naming convention where MCP servers are prefixed with mcp-server-.
License
MIT License - see LICENSE file for details.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.