Skip plugin auto-start in headless batchmode (fix CI / -runTests)#838
Open
nwl9009 wants to merge 1 commit into
Open
Skip plugin auto-start in headless batchmode (fix CI / -runTests)#838nwl9009 wants to merge 1 commit into
nwl9009 wants to merge 1 commit into
Conversation
The Editor plugin auto-starts and connects to the local MCP server on every domain load via
`Startup` ([InitializeOnLoad]). This also fires in headless `-batchmode -runTests`. When the package
is committed to a project whose CI runs headless:
1. The headless instance connects to the same local server as the developer's interactive Editor and
forcibly disconnects the interactive client ("Server forcefully disconnected this plugin. Reason:
Authorization failed.").
2. With no token in a clean CI checkout, the plugin logs an [Error] from a background SignalR
connection callback, which Unity's Test Framework turns into a test failure — failing every
PlayMode test regardless of its own result. It can't be suppressed with
LogAssert.ignoreFailingMessages (the log isn't on the test's main-thread scope).
Fix: return early from `Startup`'s static constructor when `Application.isBatchMode`, so the plugin
neither builds nor connects in headless. Preserves intentional headless use via an opt-in env var
`UNITY_MCP_BATCHMODE=1`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Editor plugin auto-starts and connects to the local MCP server on every domain load via
Startup([InitializeOnLoad]→UnityMcpPluginEditor.Instance.BuildMcpPluginIfNeeded()inEditor/Scripts/Startup.cs). This also fires under headless-batchmode -runTests. When the package is committed to a project whose CI runs Unity headless:McpManagerClientHub: Server forcefully disconnected this plugin. Reason: Authorization failed. Token may be missing, invalid, or revoked.[Error]from a background SignalR connection callback. Unity's Test Framework converts that stray error into a test failure, so every PlayMode test goes red regardless of its own assertions. It can't be suppressed withLogAssert.ignoreFailingMessagesbecause the log isn't raised on the test's main-thread scope.Fix
Return early from
Startup's static constructor whenApplication.isBatchMode, so the plugin neither builds nor connects during headless runs. Intentional headless use (e.g. running the MCP server in CI on purpose) is preserved via an opt-in environment variableUNITY_MCP_BATCHMODE=1.Notes
-runTests. A built-in gate removes that need.🤖 Generated with Claude Code