unity-mcp/MCPForUnity/Editor/Services/Transport
dsarno c2a6b0ac7a
HTTP setup overhaul: transport selection (HTTP local/remote vs stdio), safer lifecycle, cleaner UI, better Claude Code integration (#499)
* Avoid blocking Claude CLI status checks on focus

* Fix Claude Code registration to remove existing server before re-registering

When registering with Claude Code, if a UnityMCP server already exists,
remove it first before adding the new registration. This ensures the
transport mode (HTTP vs stdio) is always updated to match the current
UseHttpTransport EditorPref setting.

Previously, if a stdio registration existed and the user tried to register
with HTTP, the command would fail with 'already exists' and the old stdio
configuration would remain unchanged.

* Fix Claude Code transport validation to parse CLI output format correctly

The validation code was incorrectly parsing the output of 'claude mcp get UnityMCP' by looking for JSON format ("transport": "http"), but the CLI actually returns human-readable text format ("Type: http"). This caused the transport mismatch detection to never trigger, allowing stdio to be selected in the UI while HTTP was registered with Claude Code.

Changes:
- Fix parsing logic to check for "Type: http" or "Type: stdio" in CLI output
- Add OnTransportChanged event to refresh client status when transport changes
- Wire up event handler to trigger client status refresh on transport dropdown change

This ensures that when the transport mode in Unity doesn't match what's registered with Claude Code, the UI will correctly show an error status with instructions to re-register.

* Fix Claude Code registration UI blocking and thread safety issues

This commit resolves three issues with Claude Code registration:

1. UI blocking: Removed synchronous CheckStatus() call after registration
   that was blocking the editor. Status is now set immediately with async
   verification happening in the background.

2. Thread safety: Fixed "can only be called from the main thread" errors
   by capturing Application.dataPath and EditorPrefs.GetBool() on the main
   thread before spawning async status check tasks.

3. Transport mismatch detection: Transport mode changes now trigger immediate
   status checks to detect HTTP/stdio mismatches, instead of waiting for the
   45-second refresh interval.

The registration button now turns green immediately after successful
registration without blocking, and properly detects transport mismatches
when switching between HTTP and stdio modes.

* Enforce thread safety for Claude Code status checks at compile time

Address code review feedback by making CheckStatusWithProjectDir thread-safe
by design rather than by convention:

1. Made projectDir and useHttpTransport parameters non-nullable to prevent
   accidental background thread calls without captured values

2. Removed nullable fallback to EditorPrefs.GetBool() which would cause
   thread safety violations if called from background threads

3. Added ArgumentNullException for null projectDir instead of falling back
   to Application.dataPath (which is main-thread only)

4. Added XML documentation clearly stating threading contracts:
   - CheckStatus() must be called from main thread
   - CheckStatusWithProjectDir() is safe for background threads

5. Removed unreachable else branch in async status check code

These changes make it impossible to misuse the API from background threads,
with compile-time enforcement instead of runtime errors.

* Consolidate local HTTP Start/Stop and auto-start session

* HTTP improvements: Unity-owned server lifecycle + UI polish

* Deterministic HTTP stop via pidfile+token; spawn server in terminal

* Fix review feedback: token validation, host normalization, safer casts

* Fix stop heuristics edge cases; remove dead pid capture

* Fix unity substring guard in stop heuristics

* Fix local server cleanup and connection checks

* Fix read_console default limits; cleanup Unity-managed server vestiges

* Fix unfocused reconnect stalls; fast-fail retryable Unity commands

* Simplify PluginHub reload handling; honor run_tests timeout

* Fix Windows Claude CLI status check threading
2026-01-01 17:08:51 -08:00
..
Transports HTTP setup overhaul: transport selection (HTTP local/remote vs stdio), safer lifecycle, cleaner UI, better Claude Code integration (#499) 2026-01-01 17:08:51 -08:00
IMcpTransportClient.cs HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
IMcpTransportClient.cs.meta HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
TransportCommandDispatcher.cs HTTP setup overhaul: transport selection (HTTP local/remote vs stdio), safer lifecycle, cleaner UI, better Claude Code integration (#499) 2026-01-01 17:08:51 -08:00
TransportCommandDispatcher.cs.meta HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
TransportManager.cs Fix stdio reloads (#402) 2025-11-27 19:33:26 -04:00
TransportManager.cs.meta HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
TransportState.cs HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
TransportState.cs.meta HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
Transports.meta HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00