From 810d756be9fd18cdf5aa68ddcc9baef85a868f4c Mon Sep 17 00:00:00 2001 From: Marcus Sanatan Date: Wed, 21 Jan 2026 14:41:16 -0400 Subject: [PATCH] Minor fixes (#602) * Log a message with implicit URI changes Small update for #542 * Log a message with implicit URI changes Small update for #542 * Add helper scripts to update forks * fix: improve HTTP Local URL validation UX and styling specificity - Rename CSS class from generic "error" to "http-local-url-error" for better specificity - Rename "invalid-url" class to "http-local-invalid-url" for clarity - Disable httpServerCommandField when URL is invalid or transport not HTTP Local - Clear field value and tooltip when showing validation errors - Ensure field is re-enabled when URL becomes valid --- .../Transports/WebSocketTransportClient.cs | 11 ++++++++--- .../Editor/Windows/Components/Common.uss | 2 +- .../Connection/McpConnectionSection.cs | 15 +++++++++------ tools/update_fork.bat | 17 +++++++++++++++++ tools/update_fork.sh | 8 ++++++++ 5 files changed, 43 insertions(+), 10 deletions(-) create mode 100755 tools/update_fork.bat create mode 100755 tools/update_fork.sh diff --git a/MCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.cs b/MCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.cs index 4588e4a..65b4e48 100644 --- a/MCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.cs +++ b/MCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.cs @@ -682,9 +682,14 @@ namespace MCPForUnity.Editor.Services.Transport.Transports throw new InvalidOperationException($"Invalid MCP base URL: {baseUrl}"); } - // Replace 0.0.0.0 with localhost for client connections - // 0.0.0.0 is only valid for server binding, not client connections - string host = httpUri.Host == "0.0.0.0" ? "localhost" : httpUri.Host; + // Replace bind-only addresses with localhost for client connections + // 0.0.0.0 and :: are only valid for server binding, not client connections + string host = httpUri.Host; + if (host == "0.0.0.0" || host == "::") + { + McpLog.Warn($"[WebSocket] Base URL host '{host}' is bind-only; using 'localhost' for client connection."); + host = "localhost"; + } var builder = new UriBuilder(httpUri) { diff --git a/MCPForUnity/Editor/Windows/Components/Common.uss b/MCPForUnity/Editor/Windows/Components/Common.uss index 5aa6e98..fdaa700 100644 --- a/MCPForUnity/Editor/Windows/Components/Common.uss +++ b/MCPForUnity/Editor/Windows/Components/Common.uss @@ -437,7 +437,7 @@ margin-bottom: 4px; } -.help-text.error { +.help-text.http-local-url-error { color: rgba(255, 80, 80, 1); -unity-font-style: bold; } diff --git a/MCPForUnity/Editor/Windows/Components/Connection/McpConnectionSection.cs b/MCPForUnity/Editor/Windows/Components/Connection/McpConnectionSection.cs index 782ed7b..f54dcb8 100644 --- a/MCPForUnity/Editor/Windows/Components/Connection/McpConnectionSection.cs +++ b/MCPForUnity/Editor/Windows/Components/Connection/McpConnectionSection.cs @@ -420,6 +420,7 @@ namespace MCPForUnity.Editor.Windows.Components.Connection httpServerCommandSection.style.display = DisplayStyle.None; httpServerCommandField.value = string.Empty; httpServerCommandField.tooltip = string.Empty; + httpServerCommandField.SetEnabled(false); if (httpServerCommandHint != null) { httpServerCommandHint.text = string.Empty; @@ -435,22 +436,24 @@ namespace MCPForUnity.Editor.Windows.Components.Connection if (!isLocalHttpUrl) { - httpServerCommandField.value = ""; - httpServerCommandField.tooltip = "The command cannot be generated because the URL is not a local address."; - httpServerCommandSection.EnableInClassList("invalid-url", true); + httpServerCommandField.value = string.Empty; + httpServerCommandField.tooltip = string.Empty; + httpServerCommandField.SetEnabled(false); + httpServerCommandSection.EnableInClassList("http-local-invalid-url", true); if (httpServerCommandHint != null) { httpServerCommandHint.text = "⚠ HTTP Local requires a localhost URL (localhost/127.0.0.1/0.0.0.0/::1)."; - httpServerCommandHint.AddToClassList("error"); + httpServerCommandHint.AddToClassList("http-local-url-error"); } copyHttpServerCommandButton?.SetEnabled(false); return; } - httpServerCommandSection.EnableInClassList("invalid-url", false); + httpServerCommandSection.EnableInClassList("http-local-invalid-url", false); + httpServerCommandField.SetEnabled(true); if (httpServerCommandHint != null) { - httpServerCommandHint.RemoveFromClassList("error"); + httpServerCommandHint.RemoveFromClassList("http-local-url-error"); } if (MCPServiceLocator.Server.TryGetLocalHttpServerCommand(out var command, out var error)) diff --git a/tools/update_fork.bat b/tools/update_fork.bat new file mode 100755 index 0000000..db70dd2 --- /dev/null +++ b/tools/update_fork.bat @@ -0,0 +1,17 @@ +@echo off +setlocal + +git checkout main +if errorlevel 1 exit /b 1 + +git fetch -ap upstream +if errorlevel 1 exit /b 1 + +git fetch -ap +if errorlevel 1 exit /b 1 + +git rebase upstream/main +if errorlevel 1 exit /b 1 + +git push +if errorlevel 1 exit /b 1 diff --git a/tools/update_fork.sh b/tools/update_fork.sh new file mode 100755 index 0000000..dab783b --- /dev/null +++ b/tools/update_fork.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail + +git checkout main +git fetch -ap upstream +git fetch -ap +git rebase upstream/main +git push