Skip to content

Conversation

@msanatan
Copy link
Member

@msanatan msanatan commented Jan 21, 2026

Simpler implementation of #541, which it closes

Summary by Sourcery

Adjust client WebSocket host handling and update the server Docker image entrypoint for MCP gateway usage.

Bug Fixes:

  • Handle bind-only hosts 0.0.0.0 and :: by mapping them to localhost for WebSocket client connections, with a warning log.

Enhancements:

  • Improve WebSocket client host validation by logging when bind-only addresses are replaced with localhost.
  • Update the server Dockerfile to use an ENTRYPOINT targeting the MCP for Unity CLI with a default stdio transport suitable for Docker MCP Gateway usage.

Documentation:

  • Document Docker usage patterns in the Dockerfile comments, including HTTP mode, port mapping, and project-scoped tools guidance.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved WebSocket host address resolution to handle additional network configuration scenarios, with enhanced diagnostic logging when bind-only addresses are detected.
  • Chores

    • Updated Docker server startup configuration with improved documentation for deployment and hosting flexibility.

✏️ Tip: You can customize this high-level summary in your review settings.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 21, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts WebSocket client host handling for bind-only addresses and restructures the Docker server image entrypoint to default to a stdio-based MCP gateway with configurable transport via container arguments.

Sequence diagram for WebSocket client handling bind-only host addresses

