Skip to content

Conversation

@msanatan
Copy link
Contributor

@msanatan msanatan commented Oct 25, 2025

I want to experiment with using uvx from this location, and if it manages all the use cases correctly, we won't clone and copy the server code

Summary by CodeRabbit

Release Notes

  • New Features

    • Added MCP server for Unity Editor integration with Model Context Protocol support.
    • Introduced comprehensive toolset for managing Unity projects: assets, scenes, GameObjects, scripts, shaders, tests, menus, and console operations.
    • Added resource discovery API to query Unity Editor state and available menu items.
    • Implemented privacy-focused telemetry system to track feature usage and performance metrics.
    • Provided Docker containerization for streamlined server deployment.
  • Documentation

    • Added comprehensive README with installation instructions (uvx, uv, Docker) and MCP client configuration examples.
  • Chores

    • Added project configuration files for Python packaging and type checking.

I want to experiment with using `uvx` from this location, and if it manages all the use cases correctly, we won't clone and copy the server code
@msanatan msanatan self-assigned this Oct 25, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 25, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Introduces a complete Python-based MCP server for Unity integration. Adds core infrastructure (connection management, port discovery, telemetry, module discovery), a registry system for tools and resources, an extensible set of Unity tools (asset, scene, script, shader, menu, test management), resource endpoints, and comprehensive server configuration with logging, retry logic, and optional telemetry collection.

Changes

Cohort / File(s) Change Summary
Infrastructure & Configuration
Dockerfile, pyproject.toml, pyrightconfig.json, server_version.txt, README.md
Docker containerization setup with Python 3.13-slim, project metadata with dependencies (fastmcp, mcp, pydantic, httpx), Pyright type checking configuration, version resource, and comprehensive usage/installation documentation.
Core Server & Configuration
config.py, models.py, server.py
Server configuration dataclass with network, logging, and telemetry settings; standardized MCPResponse Pydantic model; main FastMCP server with logging, telemetry integration, lifecycle management, and startup/shutdown coordination with Unity connection.
Connection & Discovery
unity_connection.py, port_discovery.py, module_discovery.py
TCP connection manager with framed/legacy I/O, handshake, command sending with retry/backoff logic; port discovery with registry scanning and UDP probing fallbacks; utility to discover and dynamically import Python modules from directories.
Telemetry System
telemetry.py, telemetry_decorator.py, test_telemetry.py
Privacy-focused fire-and-forget telemetry with persistent UUID/milestone storage, background worker thread, httpx/urllib transport selection, endpoint validation; decorators for recording tool/resource usage and milestones; test suite for telemetry functionality.
Registry & Tool/Resource Loaders
registry/tool_registry.py, registry/resource_registry.py, registry/__init__.py, tools/__init__.py, resources/__init__.py
Decorator-based tool and resource registration with metadata storage; public registry interfaces; auto-discovery loaders that import modules, wrap functions with telemetry, apply MCP decorators, and register with FastMCP.
Reload & Deprecated
reload_sentinel.py
Deprecation shim returning no-op function with guidance to use execute_menu_item for reload sentinel.
Unity Tools
tools/execute_menu_item.py, tools/manage_asset.py, tools/manage_editor.py, tools/manage_gameobject.py, tools/manage_prefabs.py, tools/manage_scene.py, tools/manage_script.py, tools/manage_shader.py, tools/read_console.py, tools/resource_tools.py, tools/run_tests.py, tools/script_apply_edits.py
12 MCP tool implementations for Unity Editor operations: menu/asset/scene/script/shader/prefab/gameobject management; editor state queries; console reading; test execution; resource listing/searching; script edits with local text application, anchor matching, and structured edit workflows.
Unity Resources
resources/menu_items.py, resources/tests.py
Resource endpoints returning menu items and test lists (EditMode/PlayMode) from Unity via async command dispatch.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant FastMCP as FastMCP Server
    participant TelemetryDec as Telemetry Decorator
    participant UnityConn as Unity Connection
    participant Telemetry as Telemetry Collector
    participant Unity as Unity Editor

    Client->>FastMCP: Call MCP tool (e.g., manage_script)
    FastMCP->>TelemetryDec: Invoke decorated function
    TelemetryDec->>TelemetryDec: Start timer
    TelemetryDec->>UnityConn: send_command_with_retry()
    UnityConn->>UnityConn: Check port (cached or discover)
    UnityConn->>Unity: TCP connect + handshake
    Unity-->>UnityConn: FRAMING=1 response
    UnityConn->>Unity: Send command (JSON with length header)
    UnityConn->>UnityConn: receive_full_response()<br/>(handle framing, heartbeat)
    Unity-->>UnityConn: Response (with length header)
    UnityConn-->>TelemetryDec: Return parsed response dict
    TelemetryDec->>Telemetry: record_tool_usage()<br/>(name, success, duration, error)
    TelemetryDec->>Telemetry: record_milestone() if applicable
    Telemetry->>Telemetry: Enqueue to background worker
    Telemetry-->>Telemetry: (async send via httpx)
    TelemetryDec-->>FastMCP: Return response
    FastMCP-->>Client: MCP response
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~70 minutes

