Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unity_mcp_daemon

HTTP bridge for driving the Unity editor from an external AI agent or script.

It talks to the CoplayDev/unity-mcp server (PyPI package mcpforunityserver) over its REST API and exposes a set of small HTTP services on 127.0.0.1. The server process is spawned automatically via uvx and restarted if it exits.

Why

Calling MCP tools through a chat interface is slow and fragile. This daemon turns Unity automation into plain HTTP calls you can issue from any language or agent framework:

# Run C# in the editor (method body, return value comes back in "result")
$b = @{ code = 'return UnityEngine.Application.version;' } | ConvertTo-Json
Invoke-RestMethod http://127.0.0.1:44903/execute -Method Post -Body $b -ContentType 'application/json'

# Start / stop Play Mode
Invoke-RestMethod http://127.0.0.1:44902/start -Method Post -Body '{}' -ContentType 'application/json'
Invoke-RestMethod http://127.0.0.1:44902/stop  -Method Post -Body '{}' -ContentType 'application/json'

# Read a script from the project
Invoke-RestMethod http://127.0.0.1:44901/read -Method Post -Body '{"path":"Assets/Scripts/Player.cs"}' -ContentType 'application/json'

Prerequisites

  • Unity Editor with the unity-mcp plugin installed into the project.
  • uv installed (irm https://astral.sh/uv/install.ps1 | iex) so the daemon can spawn the server, OR an already-running server started another way (e.g. from the Unity plugin's "Start server" menu).
  • Go 1.20+ to build (or use a pre-built release).

What to install in Unity (step by step)

  1. Open the project in Unity Editor (Unity 6 or 6000.x recommended; the plugin supports recent Unity versions).

  2. Install the unity-mcp plugin — open Window → Package Manager, click the + button in the top-left, choose "Add package from git URL…" and paste:

    https://github.com/CoplayDev/unity-mcp.git?path=/MCPForUnity#main
    

    Wait for the package to finish importing (you'll see a new menu entry Window → MCP for Unity).

    Alternative: clone the repo locally and reference the MCPForUnity subfolder by local path instead of the git URL — useful when git-URL resolution is slow or blocked.

  3. Open the plugin windowWindow → MCP for Unity. In the Server Status section, click Start Server (or run Auto-Setup). This launches the MCP HTTP server (default http://127.0.0.1:8080).

  4. Start the Unity Bridge — in the same window, under Unity Bridge, click Start Bridge. The daemon will then see your editor as a connected instance.

    • Optional: enable Auto-Start on Editor Load in the plugin's Advanced Settings so the bridge starts automatically every time the editor opens.
  5. Verify — with the daemon running, check that it lists the instance:

    Invoke-RestMethod http://127.0.0.1:44900/instances

    You should see your Unity instance in result, and then all ports 44900–44904 are live for the commands shown above.

Configuration

Flags (run with -h to see all):

Flag Default Purpose
-url http://127.0.0.1:8080 Base URL of the Unity MCP server (HTTP transport).
-uvx auto Path to uvx (or uv); auto-detected if empty.
-no-spawn false Do not auto-spawn the server; only proxy to a running one.

uvx is resolved in this order:

  1. -uvx <path> flag
  2. UNITY_MCP_UVX environment variable
  3. uvx on PATH
  4. uv on PATH (used as uv tool run --from mcpforunityserver ...)
  5. Common install locations (%LOCALAPPDATA%\Programs\uv\uvx.exe, %USERPROFILE%\.local\bin\uvx.exe, %LOCALAPPDATA%\Microsoft\WinGet\Links\uvx.exe, %ProgramFiles%\uv\uvx.exe)

If the server is already reachable at -url (e.g. launched by the Unity plugin), the daemon proxies to it and never spawns a second one.

Build & run

go build -o unity_mcp_daemon.exe .
.\unity_mcp_daemon.exe

Order of operations:

  1. Start Unity with the plugin installed and the server + bridge started (see the Unity steps above).
  2. Start the daemon — it detects the already-running server and proxies to it (no second server is spawned).
  3. Call the endpoints on ports 44900–44904 from any script or AI agent.

Point a browser at http://127.0.0.1:44900/ for the full endpoint reference.

Ports

Port Service Purpose
44900 rpc Generic proxy to any server command (/call), plus /instances and /health
44901 scripts Read / create / edit / delete C# scripts (/read, /create, /edit, /delete)
44902 play Play / pause / stop mode and other editor actions (/start, /pause, /stop, /call)
44903 code Execute C# in the editor (/execute, /history, /replay, /clear)
44904 console Read / grep / clear the Unity console (/tail, /grep, /clear)

Every port serves GET / and GET /help with the same documentation.

How it works

  • core.go — daemon core: REST client for the server's /api/command, auto-spawn/restart of the uvx process, connectivity keepalive.
  • goroutines.go — the five HTTP service goroutines (ports 44900–44904) plus path/URI helpers.
  • main.go — entry point, flags, uvx auto-detection.

Each HTTP endpoint maps to one or two Unity MCP commands and answers with a compact JSON body: {"result": {...}, "error": ""}. The error field is filled on transport failures or when the server reports success: false.

Disclaimer

This is an independent project and is not affiliated with, endorsed by, or in any way officially connected with Unity Technologies. See the full disclaimer of liability and trademark notice in DISCLAIMER.md.

License

Apache License 2.0 — see LICENSE.

About

HTTP bridge for driving the Unity editor from an external AI agent/script via the CoplayDev unity-mcp server

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages