UnityAutonomousMCP
A comprehensive autonomous agent framework for Unity 2022.3.22f1 combining Model Context Protocol with AI decision-making, enabling intelligent task planning, editor automation, and multi-agent coordination.
README
Unity Autonomous Agent MCP
🤖 A comprehensive autonomous agent framework for Unity 2022.3.22f1 that combines the power of Model Context Protocol (MCP) with advanced AI decision-making capabilities.
🌟 Key Features
🧠 Autonomous Agent Capabilities
- Intelligent Task Planning: AI-driven task decomposition and execution planning
- Decision Making: Context-aware decision trees with learning capabilities
- Self-Improvement: Continuous learning from user interactions and outcomes
- Multi-Agent Coordination: Support for multiple autonomous agents working together
🎮 Unity Integration
- Full Editor Control: Complete Unity Editor automation and manipulation
- Runtime AI: In-game autonomous NPC behavior and debugging
- Asset Management: Intelligent asset creation, optimization, and organization
- Scene Management: Automated scene setup, optimization, and testing
🔧 Advanced MCP Features
- Extensible Architecture: Plugin-based system for custom tools and handlers
- Real-time Communication: Low-latency TCP/IP communication with external AI services
- Multi-Provider Support: Compatible with Claude, GPT, Gemini, and custom LLM providers
- Resource Management: Intelligent resource allocation and optimization
🏗️ Architecture Overview
┌─────────────────────────────────────────────────────────────┐
│ Unity Autonomous Agent MCP │
├─────────────────────────────────────────────────────────────┤
│ ┌─────────────────┐ ┌─────────────────┐ ┌──────────────┐ │
│ │ Agent Core │ │ Task Planner │ │ Decision │ │
│ │ │ │ │ │ Engine │ │
│ │ - State Mgmt │ │ - Task Decomp │ │ - ML Models │ │
│ │ - Learning │ │ - Priority │ │ - Context │ │
│ │ - Memory │ │ - Scheduling │ │ - Reasoning │ │
│ └─────────────────┘ └─────────────────┘ └──────────────┘ │
├─────────────────────────────────────────────────────────────┤
│ ┌─────────────────┐ ┌─────────────────┐ ┌──────────────┐ │
│ │ MCP Server │ │ Unity Bridge │ │ Plugin │ │
│ │ │ │ │ │ System │ │
│ │ - Protocol │ │ - Editor API │ │ - Custom │ │
│ │ - Handlers │ │ - Runtime API │ │ Tools │ │
│ │ - Transport │ │ - Asset Mgmt │ │ - Extensions │ │
│ └─────────────────┘ └─────────────────┘ └──────────────┘ │
├─────────────────────────────────────────────────────────────┤
│ Unity Engine (2022.3.22f1) │
└─────────────────────────────────────────────────────────────┘
📋 Requirements
- Unity 2022.3.22f1 or later (tested up to Unity 6.1)
- .NET/C# 9.0
- Node.js 18.0.0+ with npm (for TypeScript server)
- Python 3.8+ (for ML/AI components)
- External LLM Provider (Claude, OpenAI, Gemini, or custom)
🚀 Quick Start
Re-analysis details and capability gaps are documented in
docs/capability-matrix.md.
1. Installation
# Clone the repository
git clone https://github.com/KinofSin/UnityAutonomousMCP.git
cd UnityAutonomousMCP
# Install Unity Package
# In Unity Editor: Window > Package Manager > Add package from git URL
# Enter: file:///path/to/UnityAutonomousMCP/com.autonomous-unity.mcp
2. Setup TypeScript Server
npm install
npm run build
npm run smoke
npm run smoke validates planner + executor behavior (including run_tests -> get_test_job polling) for both successful and failed test-job terminal paths, without requiring a live Unity Editor.
3. Run modes
# Autonomous bootstrap (local dry-run using mock Unity bridge)
npm run dev -- -- "inspect scene and update scripts"
# MCP stdio mode (for Claude/Cursor/Windsurf MCP client config)
npm run dev -- --mcp
# Force mock bridge explicitly
npm run dev -- --mock -- "inspect scene and update scripts"
4. Transport bridge configuration (real Unity connection)
Unity package host (inside Unity Editor) serves both transports:
- HTTP endpoint:
POST /mcp/toolonUNITY_HTTP_PORT(default8080) - TCP endpoint: newline-delimited JSON on
UNITY_TCP_PORT(default8081)
Node-side bridge environment variables:
UNITY_TRANSPORT=http # http | tcp | mock
UNITY_HOST=127.0.0.1
UNITY_HTTP_PORT=8080
UNITY_TCP_PORT=8081
UNITY_TIMEOUT_MS=10000
UNITY_TEST_POLL_ATTEMPTS=30
UNITY_TEST_POLL_INTERVAL_MS=1000
UNITY_TEST_POLL_TIMEOUT_MS=120000
5. Configure Claude Desktop
{
"mcpServers": {
"unity-autonomous-agent": {
"command": "node",
"args": ["path/to/server/dist/index.js"],
"env": {
"UNITY_HOST": "localhost",
"UNITY_TRANSPORT": "http",
"UNITY_HTTP_PORT": "8080",
"UNITY_TCP_PORT": "8081",
"AI_PROVIDER": "anthropic",
"AI_API_KEY": "your-api-key"
}
}
}
}
6. Start Using
- Open Unity Project
- Navigate to
Edit > Preferences > Autonomous Agent MCP - Configure host + HTTP/TCP ports
- Click "Connect" to start Unity transport host
- Start MCP server (
npm run dev -- --mcp) - Begin interacting with AI through your preferred MCP client
✅ Current implementation status (this repo)
- Capability matrix + gap analysis:
docs/capability-matrix.md - Autonomous planner core:
server/src/planner.ts - Policy guardrails:
server/src/policy.ts - Plan executor:
server/src/executor.ts - MCP server tools (
autonomous_plan,unity_tool_call,list_capabilities):server/src/mcpServer.ts - Real Unity bridge transports (HTTP/TCP + env-driven mode):
server/src/unityBridge.ts - Concrete step contracts for autonomous_plan:
server/src/contracts.ts - Unity 2022.3.22f1 package scaffold:
com.autonomous-unity.mcp/- Editor settings/provider:
Editor/AutonomousMcpSettingsProvider.cs - Real transport host:
Editor/AutonomousMcpTransportHost.cs - Tool dispatcher:
Editor/AutonomousMcpToolDispatcher.cs - Runtime entry component:
Runtime/AutonomousMcpRuntime.cs
- Editor settings/provider:
🔁 End-to-end autonomous_plan contract mapping
autonomous_plan now emits concrete Unity tool payloads:
read_console→{ level, limit }manage_scene→{ action: "inspect_active_scene" }manage_script→{ action: "create_or_update", scriptPath, contents }(when goal implies code changes)validate_script→{ strict }(after script edits)run_tests→{ mode }(when goal mentions tests; returnsjobId)get_test_job→{ jobId }(executor polls untilcompletedorfailed)batch_execute→{ operations: [{ tool: "manage_scene", params: { action: "save_active_scene" } }] }
Test execution flow
run_testsstarts an async Unity Test Runner job (editmodeorplaymode)- Server receives
{ jobId, status: "queued" } - Executor automatically calls
get_test_jobuntil terminal state - Final test summary (passed/failed/skipped + per-test details) is included in execution results
Test polling policy limits
UNITY_TEST_POLL_ATTEMPTS: max polling iterations forget_test_job(clamped 1..300)UNITY_TEST_POLL_INTERVAL_MS: delay between polls in milliseconds (clamped 100..60000)UNITY_TEST_POLL_TIMEOUT_MS: overall timeout for polling cycle (clamped 1000..1800000)
🤖 Autonomous Agent Features
Intelligent Task Planning
- Goal Decomposition: Break complex tasks into manageable subtasks
- Priority Management: Dynamic task prioritization based on context
- Resource Allocation: Optimal distribution of system resources
- Dependency Resolution: Handle task dependencies and conflicts
Learning & Adaptation
- Pattern Recognition: Learn from user behavior and preferences
- Performance Optimization: Improve efficiency over time
- Error Recovery: Learn from mistakes and avoid repetition
- Context Awareness: Adapt to project-specific requirements
Multi-Agent Coordination
- Agent Communication: Coordinate multiple specialized agents
- Task Distribution: Distribute workload across agent instances
- Conflict Resolution: Handle competing priorities and resource conflicts
- Collaborative Problem Solving: Combine multiple agent perspectives
🔧 MCP Tools & Capabilities
🎮 Unity Editor Tools
- Scene Management: Create, modify, optimize scenes automatically
- Asset Operations: Intelligent asset creation and organization
- GameObject Control: Advanced object manipulation and optimization
- Component Management: Dynamic component addition and configuration
- Build Automation: Automated build processes and optimization
🧩 Advanced Development Tools
- Code Generation: AI-assisted script writing and optimization
- Testing Automation: Automated test creation and execution
- Performance Analysis: Real-time performance monitoring and optimization
- Debugging Assistant: Intelligent error detection and resolution
- Documentation Generation: Auto-generate technical documentation
🎯 Runtime AI Features
- NPC Behavior: Dynamic, intelligent NPC behavior systems
- Game Balance: Automated game balance testing and adjustment
- Player Analytics: Real-time player behavior analysis
- Dynamic Difficulty: Adaptive difficulty adjustment systems
- Content Generation: Procedural content creation and optimization
🔌 Plugin System
Create custom plugins to extend functionality:
[AutonomousPlugin("custom-tool")]
public class CustomToolPlugin : IAutonomousTool
{
public async Task<ToolResult> ExecuteAsync(ToolContext context)
{
// Your custom tool logic
return new ToolResult { Success = true, Data = result };
}
}
📊 Performance & Monitoring
Real-time Metrics
- Agent Performance: Monitor agent efficiency and accuracy
- Resource Usage: Track CPU, memory, and network utilization
- Task Completion: Measure task success rates and timing
- Learning Progress: Track agent improvement over time
Optimization Features
- Caching System: Intelligent caching for frequently used data
- Batch Processing: Optimize multiple operations together
- Predictive Loading: Anticipate and preload required resources
- Adaptive Performance: Adjust performance based on system capabilities
🛡️ Security & Safety
Safety Measures
- Sandboxed Execution: Isolate agent operations from critical systems
- Permission System: Granular control over agent capabilities
- Audit Logging: Complete audit trail of all agent actions
- Rollback Capability: Undo system for agent modifications
Best Practices
- Regular Backups: Automatic backup before major operations
- Validation Checks: Verify operation safety before execution
- User Confirmation: Require confirmation for destructive operations
- Error Handling: Comprehensive error recovery mechanisms
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
- Clone repository
- Install dependencies (
npm installin server directory) - Open Unity project
- Enable Developer Mode in preferences
- Start contributing!
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Built upon the excellent foundations of Unity-MCP and UnityMCP
- Inspired by the latest advances in autonomous agents and AI decision-making
- Community feedback and contributions have been invaluable
🚀 Ready to transform your Unity development with AI-powered autonomy?
Start building intelligent, self-improving Unity projects today!
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。