Skip to content

[Request] Add explicit Unity port/URL targeting for stdio mode #697

Closed

Description

@gravitydeepimpactsun

Summary

When using mcp-for-unity in --transport stdio mode with multiple Unity Editor instances, there is currently no explicit way to pin the backend to a specific Unity endpoint by port or URL.

This makes routing ambiguous in multi-instance setups and can lead to repeated reconnect loops and lingering Python/MCP processes consuming CPU.


Current behavior

mcp-for-unity supports:

  • --transport stdio|http
  • --http-url / --http-port (HTTP transport only)
  • --default-instance (instance selection)

It does not support explicit Unity endpoint targeting (e.g. --unity-port or --unity-url) when using stdio.


Problem

In real workflows with two or more Unity projects/editors running simultaneously (each with different Unity MCP ports), users often need deterministic routing from one CLI session to one editor.

Instance naming / hash targeting helps, but explicit port/URL pinning would be:

  • simpler to reason about,
  • easier to automate in scripts and configs,
  • less error-prone in multi-instance environments.

Requested feature

Add explicit Unity endpoint targeting flags and environment variables, for example:

CLI

  • --unity-url http://127.0.0.1:6401
  • and/or --unity-port 6401

Environment variables

  • UNITY_MCP_UNITY_URL
  • and/or UNITY_MCP_UNITY_PORT

Behavior

  • Works with --transport stdio.
  • If both instance selection and port/URL are provided, document precedence.
  • Preserve backward compatibility with the existing --default-instance flow.

Why this helps

  • Deterministic selection in multi-Unity sessions.
  • Fewer accidental cross-attachments.
  • Lower chance of retry/spin loops and orphaned background processes.
  • Better DX for tools like OpenCode/Codex where MCP is launched automatically.

Repro context

  • OS: Windows
  • Multiple Unity editors open simultaneously
  • mcp-for-unity launched via uvx in stdio mode
  • Distinct Unity-side MCP ports configured
  • Need a reliable way to bind each CLI session to one Unity instance by endpoint

Activity

  1. added 3 commits that reference this issue on Feb 18, 2026
    628145c
    b87baaf
    0cb5a0d
  2. added a commit that references this issue on Feb 18, 2026
    4055fe5
  3. dsarno commented on Feb 18, 2026

    @dsarno
    Collaborator

    Thanks for filing this @gravitydeepimpactsun! This has been addressed in #772, which takes a slightly different approach than the original CLI flags — instead of requiring --unity-port / --unity-url at startup, you can now pass unity_instance as a parameter on any individual tool call to route it to a specific instance:

    # Route by port (stdio only)
    manage_scene(action="get_active", unity_instance="6402")
    
    # Route by hash prefix
    manage_scene(action="get_active", unity_instance="abc")
    
    # Route by full Name@hash
    manage_scene(action="get_active", unity_instance="MyGame@abc123")

    set_active_instance also now accepts port numbers for session pinning.

    This is merged into the beta branch. If you'd like to try it now, you can point your Unity Package Manager at:
    https://github.com/CoplayDev/unity-mcp.git?path=/MCPForUnity#beta

  4. added 2 commits that reference this issue on Feb 25, 2026
    f630d9f
    d6a4631
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions