Unity-MCP
A bridge between Unity and AI assistants using the Model Context Protocol (MCP).
Overview
Unity-MCP is an open-source implementation of the Model Context Protocol for Unity game development. It enables AI assistants to interact with Unity game environments through a standardized interface, allowing for AI-assisted game development, automated testing, scene analysis, and runtime debugging.
Architecture
The architecture has been simplified to use AILogger for persistence, removing the need for a separate server component:
- AI Assistant: Communicates with the Unity-MCP STDIO Client using the MCP protocol
- Unity-MCP STDIO Client: Forwards commands to the Unity Client and stores results in AILogger
- Unity Client: Executes commands in Unity and returns results
- AILogger: Stores logs and results for later retrieval
The Unity-MCP STDIO Client communicates directly with the Unity Client, which provides endpoints for both code execution and queries. The query tool transforms queries into code execution by wrapping them in a return
statement.
Features
- Execute C# code in the Unity runtime environment
- Inspect game objects and their components
- Analyze scene hierarchies and structures
- Run tests and receive results
- Invoke methods on game objects and components
- Modify game state during runtime
Deployment Options
- Unity Editor Extension: An Editor extension that persists beyond game execution cycles
- Docker Container: A containerized version that communicates with Unity over the network
- NPX Package: A Node.js package that can be installed and run via NPX
Documentation
- MCP Architecture: Overview of the MCP architecture and namespaces
- MCP STDIO Client: Information about the MCP STDIO client and its logging capabilities
- Query Tool: Detailed information about the query tool and how it works
- AILogger Integration: Detailed information about the AILogger integration
- API Reference: Detailed information about the API endpoints
- Installation Guide: Step-by-step instructions for installing and setting up Unity-MCP
- Development Guide: Information about the development environment and workflow
- Hot Reloading Guide: Detailed information about hot reloading in the development environment
- Hot Reloading Quick Reference: Quick reference guide for hot reloading commands and tips
- Contributing Guide: Guidelines for contributing to the project
Getting Started
To get started with Unity-MCP, follow these steps:
- Clone the repository:
- Install dependencies:
- Build the project:
- Start the MCP STDIO client:This will start the MCP STDIO client that communicates with Unity and uses AILogger for persistence.Note: Make sure AILogger is running on http://localhost:3030 or set the AI_LOGGER_URL environment variable to point to your AILogger instance.
- Run tests:
For more detailed instructions, see the Installation Guide.
Connecting to AI Assistants
To connect the Unity-MCP bridge to an AI assistant, you need to create an MCP configuration file:
Place this file in the appropriate location for your AI assistant. For Claude, this would typically be in the Claude Desktop app's configuration directory.
Available Tools
The Unity-MCP bridge provides the following tools:
- execute_code: Execute C# code directly in Unity.
- query: Execute a query using dot notation to access objects, properties, and methods.
- get_logs: Retrieve logs from AILogger.
- get_log_by_name: Retrieve a specific log from AILogger.
Usage Examples
Executing Code in Unity
You can execute C# code in Unity using the execute_code
tool. The code will be executed in the Unity runtime environment, and the result will be stored in AILogger for later retrieval.
JSON-RPC Request
JSON-RPC Response
Querying Unity Objects
You can query Unity objects using the query
tool. This allows you to access objects, properties, and methods using dot notation.
JSON-RPC Request
JSON-RPC Response
Retrieving Results from AILogger
You can retrieve the results of previous operations from AILogger using the get_log_by_name
tool.
JSON-RPC Request
JSON-RPC Response
Example Usage
Once the AI assistant has access to the Unity tool, you can ask it to perform tasks like:
License
MIT
Author
T Savo (@TSavo)
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Unity 和 AI 助手之间的桥梁,使 AI 能够通过标准化接口与 Unity 游戏环境进行交互,以执行代码、场景分析和运行时调试。
Related Resources
Related MCP Servers
- -securityAlicense-qualityA server that enables AI assistants to understand and interact with Unity projects in real-time, providing access to scene hierarchy, project settings, and the ability to execute code directly in the Unity Editor.Last updated -90MIT License
- -securityFlicense-qualityA protocol server that bridges AI assistants with Unity projects, allowing them to analyze code, parse scenes, generate scripts, and perform other Unity operations through specialized tools.Last updated -
- -securityFlicense-qualityA bridge that enables controlling Unity Editor through natural language commands via AI assistants, allowing users to create materials, build projects, manage scenes, and configure settings without manual interaction.Last updated -64
- -securityAlicense-qualityA bridge that enables AI assistants to connect to VS Code's debugger, allowing them to interact with and control debugging sessions through websocket connections.Last updated -9MIT License