Skip to content

[Bug]: [Windows] Headless server launch always fails with error: The handle is invalid. (os error 6) (regression from #1201/#1188) #1279

Description

@AnaelMaayan

What happened?

On Windows, "Start Server" (and the auto-start path) in the MCP for Unity window fails every time with:

error: The handle is invalid. (os error 6)

This is the entire contents of Library/MCPForUnity/Logs/server-launch-{port}.log — no FastMCP banner, no traceback, nothing else. The (os error N) formatting is uv's/uvx's own Rust error-printing style (Python would say [WinError 6]), so the failure happens inside uvx itself, before it gets anywhere near launching the Python server.

I believe this is a regression from #1201 (fixes #1188 — hides the terminal window on Windows by launching headless via CreateNoWindow = true with no explicit stdio redirection).

Root cause

TerminalLauncher.CreateHeadlessProcessStartInfo (Windows branch) builds:

FileName = "cmd.exe",
Arguments = $"/c \"{command} >> \"{logFilePath}\" 2>&1\"",
UseShellExecute = false,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden

with none of RedirectStandardInput/Output/Error set — the >>/2>&1 redirection is left entirely to cmd.exe's own command-line parsing rather than the ProcessStartInfo.

The Unity Editor process itself is a GUI-subsystem process with no console at all. When it starts a child with CreateNoWindow = true and no stdio redirection, per the Win32 docs for that flag ("the console handle for the application is not set"), the resulting cmd.exe → uvx.exe chain gets no real console. cmd.exe's own >> file 2>&1 redirection gives it a valid stdout/stderr (a real file handle), but stdin is never touched, so uvx.exe inherits a console-less/invalid stdin. uvx then appears to touch that handle early during startup (plausibly for Ctrl-C/TTY setup) and dies immediately with ERROR_INVALID_HANDLE before it ever gets to spawn the Python venv / print anything.

Reproduction steps

  1. On Windows, open a Unity project with MCP for Unity (HTTP transport, default settings).
  2. Window > MCP for Unity > Start Server (or let auto-start trigger it).
  3. Observe: Local HTTP server did not become reachable. with the log containing only error: The handle is invalid. (os error 6).
  4. This is deterministic — every attempt from inside the Unity Editor process fails identically, including with a warm uv cache (so it isn't a first-run download/extraction race).
  5. Confirming it's specific to the console-less parent: copy the exact command Unity prints in the error dialog ("To run it yourself, copy this command into a terminal") and run it via an equivalent ProcessStartInfo (cmd.exe /c "<command> >> log 2>&1", UseShellExecute=false, CreateNoWindow=true, no stdio redirection) but spawned from a process that already owns a console (e.g. a PowerShell/cmd session) instead of from Unity — it starts cleanly every time (FastMCP banner, Uvicorn listening). Running the identical command directly in a terminal ("To run it yourself...") also always works, which is why that fallback advice in the error dialog is misleading here — it works precisely because a terminal has a console, which is the variable that matters.

Suggested fix

Give the child process a real (even if empty) stdin instead of none, e.g. in the Windows branch of CreateHeadlessProcessStartInfo, redirect stdin from NUL:

string winRedirect = $"{command} < NUL >> \"{logFilePath}\" 2>&1";

or set RedirectStandardInput = true on the ProcessStartInfo and immediately close the stream after start. Either should give uvx.exe a valid handle to query instead of none.

Unity version

6000.0.78f1

MCP for Unity package version

10.1.0

Python server version

mcpforunityserver==10.1.0

MCP client

Claude Code

Transport

HTTP (default)

OS

Windows (11)

Relevant logs / console output

Library/MCPForUnity/Logs/server-launch-8080.log:

error: The handle is invalid. (os error 6)

Unity console:

MCP-FOR-UNITY: Local HTTP server did not become reachable. Launch log: C:\...\Library\MCPForUnity\Logs\server-launch-8080.log
error: The handle is invalid. (os error 6)
To run it yourself, copy this command into a terminal:
C:\Users\User\.local\bin\uvx.exe --from "mcpforunityserver==10.1.0" mcp-for-unity --transport http --http-url http://127.0.0.1:8080 --project-scoped-tools
UnityEngine.Debug:LogError (object)
MCPForUnity.Editor.Helpers.McpLog:Error (string) (at ./Library/PackageCache/com.coplaydev.unity-mcp@.../Editor/Helpers/McpLog.cs:50)
MCPForUnity.Editor.Services.ServerManagementService:LogLocalHttpServerLaunchFailure () (at ./Library/PackageCache/com.coplaydev.unity-mcp@.../Editor/Services/ServerManagementService.cs:1053)
MCPForUnity.Editor.Windows.Components.Connection.McpConnectionSection/<TryAutoStartSessionAsync>d__64:MoveNext () (at ./Library/PackageCache/com.coplaydev.unity-mcp@.../Editor/Windows/Components/Connection/McpConnectionSection.cs:798)
...

Checks

  • I searched existing issues and did not find a duplicate
  • I included logs / steps to reproduce

Activity

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