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.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。
mcp-server-qdrant
这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。