unity-mcp/MCPForUnity
dsarno 39bff4ae27
Fix PlayMode tests stalling when unfocused (python refresh utility), improve domain reload recovery and refresh tool (#554)
* Fix test job state management after domain reload

- TestRunnerService.RunFinished: Always clean up job state even when
  _runCompletionSource is null (happens after PlayMode domain reload)
- TestJobManager: Detect and clear stale jobs (5+ min without updates)
  on startup to recover from stuck state after domain reload
- refresh_unity.py: Add "could not connect" to retryable errors when
  wait_for_ready=True, so connection failures during domain reload
  trigger waiting instead of immediate failure

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add focus nudge to handle OS-level throttling during PlayMode tests

When Unity is unfocused, macOS App Nap (and similar OS features) can
throttle the process, causing PlayMode tests to stall even with Unity
No Throttling mode enabled.

Changes:
- Add ApplyNoThrottlingPreemptive() to TestRunnerNoThrottle for early
  throttle prevention before PlayMode Execute()
- Add focus_nudge.py utility that temporarily focuses Unity and returns
  focus to the original app (supports macOS, Windows, Linux)
- Integrate focus nudge into get_test_job polling - when tests appear
  stalled (unfocused + no progress for 10s), automatically nudge Unity

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix code review issues in focus_nudge.py

- Remove redundant time import (already imported at module level)
- Escape window titles in PowerShell script to prevent injection
- Remove unused Callable import

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Improve focus nudge logging and fix skipped tests

- Improve logging in focus_nudge.py: rate limit skip and focus return at INFO level
- Improve logging in run_tests.py: show nudge completion status
- Fix path resolution in test_logging_stdout.py and test_transport_framing.py
- Add PlayMode tests to UnityMCPTests project for testing PlayMode runner

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add troubleshooting note about focus permission requests

When running PlayMode tests with Unity in the background, the focus
nudge feature may trigger OS permission prompts (especially on macOS
for accessibility/automation). Document this expected behavior.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 15:02:40 -08:00
..
Editor Fix PlayMode tests stalling when unfocused (python refresh utility), improve domain reload recovery and refresh tool (#554) 2026-01-14 15:02:40 -08:00
Runtime Fix manage_components set_property for object references (#551) 2026-01-13 22:23:18 -08:00
Editor.meta Rename plugin folder to MCPForUnity (#303) 2025-10-03 20:23:28 -04:00
README.md HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
README.md.meta Rename plugin folder to MCPForUnity (#303) 2025-10-03 20:23:28 -04:00
Runtime.meta Rename plugin folder to MCPForUnity (#303) 2025-10-03 20:23:28 -04:00
package.json chore: bump version to 9.0.3 2026-01-08 16:01:52 +00:00
package.json.meta Add .meta files (#472) 2025-12-19 18:59:19 -04:00

README.md

MCP for Unity — Editor Plugin Guide

Use this guide to configure and run MCP for Unity inside the Unity Editor. Installation is covered elsewhere; this document focuses on the Editor window, client configuration, and troubleshooting.

Open the window

  • Unity menu: Window > MCP for Unity

The window has four areas: Server Status, Unity Bridge, MCP Client Configuration, and Script Validation.


Quick start

  1. Open Window > MCP for Unity.
  2. Click “Auto-Setup”.
  3. If prompted:
    • Select the packaged server folder (Server) if you want to run the bundled implementation.
    • Install Python and/or uv/uvx if missing so the server can be managed locally.
    • For Claude Code, ensure the claude CLI is installed.
  4. Click “Start Bridge” if the Unity Bridge shows “Stopped”.
  5. Use your MCP client (Cursor, VS Code, Windsurf, Claude Code) to connect.

Server Status

  • Status dot and label:
    • Installed / Installed (Embedded) / Not Installed.
  • Mode and ports:
    • Mode: Auto or Standard.
    • Ports: Unity (varies; shown in UI), MCP 6500.
  • Actions:
    • Auto-Setup: Registers/updates your selected MCP client(s), ensures bridge connectivity. Shows “Connected ✓” after success.
    • Rebuild MCP Server: Rebuilds the Python based MCP server
    • Select server folder…: Choose the folder containing server.py.
    • Verify again: Re-checks server presence.
    • If Python isnt detected, use “Open Install Instructions”.
  • HTTP Server Command foldout:
    • Expands to display the exact uvx command Unity will run.
    • Includes a copy button and the “Start Local HTTP Server” action so you can launch or reuse the command elsewhere.

Unity Bridge

  • Shows Running or Stopped with a status dot.
  • Start/Stop Bridge button toggles the Unity bridge process used by MCP clients to talk to Unity.
  • Tip: After Auto-Setup, the bridge may auto-start in Auto mode.

MCP Client Configuration

  • Select Client: Choose your target MCP client (e.g., Cursor, VS Code, Windsurf, Claude Code).
  • Per-client actions:
    • Cursor / VS Code / Windsurf:
      • Auto Configure: Writes/updates your config to launch the server via uvx with the current package version:
        • Command: uvx (or your overridden path)
        • Args: --from mcp-for-unity
      • Manual Setup: Opens a window with a pre-filled JSON snippet to copy/paste into your client config.
      • Choose UV Install Location: If uv/uvx isnt on PATH, select the executable.
      • A compact “Config:” line shows the resolved config file name once uv/server are detected.
    • Claude Code:
      • Register with Claude Code / Unregister MCP for Unity with Claude Code.
      • If the CLI isnt found, click “Choose Claude Install Location”.
      • The window displays the resolved Claude CLI path when detected.

Notes:

  • The UI shows a status dot and a short status text (e.g., “Configured”, “uv Not Found”, “Claude Not Found”).
  • Use “Auto Configure” for one-click setup; use “Manual Setup” when you prefer to review/copy config.

Script Validation

  • Validation Level options:
    • Basic — Only syntax checks
    • Standard — Syntax + Unity practices
    • Comprehensive — All checks + semantic analysis
    • Strict — Full semantic validation (requires Roslyn)
  • Pick a level based on your projects needs. A description is shown under the dropdown.

Troubleshooting


Tips

  • Use Cmd+Shift+M (macOS) / Ctrl+Shift+M (Windows, Linux) to toggle the MCP for Unity window.
  • Enable “Show Debug Logs” in the header for more details in the Console when diagnosing issues.