CoplayDev/unity-mcp · error · InvalidOperationException
Failed to register with Claude Code: {stderr} {stdout}
Error message
Failed to register with Claude Code:
{stderr}
{stdout} What it means
RegisterWithCapturedValues() runs `claude mcp add --scope local ...` via ExecPath.TryRun with a 15-second timeout. If the process exits non-zero (TryRun returns false), it throws InvalidOperationException embedding both stderr and stdout. The actual failure reason is in the stderr text — common causes include invalid arguments, authentication errors, scope conflicts, or the binary being present but broken.
Source
Thrown at MCPForUnity/Editor/Clients/McpClientConfiguratorBase.cs:920
else
{
args = $"mcp add --scope local --transport http UnityMCP {httpUrl}";
}
}
else
{
// Use --scope local to register in the project-local config, avoiding conflicts with user-level config (#664)
args = $"mcp add --scope local --transport stdio UnityMCP -- \"{uvxPath}\" {uvxDevFlags}{fromArgs} {packageName}";
}
// Remove any existing registrations from ALL scopes to prevent stale config conflicts (#664)
McpLog.Info("Removing any existing UnityMCP registrations from all scopes before adding...");
RemoveFromAllScopes(claudePath, projectDir, pathPrepend);
// Now add the registration
if (!ExecPath.TryRun(claudePath, args, projectDir, out var stdout, out var stderr, 15000, pathPrepend))
{
throw new InvalidOperationException($"Failed to register with Claude Code:\n{stderr}\n{stdout}");
}
McpLog.Info($"Successfully registered with Claude Code using {(useHttpTransport ? "HTTP" : "stdio")} transport.");
client.SetStatus(McpStatus.Configured);
client.configuredTransport = serverTransport;
}
/// <summary>
/// Thread-safe unregistration using pre-captured values.
/// </summary>
private void UnregisterWithCapturedValues(string projectDir, string claudePath, string pathPrepend)
{
if (string.IsNullOrEmpty(claudePath))
{
throw new InvalidOperationException("Claude CLI not found. Please install Claude Code first.");
}
// Remove from ALL scopes to ensure complete cleanup (#664)View on GitHub (pinned to c21bf496bc)
Solutions
- Read the stderr in the exception message — it contains the exact CLI error.
- Update Claude Code to the latest version: `npm update -g @anthropic-ai/claude-code`.
- Run the exact `claude mcp add` command from GetManualSnippet() manually in a terminal to see the full error output.
- If a stale registration conflicts, run `claude mcp remove UnityMCP` in all scopes before retrying.
- For timeout issues, check if Claude CLI is prompting for input interactively (it cannot in a subprocess).
Defensive patterns
Strategy: try-catch
Try / catch
try { configurator.Configure(); }
catch (InvalidOperationException ex)
{ Debug.LogError($"Claude registration failed:\n{ex.Message}"); ShowManualSnippet(); } Prevention
- Keep Claude Code updated to support current CLI flags (--scope, --transport).
- Remove stale UnityMCP registrations from all scopes before reconfiguring.
- Run the manual `claude mcp add` command in a terminal to diagnose interactively.
When it happens
Trigger: The `claude mcp add` subprocess fails: wrong CLI version (missing --scope or --transport flags), malformed URL, authentication required, the binary exists but errors at runtime, or the 15-second timeout is exceeded.
Common situations: Claude Code CLI version mismatch (older version without --scope local support). The HTTP URL is malformed or unreachable. A stale registration in a different scope blocks the add. The process exceeds the 15-second timeout on a slow machine.
Related errors
- Claude CLI not found. Please install Claude Code first.
- Cherry Studio uses UI-based configuration. Please use the Ma
- OpenClaw config contains non-JSON content and cannot be safe
- uvx not found. Install uv/uvx or set the override in Advance
- uvx not found. Install uv/uvx or set the override in Advance
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/1da71e5adcfb7776.
Report an issue: GitHub.