Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
YetAnotherUnityMcp bridges Unity with AI, enabling agents to control scenes via a custom TCP protocol and the Model Context Protocol.
DO NOT USE THIS. THIS IS A TOY PROJECT TO SEE WHAT I CAN DO WITH CLAUDE CODE. I'M TRYING TO ASSESS IF A DEV CAN CORRECTLY WORK WITH JUST VIBE CODING SO FAR, IT SEEMS NOT TO BE THE CASE !
A Unity Master Control Protocol (MCP) implementation that allows AI agents to control and interact with Unity.
YetAnotherUnityMcp is a system that bridges the Unity game engine with AI-driven tools using the Model Context Protocol (MCP). It consists of a Unity .NET/C# plugin acting as the MCP TCP server, and a Python MCP client (built with FastMCP) that handles requests from AI agents. Communication between Unity and the client is done via a custom TCP protocol, enabling real-time, bidirectional exchange of JSON messages and image data.
This architecture cleanly separates the game engine concerns from the AI logic, improving scalability and maintainability. The goal is to allow AI agents (e.g. an LLM-based assistant) to inspect and control a running Unity scene in a structured, safe manner. The container-based approach for organizing resources and tools further improves code organization and reduces boilerplate.
Key components include:
The Model Context Protocol (MCP) is a standardized way for AI models to interact with applications. It separates the concerns of providing context from the LLM interaction itself, allowing for:
YetAnotherUnityMcp implements the official MCP specification with full compliance, including:
plugin/Scripts
folder to your Unity project's Assets directoryNew-Item -ItemType SymbolicLink -Target "D:\Dev\YetAnotherUnityMcp\plugin" -Path "C:\Users\azrea\My project\Assets\Plugins\YetAnotherUnityMcp"
# Clone the repository
git clone https://github.com/yourusername/YetAnotherUnityMcp.git
cd YetAnotherUnityMcp
# Create and activate a virtual environment using uv
uv venv -p 3.11
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install the server with development dependencies
uv pip install -e ".\[dev]"
# Run the MCP client
python -m server.mcp_server
# Install FastMCP and tools
uv pip install fastmcp
# Run the client with MCP inspector for debugging
fastmcp dev server/mcp_server.py
# Install in Claude Desktop
fastmcp install server/mcp_server.py --name "Unity Controller"
YetAnotherUnityMcp/
├── server/ # Python MCP client
│ ├── unity_client_util.py # Unity client utility functions
│ ├── unity_tcp_client.py # High-level Unity TCP client
│ ├── mcp_server.py # MCP server implementation
│ ├── dynamic_tool_invoker.py # Dynamic tool invocation system
│ ├── dynamic_tools.py # Dynamic tool manager
│ ├── connection_manager.py # Connection lifecycle management
│ └── websocket_client.py # Low-level TCP client (legacy name)
├── plugin/ # Unity C# plugin
│ ├── Scripts/ # Plugin source code
│ │ ├── Editor/ # Editor extensions
│ │ │ ├── Commands/ # Editor command implementations
│ │ │ ├── MCPWindow.cs # Server control window
│ │ │ ├── MCPMenu.cs # Unity menu integration
│ │ │ ├── MCPTcpServer.cs # Primary TCP server implementation
│ │ │ ├── CommandExecutionMonitor.cs # Performance monitoring
│ │ │ ├── Models/ # Data models for Editor
│ │ │ └── Net/ # TCP communication implementation
│ │ └── YetAnotherUnityMcp.asmdef # Assembly definition
│ └── README.md # Plugin documentation
└── tests/ # Test suite
The Unity plugin hosts a TCP server that listens for connections from MCP clients. This server:
For detailed information about the container-based approach, see the MCP Container Documentation.
The Python client connects to the Unity TCP server and provides an MCP interface for AI tools. It:
unity://info
- Basic information about the Unity environmentunity://logs
- Editor logs for debuggingunity://scene/{scene_name}
- Information about a specific sceneunity://object/{object_id}
- Details about a specific GameObjectexecute_code_in_unity
- Run C# code in the Unity Editorunity_screenshot
- Take screenshots of the Unity Editorunity_modify_object
- Change properties of Unity GameObjectsunity_logs
- Get logs from UnityAll communication between the Unity server and the Python client uses a TCP socket connection with a simple framing protocol, which allows persistent, low-latency bidirectional messaging. The connection is initiated by the Python client to the Unity server's TCP endpoint (e.g. localhost:8080
).
The protocol uses a simple framing mechanism:
Every message is a JSON object containing at least a command or response type, a unique ID (to pair requests with responses), and a parameters or result object. The connection is maintained with periodic ping/pong messages. For more details on the communication protocol, see the Technical Details document.
# Python client development
python -m pytest # Run tests
python -m black . # Format code
python -m flake8 # Lint code
python -m mypy . # Type check
# MCP Development
fastmcp dev server/mcp_server.py # Run with MCP Inspector UI
# Unity server development
# Use the MCP Server window in Unity for debugging
# Monitor connections and messages in real-time
This project is licensed under the MIT License - see the LICENSE file for details.
For more details on architecture, implementation, and extensibility, see the Technical Details document.