mcp-server-unity
Enables AI assistants like Claude to interact with Unity projects programmatically, supporting project management, asset creation, and build automation.
README
Unity MCP Server
A Model Context Protocol (MCP) server that enables AI assistants like Claude to interact with Unity projects programmatically. Supports both Claude Desktop integration and HTTP API for flexible development workflows.
Features
📦 Core Features
- Project Management: Set up and manage Unity projects with automatic validation
- Asset Creation: Create scripts, materials, shaders, and scenes
- Asset Management: Read, list, and update Unity assets
- Build Automation: Multi-platform builds with custom settings
- Render Pipeline Detection: Automatic detection of Built-in, URP, or HDRP
🔧 Material Management
- Material Creation: Auto-detects render pipeline for correct shader selection
- Shader Updates: Change material shaders with GUID management
- Property Editing: Update colors, floats, textures, and vectors
- Batch Conversion: Convert multiple materials to different shaders
- Material Reading: Inspect material properties and shader information
📝 Code Management
- Script Creation: Create C# scripts with proper namespace structure
- Script Updates: Update existing scripts with full content replacement
- Code Analysis: Diff comparison, duplicate class detection
- Namespace Management: Auto-suggest and apply namespaces based on file location
- Compilation Monitoring: Real-time compilation error tracking
🛠️ Advanced Features
- Editor Extensions: Custom windows, inspectors, property drawers
- Shader Creation: Built-in, URP, HDRP, Shader Graph support
- Unity Refresh: Automatic asset database refresh with batch operations
- Diagnostics: Compilation errors, asset validation, editor log analysis
🎨 UI Toolkit Development
- UXML Creation: Create UI layouts with templates (window, document, component)
- USS Styling: Generate stylesheets with themes, utilities, and component styles
- Component System: Create complete UI components with UXML, USS, and C# controller
- File Management: Read, update, and list UXML/USS files
- UI Builder Integration: Files compatible with Unity's visual UI Builder tool
Installation
# Clone the repository
git clone https://github.com/zabaglione/unity-mcp-server.git
cd unity-mcp-server
# Install dependencies
npm install
# Build the project
npm run build
Usage Options
Option 1: Claude Desktop (MCP stdio)
Add 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/unity-mcp/build/index.js"]
}
}
}
Then use natural language in Claude Desktop:
- "Set Unity project to /path/to/project"
- "Create a 2D platformer with inventory system"
- "Generate a player controller with double jump"
Option 2: HTTP Server
- Start the HTTP server:
npm run start:http
# or specify a custom port
PORT=8080 npm run start:http
- Set up your Unity project:
curl -X POST http://localhost:3000/api/project/setup \
-H "Content-Type: application/json" \
-d '{"projectPath": "/path/to/your/unity/project"}'
- Analyze requirements with AI:
curl -X POST http://localhost:3000/api/ai/analyze \
-H "Content-Type: application/json" \
-d '{"description": "Create a 2D platformer with inventory system"}'
Documentation
- API Documentation - Complete HTTP API reference
- Available Tools - List of all MCP tools
- Critical Features - ⚠️ MUST READ: Essential features for proper Unity integration
- Documentation Index - All documentation
Key Endpoints
GET /health- Health checkGET /api-docs- API documentationPOST /api/project/setup- Configure Unity projectPOST /api/ai/analyze- Analyze requirementsPOST /api/system/player-controller- Generate player controllerPOST /api/asset/create-script- Create C# scriptsPOST /api/batch- Execute batch operations
Usage Examples
Create a Player Controller
const response = await fetch('http://localhost:3000/api/system/player-controller', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
gameType: 'platformer',
requirements: ['doubleJump', 'wallJump', 'dash']
})
});
Generate Project Structure
const response = await fetch('http://localhost:3000/api/project/create-structure', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
projectType: '2D_Platformer',
customStructure: {
folders: ['Scripts/Player', 'Scripts/Enemy', 'Scripts/UI']
}
})
});
UI Toolkit Examples
Important: Effective Prompt Patterns
For best results with UI Toolkit, use specific keywords like "UI Toolkit panel component" or mention file types (UXML, USS).
Create a Game HUD
# ✅ Recommended - Specific component type
"Create a UI Toolkit panel component named GameHUD with health bar, score display, and minimap"
# ✅ Recommended - Explicit file types
"Create GameHUD.uxml, GameHUD.uss, and GameHUDController.cs for a game HUD with health bar"
# The server will create:
# 1. GameHUD.uxml with proper layout
# 2. GameHUD.uss with styling
# 3. GameHUD.cs controller to manage the UI
Create a Settings Menu
# ✅ Recommended approach
"Create a UI Toolkit panel component named SettingsMenu with graphics, audio, and controls tabs"
# Alternative: Specify component type
"Create a form component called SettingsMenu using UI Toolkit"
# Creates:
# - SettingsMenu.uxml with tab navigation
# - SettingsMenu.uss with professional styling
# - SettingsMenu.cs with tab switching logic
Create Custom UI Components
# ✅ Specify component type for better recognition
"Create a UI Toolkit button component named CustomButton with hover effects"
# Create an inventory system
"Create a UI Toolkit panel component named InventorySystem with item slots and drag-drop support"
# Create a dialog system
"Create a UI Toolkit modal component named DialogBox with typewriter effect"
Update Existing UI
# Update UXML layout
"Update the MainMenu.uxml to add a credits button"
# Update USS styles
"Update GameTheme.uss to use a dark color scheme"
# Read UI files
"Show me the current HUD.uxml layout"
"Read the styles from GameTheme.uss"
Step-by-Step Approach (if automatic detection fails)
# Create files individually
"1. Create HUD.uxml for UI Toolkit"
"2. Create HUD.uss for styling"
"3. Create HUDController.cs for the UI logic"
UI Toolkit Troubleshooting
If UI Toolkit commands only create C# scripts instead of UXML/USS files:
- Use specific component types: "UI Toolkit panel component" works better than just "UI Toolkit"
- Name the component explicitly: "Create a UI Toolkit panel component named GameHUD"
- Mention file types: "Create GameHUD.uxml and GameHUD.uss"
- Use the step-by-step approach if automatic detection fails
Recent Updates
v2.3.0 (2025-06-13)
- Added full UI Toolkit support
- UXML/USS file creation, reading, and updating
- Complete UI component creation (UXML + USS + C#)
- Multiple UI templates (button, panel, list, form, card, modal)
- Theme system and utility styles support
Development
# Run in development mode
npm run dev
# Run tests
npm test
# Clean build
npm run clean
Configuration
Environment Variables
PORT- HTTP server port (default: 3000)UNITY_PATH- Path to Unity executable (auto-detected if not set)
Supported Platforms
- macOS
- Windows
- Linux
Unity Versions
- Unity 2021.3 LTS and newer
- Unity 6000.x (Unity 6)
Architecture
The server uses a modular service architecture:
- AI Core - Natural language processing and planning
- Service Layer - Unity project operations
- HTTP API - RESTful endpoints
- Template System - Code generation templates
Requirements
- Node.js 18.x or higher
- Unity 2021.3 LTS or newer
- npm or yarn
Contributing
See CONTRIBUTING.md for contribution guidelines.
License
MIT License - see LICENSE for details.
Acknowledgments
Built with:
- Express.js for HTTP server
- TypeScript for type safety
- Unity Editor integration
Support
For issues and feature requests, please use the GitHub issue tracker.
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_update_script- Update script contentasset_list_scripts- List all scriptsasset_create_scene- Create Unity scenesasset_create_shader- Create shaders (builtin, URP, HDRP, ShaderGraph)asset_read_shader- Read shader contentasset_update_shader- Update shader contentasset_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
Material Management
asset_create_material- Create materials with auto-detected render pipelineasset_create_material_with_shader- Create material with specific shaderasset_update_material_shader- Change material shaderasset_update_material_properties- Update material propertiesasset_read_material- Read material propertiesasset_update_material- Update entire material content (YAML)asset_clone_material- Clone material with new nameasset_batch_convert_materials- Batch convert materialsasset_list_materials- List all materials
Code Analysis
code_analyze_diff- Get detailed diff between filescode_detect_duplicates- Detect duplicate class namescode_suggest_namespace- Suggest namespace for filecode_apply_namespace- Apply namespace to script
Compilation Tools
compile_get_errors- Get compilation errors with contextcompile_get_status- Get current compilation statuscompile_install_helper- Install compilation monitoring helper
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
UI Toolkit Operations
ui_create_uxml- Create UXML layout filesui_create_uss- Create USS style filesui_update_uxml- Update existing UXML contentui_update_uss- Update existing USS contentui_read_uxml- Read UXML file contentui_read_uss- Read USS file contentui_list_uxml- List all UXML filesui_list_uss- List all USS filesui_create_component- Create complete UI component (UXML + USS + C#)
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
│ │ ├── material-service.ts # Material management
│ │ ├── code-analysis-service.ts # Code analysis tools
│ │ ├── compilation-service.ts # Compilation monitoring
│ │ ├── 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 Documentation: See tests/README.md for testing guide
-
Test Cases: Comprehensive test coverage in
tests/directory
Recent Updates
v2.2.0 (2025-06-06)
- Added shader and material update features
- Implemented temporary backup system with automatic cleanup
- Added material cloning functionality
- Enhanced shader GUID caching and lookup
- Added comprehensive read operations for shaders
v2.1.0 (2025-06-06)
- Fixed shader-material GUID reference issues
- Added meta file generation for all Unity assets
- Improved custom shader detection and lookup
- Enhanced material creation with proper shader references
- Added comprehensive debugging and logging
See CHANGELOG.md for full version history.
Known Issues and Solutions
Custom Shader References
When creating custom shaders, use the full shader name (including "Custom/" prefix) when creating materials:
# Create shader
asset_create_shader shaderName:"MyShader" shaderType:"builtin"
# Returns: Shader Name: Custom/MyShader
# Create material with that shader
asset_create_material_with_shader materialName:"MyMaterial" shaderName:"Custom/MyShader"
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.