How arodoid/unitymcp works
Main Components
• Unity Plugin (UnityMCPPlugin):
• Represents the Unity Editor integration, which includes:
• A Debug window (accessible through Unity’s top menu)
• A WebSocket client to establish real-time communication with the server
• A command execution engine to run C# code in the editor context
• Editor state tracking and logging components
• MCP Server (unity-mcp-server):
• A TypeScript-based backend exposing a set of tools:
• get_editor_state, execute_editor_command, and get_logs functionalities
• WebSocket server listening (default port 8080), receiving, processing, and responding to commands
• Additional support features like error and timeout management
Relationships and Interactions
• The Unity plugin acts as a client connecting to the MCP Server via WebSocket.
• The data flow is bidirectional:
• Outbound: The plugin sends real-time status, log messages, and command execution requests to the server.
• Inbound: The server provides data responses (like editor state, command confirmations, or error logs) back to the plugin.
Architectural Patterns and Design Principles
• Separation of Concerns: Frontend (Unity plugin) and backend (MCP server) are clearly separated.
• Real-Time Communication: Leverages WebSockets for low latency, bidirectional data transfers.
• Modular and Extensible Design: The server is built with TypeScript (and includes a Dockerfile, package configuration, TypeScript config, etc.), suggesting that maintainability and ease of updates are vital.
• Command Execution and Error Handling: The system has built-in measures (such as command timeout, logging, error handling) to ensure robust interactions.
Technologies, Frameworks, or Libraries
• Unity & C#: The plugin uses Unity Editor’s API (UnityEngine, UnityEditor) for real-time state monitoring and command execution.
• TypeScript & Node.js: The MCP server is built in TypeScript running on Node.js (with an accompanying Dockerfile for deployment, which suggests containerization is supported).
• WebSockets: The communication between the plugin and server is established over WebSocket on port 8080.
• JSON: The standard format for message exchange.