sequenceDiagram
    actor Developer
    participant UnityClient
    participant WebSocketTransportClient
    participant WebSocketServer

    Developer->>UnityClient: Configure MCP base URL (e.g. http://0.0.0.0:8080)
    UnityClient->>WebSocketTransportClient: Connect(baseUrl)
    WebSocketTransportClient->>WebSocketTransportClient: BuildWebSocketUri(baseUrl)
    WebSocketTransportClient->>WebSocketTransportClient: Parse baseUrl as httpUri
    WebSocketTransportClient->>WebSocketTransportClient: host = httpUri.Host
    alt host is bind-only (0.0.0.0 or ::)
        WebSocketTransportClient->>WebSocketTransportClient: Log warning via McpLog.Warn
        WebSocketTransportClient->>WebSocketTransportClient: host = localhost
    end
    WebSocketTransportClient->>WebSocketTransportClient: Build ws or wss Uri using host
    WebSocketTransportClient->>WebSocketServer: Open WebSocket connection
    WebSocketServer-->>WebSocketTransportClient: Connection established
    WebSocketTransportClient-->>UnityClient: Ready for MCP communication
Loading

Updated class diagram for WebSocketTransportClient host resolution

classDiagram
    class WebSocketTransportClient {
        +Connect(string baseUrl)
        -BuildWebSocketUri(string baseUrl) Uri
    }

    class McpLog {
        +Warn(string message)
    }

    WebSocketTransportClient ..> McpLog : uses

    class BuildWebSocketUriLogic {
        -string baseUrl
        -Uri httpUri
        -string host
        +ResolveHost()
        +CreateWebSocketUri()
    }

    WebSocketTransportClient ..> BuildWebSocketUriLogic : delegates logic

    class BindOnlyAddressHandling {
        +bool IsBindOnly(string host)
        +string ToClientHost(string host)
    }

    BuildWebSocketUriLogic ..> BindOnlyAddressHandling : checks 0_0_0_0_or_double_colon
    BindOnlyAddressHandling ..> McpLog : logs_warn_on_bind_only
Loading

File-Level Changes

Change Details Files
Normalize bind-only WebSocket base URL hosts to localhost and add logging when this occurs.
  • Treat both 0.0.0.0 and :: as bind-only addresses that cannot be used for WebSocket client connections.
  • Log a warning when a bind-only host is detected, indicating that localhost will be used instead.
  • Preserve other URI components while substituting the host used to build the WebSocket URI.
MCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.cs
Change Docker container startup to use an ENTRYPOINT for the MCP gateway with a default stdio transport and an overridable CMD.
  • Switch from a fixed CMD that runs the HTTP transport server to an ENTRYPOINT that runs the MCP for Unity gateway.
  • Provide an empty CMD so users can pass custom arguments via docker run to choose transports and ports.
  • Document default stdio transport behavior and how to enable HTTP transport and project-scoped tools in container usage comments.
Server/Dockerfile

Possibly linked issues

  • #unknown: The PR’s Dockerfile changes document the exact docker run usage requested in the issue, fulfilling it.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@msanatan msanatan merged commit 1ad4f09 into CoplayDev:main Jan 21, 2026
1 of 2 checks passed
@msanatan msanatan deleted the docker-mcp-gateway branch January 21, 2026 20:00
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 21, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Two files are modified: WebSocketTransportClient.cs now treats both 0.0.0.0 and :: (IPv6 loopback) as bind-only addresses, substituting localhost for client connections and emitting a warning; Server/Dockerfile switches from CMD to ENTRYPOINT for running mcp-for-unity via uv with added documentation.

Changes

Cohort / File(s) Summary
Host Resolution Normalization
MCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.cs
Expanded bind-only address detection from 0.0.0.0 only to include :: (IPv6 loopback). When either address is detected, it is replaced with localhost for client connections. Warning log emitted upon detection.
Docker Entrypoint Configuration
Server/Dockerfile
Changed from CMD invocation running Python via uv to ENTRYPOINT running mcp-for-unity via uv. Added comments explaining that ENTRYPOINT allows docker run overrides and describes default behavior for HTTP or remote hosting.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through networks wide,
Where 0.0.0.0 and :: collide,
Now localhost's the path they take,
And Docker's entry keeps them awake! 🐳✨

✨ Finishing touches
  • 📝 Generate docstrings

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.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • Instead of comparing bind-only addresses by string ("0.0.0.0" and "::"), consider parsing httpUri.Host as an IPAddress and checking IPAddress.Any/IPv6Any to be more robust (e.g., handling variants like ::0).
  • The new warning log in BuildWebSocketUri may fire frequently for valid setups using bind-only hosts; consider lowering this to a debug/info level or rate-limiting it so it doesn’t become noisy in normal operation.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Instead of comparing bind-only addresses by string (`"0.0.0.0"` and `"::"`), consider parsing `httpUri.Host` as an `IPAddress` and checking `IPAddress.Any`/`IPv6Any` to be more robust (e.g., handling variants like `::0`).
- The new warning log in `BuildWebSocketUri` may fire frequently for valid setups using bind-only hosts; consider lowering this to a debug/info level or rate-limiting it so it doesn’t become noisy in normal operation.

## Individual Comments

### Comment 1
<location> `Server/Dockerfile:31` </location>
<code_context>
 ENV PYTHONPATH=/app/Server/src

-CMD ["uv", "run", "python", "src/main.py", "--transport", "http", "--http-host", "0.0.0.0", "--http-port", "8080"]
+# ENTRYPOINT allows override via docker run arguments
+# Default: stdio transport (Docker MCP Gateway compatible)
+# For HTTP: docker run -p 8080:8080 <image> --transport http --http-host 0.0.0.0 --http-port 8080
</code_context>

<issue_to_address>
**issue:** The comment about ENTRYPOINT being overridable via `docker run` is a bit misleading.

With an ENTRYPOINT like `[
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

ENV PYTHONPATH=/app/Server/src

CMD ["uv", "run", "python", "src/main.py", "--transport", "http", "--http-host", "0.0.0.0", "--http-port", "8080"]
# ENTRYPOINT allows override via docker run arguments
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: The comment about ENTRYPOINT being overridable via docker run is a bit misleading.

With an ENTRYPOINT like `[

msanatan added a commit to msanatan/unity-mcp that referenced this pull request Jan 21, 2026
* Log a message with implicit URI changes

Small update for CoplayDev#542

* Update docker container to default to stdio

Replaces CoplayDev#541
msanatan added a commit that referenced this pull request Jan 22, 2026
* feat: Add CLI for Unity MCP server

- Add click-based CLI with 15+ command groups
- Commands: gameobject, component, scene, asset, script, editor, prefab, material, lighting, ui, audio, animation, code
- HTTP transport to communicate with Unity via MCP server
- Output formats: text, json, table
- Configuration via environment variables or CLI options
- Comprehensive usage guide and unit tests

* Update based on AI feedback

* Fixes main.py error

* Update for further error fix

* Update based on AI

* Update script.py

* Update with better coverage and Tool Readme

* Log a message with implicit URI changes

Small update for #542

* Minor fixes (#602)

* Log a message with implicit URI changes

Small update for #542

* Log a message with implicit URI changes

Small update for #542

* Add helper scripts to update forks

* fix: improve HTTP Local URL validation UX and styling specificity

- Rename CSS class from generic "error" to "http-local-url-error" for better specificity
- Rename "invalid-url" class to "http-local-invalid-url" for clarity
- Disable httpServerCommandField when URL is invalid or transport not HTTP Local
- Clear field value and tooltip when showing validation errors
- Ensure field is re-enabled when URL becomes valid

* Docker mcp gateway (#603)

* Log a message with implicit URI changes

Small update for #542

* Update docker container to default to stdio

Replaces #541

* fix: Rider config path and add MCP registry manifest (#604)

- Fix RiderConfigurator to use correct GitHub Copilot config path:
  - Windows: %LOCALAPPDATA%\github-copilot\intellij\mcp.json
  - macOS: ~/Library/Application Support/github-copilot/intellij/mcp.json
  - Linux: ~/.config/github-copilot/intellij/mcp.json
- Add mcp.json for GitHub MCP Registry support:
  - Enables users to install via coplaydev/unity-mcp
  - Uses uvx with mcpforunityserver from PyPI

* Use click.echo instead of print statements

* Standardize whitespace

* Minor tweak in docs

* Use `wait` params

* Unrelated but project scoped tools should be off by default

* Update lock file

* Whitespace cleanup

* Update custom_tool_service.py to skip global registration for any tool name that already exists as a built‑in.

* Avoid silently falling back to the first Unity session when a specific unity_instance was requested but not found.

If a client passes a unity_instance that doesn’t match any session, this code will still route the command to the first available session, which can send commands to the wrong project in multi‑instance environments. Instead, when a unity_instance is provided but no matching session_id is found, return an error (e.g. 400/404 with "Unity instance '' not found") and only default to the first session when no unity_instance was specified.

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Update docs/CLI_USAGE.md

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Updated the CLI command registration to only swallow missing optional modules and to surface real import-time failures, so broken command modules don’t get silently ignored.

* Sorted __all__ alphabetically to satisfy RUF022 in __init__.py.

* Validate --params is a JSON object before merging.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: Shutong Wu <51266340+Scriptwonder@users.noreply.github.com>
Co-authored-by: dsarno <david@lighthaus.us>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.

1 participant