How codergamester/mcp-unity works
Main Components
• Editor Component:
• This folder (Editor/) contains all Unity Editor-specific code.
• Subcomponents include:
▪ Resources (e.g., GetAssetsResource, GetConsoleLogsResource, GetGameObjectResource, etc.) that provide Unity’s data.
▪ Tools (e.g., AddAssetToSceneTool, AddPackageTool, RunTestsTool, etc.) that perform actions in the editor.
▪ UnityBridge that establishes communication channels between Unity and the server.
▪ Services (e.g., TestRunnerService) supporting backend interactions.
▪ Utility classes for configuration and workspace (McpConfigUtils, VsCodeWorkspaceUtils).
• Server Component:
• The Server/ directory houses the Node.js backend.
• Contains:
▪ src folder with TypeScript sources for resources and tools mirroring the Editor functionality.
▪ Build folder with compiled JavaScript and type definitions.
▪ Package management artifacts (package.json) and Docker configuration for container deployment.
▪ Utility modules for error handling and logging.
• External AI/LLM Clients:
• Represented by connected AI coding assistants (Claude, Windsurf, Cursor) that interact via the WebSocket.
• Communication Infrastructure:
• WebSocket Server that facilitates real-time, bidirectional communications between the Editor and Node.js Server.
• Environment configuration (e.g., UNITY_PORT) helps establish the proper ports and settings.
Relationships and Interactions
• The Unity Editor component (with its Tools, Resources, Services, and UnityBridge) communicates via a WebSocket to the Node.js server.
• The Node.js Server acts as the central MCP server, handling incoming commands (e.g., execute_menu_item, select_gameobject):
• It processes these requests (using resources and tools modules) and may perform operations back in the Unity Editor.
• External AI clients connect to the Node.js server, sending instructions that are translated into actions within Unity.
• Integration with IDEs (like VSCode) is enabled via configuration and package cache access.
Architectural Patterns and Technologies
• The separation of concerns is clear: Unity Editor (client-side functionality) and Node.js Server (backend communication layer) form a loosely coupled, distributed architecture.
• The design employs a bridge pattern (visible in the UnityBridge module) to interact between Unity’s internal APIs and the external MCP protocol.
• Technologies include Unity Editor’s C# environment and Node.js with TypeScript.
• Communication patterns rely on real-time WebSocket data flows.