Areas requiring special attention:

  • unity_connection.py: Socket I/O synchronization with _io_lock, framed message protocol (8-byte big-endian length headers, heartbeat handling), reconnection/port rediscovery logic, backoff/jitter, and reload state detection
  • telemetry.py: Thread-safety of background worker, UUID/milestone persistence with OS-specific paths, endpoint URL validation (disallowing localhost), httpx vs urllib fallback, and graceful error handling ensuring telemetry never crashes the app
  • port_discovery.py: Multi-stage discovery orchestration (status file → registry files → UDP probing), fallback chain, and priority ordering of candidate ports
  • manage_gameobject.py: Extensive parameter coercion (booleans from strings, vectors from lists/strings), JSON parsing for component_properties, validation rules (e.g., ensure 'find' uses search_term not name), and prefab path handling
  • manage_script.py and script_apply_edits.py: Complex text-editing workflows with anchor matching heuristics, brace-matching fallbacks, SHA256 preconditions, and both structured (Unity-side) and text-based (local) edit paths
  • Registry and auto-discovery: Verify module discovery logic handles import errors gracefully, telemetry wrapping is applied consistently, and tool/resource metadata is correctly propagated

Possibly related PRs

Suggested reviewers

  • justinpbarnett

Poem

🐰 A server springs forth from the Python deep,
With connections to Unity, no thread left unswept!
Tools gather and register, telemetry hums,
While anchors find homes in the edits that come.
From port-discovery's dance to the framing so tight,
The MCP for Unity now shines ever bright! ✨

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch move-server-to-root

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 697e0fb and 0d9b0e1.

⛔ Files ignored due to path filters (1)
  • Server/uv.lock is excluded by !**/*.lock
📒 Files selected for processing (34)
  • Server/Dockerfile (1 hunks)
  • Server/README.md (1 hunks)
  • Server/config.py (1 hunks)
  • Server/models.py (1 hunks)
  • Server/module_discovery.py (1 hunks)
  • Server/port_discovery.py (1 hunks)
  • Server/pyproject.toml (1 hunks)
  • Server/pyrightconfig.json (1 hunks)
  • Server/registry/__init__.py (1 hunks)
  • Server/registry/resource_registry.py (1 hunks)
  • Server/registry/tool_registry.py (1 hunks)
  • Server/reload_sentinel.py (1 hunks)
  • Server/resources/__init__.py (1 hunks)
  • Server/resources/menu_items.py (1 hunks)
  • Server/resources/tests.py (1 hunks)
  • Server/server.py (1 hunks)
  • Server/server_version.txt (1 hunks)
  • Server/telemetry.py (1 hunks)
  • Server/telemetry_decorator.py (1 hunks)
  • Server/test_telemetry.py (1 hunks)
  • Server/tools/__init__.py (1 hunks)
  • Server/tools/execute_menu_item.py (1 hunks)
  • Server/tools/manage_asset.py (1 hunks)
  • Server/tools/manage_editor.py (1 hunks)
  • Server/tools/manage_gameobject.py (1 hunks)
  • Server/tools/manage_prefabs.py (1 hunks)
  • Server/tools/manage_scene.py (1 hunks)
  • Server/tools/manage_script.py (1 hunks)
  • Server/tools/manage_shader.py (1 hunks)
  • Server/tools/read_console.py (1 hunks)
  • Server/tools/resource_tools.py (1 hunks)
  • Server/tools/run_tests.py (1 hunks)
  • Server/tools/script_apply_edits.py (1 hunks)
  • Server/unity_connection.py (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@msanatan
Copy link
Contributor Author

I'm doing some tests with uvx, if it doesn't work out I'll remove this folder

@msanatan msanatan merged commit 0f506e4 into main Oct 25, 2025
1 check was pending
@msanatan msanatan deleted the move-server-to-root branch October 25, 2025 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants