# justinpbarnett/unity-mcp architecture

> Architecture diagram of the GitHub repository justinpbarnett/unity-mcp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/justinpbarnett/unity-mcp
- Repository: https://github.com/justinpbarnett/unity-mcp

## Overview

##### High-Level Overview
- Overall purpose: A bidirectional bridge between the Unity Editor (C#) and a Python server that interfaces with LLM MCP clients (e.g., Claude Desktop).
- Recognize the project as a hybrid full-stack integration between Unity and Python, enabling asset management, scene control, and editor automation.

##### Top-Level Components
- Unity Editor (Client Side)
- Contains scripts and tools (located under the Editor folder) that manage asset operations, command dispatching, and various editor utilities.
- Key subdirectories: Data, Helpers, Models, Tools, and Windows.
- Python Server (Server Side)
- Found within the Python folder, it includes the server script (server.py), configuration (config.py), and supportive tools for executing mirror functionality of the Editor tools.
- Dependencies like uv (see uv.lock) are set up to maintain runtime and dependency management.
- MCP Communication Layer
- Acts as the protocol bridge (facilitated through the UnityMCPBridge in the Editor and related Python scripts) ensuring bidirectional command and response flows.

##### Component Relationships and Interactions
- Data Flow:
- Unity Editor sends commands (via tools and models) over the MCP protocol to the Python server.
- Python server processes commands and replies, enabling real-time actions within Unity (asset manipulation, scene control, etc.).
▸ From Unity Editor Components (C#) to the Python Server.
▸ From the Python Server back to Unity Editor.
- Internal Structure:
- Within the Unity Editor, arrange components hierarchically:
– Top: Main MCP Bridge and Editor Window.
– Next: Tools (CommandRegistry, ManageAsset, etc.) and Models representing the MCP configuration.
– Base: Helper utilities and data classes.
- In the Python server, show the main server module (server.py), configuration, and ancillary tool scripts.

##### Important Architectural Patterns & Design Principles
- Separation of concerns: Clear distinction between the Editor’s client-side components and the Python server.
- Modularity: Structured directories (e.g., Editor’s Models vs. Tools) indicate well-organized modules.
- Bidirectional communication: Emphasize the use of MCP to facilitate command and response cycles.
- Dependency management: Note external tools like uv package manager and Python version dependencies.

## Diagram (Mermaid)

```mermaid
flowchart TD
    TM("Unity MCP Package"):::system
    TM --> U1
     
    subgraph "Unity Editor (Client Side)"
        U1("Unity Editor – MCP Bridge"):::unity
        U2("Editor Windows"):::unity
        U3("Tools"):::unity
        U4("Models"):::unity
        U5("Helper Utilities"):::unity
        U6("Data Components"):::unity
        U1 --> U2
        U2 --> U3
        U3 --> U4
        U4 --> U5
        U5 --> U6
    end

    U1 -->|"sendCmd"| P1
    P1 -->|"replyCmd"| U1

    subgraph "Python Server (Server Side)"
        P1("MCP Communication (Protocol Bridge)"):::python
        P2("Main Server Module"):::python
        P3("Configuration Module"):::python
        P4("Support Tools"):::python
        P1 --> P2
        P2 --> P3
        P3 --> P4
    end

    %% Click Events
    click U1 "https://github.com/justinpbarnett/unity-mcp/blob/master/Editor/UnityMCPBridge.cs"
    click U2 "https://github.com/justinpbarnett/unity-mcp/tree/master/Editor/Windows"
    click U3 "https://github.com/justinpbarnett/unity-mcp/tree/master/Editor/Tools"
    click U4 "https://github.com/justinpbarnett/unity-mcp/tree/master/Editor/Models"
    click U5 "https://github.com/justinpbarnett/unity-mcp/tree/master/Editor/Helpers"
    click U6 "https://github.com/justinpbarnett/unity-mcp/tree/master/Editor/Data"
    click P1 "https://github.com/justinpbarnett/unity-mcp/blob/master/Python/unity_connection.py"
    click P2 "https://github.com/justinpbarnett/unity-mcp/blob/master/Python/server.py"
    click P3 "https://github.com/justinpbarnett/unity-mcp/blob/master/Python/config.py"
    click P4 "https://github.com/justinpbarnett/unity-mcp/tree/master/Python/tools"

    %% Styles
    classDef system fill:#FFD966,stroke:#BF9000,stroke-width:2px;
    classDef unity fill:#CFE2F3,stroke:#084C61,stroke-width:2px;
    classDef python fill:#D9EAD3,stroke:#6AA84F,stroke-width:2px;
```
