{"record":{"id":"7b6e1f6f5feaf296","repo":"CoplayDev/unity-mcp","slug":"invalid-mcp-base-url-baseurl","errorCode":null,"errorMessage":"Invalid MCP base URL: {baseUrl}","messagePattern":"Invalid MCP base URL: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"MCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.cs","lineNumber":826,"sourceCode":"                    {\n                        _state = TransportState.Connected(TransportDisplayName, sessionId: _sessionId, details: _endpointUri.ToString());\n                        _isConnected = true;\n                        McpLog.Info(\"[WebSocket] Reconnected to MCP server\", false);\n                        return;\n                    }\n                }\n            }\n            finally\n            {\n                Interlocked.Exchange(ref _isReconnectingFlag, 0);\n            }\n        }\n\n        private static Uri BuildWebSocketUri(string baseUrl)\n        {\n            if (!Uri.TryCreate(baseUrl, UriKind.Absolute, out var httpUri))\n            {\n                throw new InvalidOperationException($\"Invalid MCP base URL: {baseUrl}\");\n            }\n\n            // Replace bind-only addresses for client connections\n            // 0.0.0.0 and :: are only valid for server binding, not client connections\n            string host = httpUri.Host;\n            if (host == \"0.0.0.0\")\n            {\n                McpLog.Warn($\"[WebSocket] Base URL host '{host}' is bind-only; using '127.0.0.1' for client connection.\");\n                host = \"127.0.0.1\";\n            }\n            else if (host == \"::\")\n            {\n                McpLog.Warn($\"[WebSocket] Base URL host '{host}' is bind-only; using '::1' for client connection.\");\n                host = \"::1\";\n            }\n\n            var builder = new UriBuilder(httpUri)\n            {","sourceCodeStart":808,"sourceCodeEnd":844,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/MCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.cs#L808-L844","documentation":"Thrown by BuildWebSocketUri when the configured MCP server base URL cannot be parsed as an absolute URI (Uri.TryCreate with UriKind.Absolute fails). The transport needs a valid http:// or https:// URL to convert into a ws:// or wss:// endpoint, after which it rewrites bind-only hosts (0.0.0.0/::) to loopback and appends /hub/plugin. Any input that is not a scheme-prefixed absolute URL is rejected.","triggerScenarios":"Calling Start/connect with a baseUrl that is empty, relative (e.g. 'localhost:6500'), missing its scheme ('//host/path'), or contains characters that break URI parsing. The baseUrl originates from MCP for Unity Advanced Settings (Server URL).","commonSituations":"Developer enters host:port without a scheme in Advanced Settings; a stale config survived a server move; an env var or serialized setting resolved to empty; copy-paste included trailing whitespace or a path fragment.","solutions":["Set the base URL with an explicit scheme, e.g. 'http://127.0.0.1:6500'.","Open MCP for Unity Advanced Settings and correct the Server URL field.","Remove trailing slashes, fragments, or stray characters from the URL.","If driving programmatically, ensure the value is non-empty and absolute before passing it to the transport."],"exampleFix":"// before\nvar baseUrl = \"localhost:6500\";\n// after\nvar baseUrl = \"http://localhost:6500\";","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(baseUrl) || !Uri.TryCreate(baseUrl, UriKind.Absolute, out _))\n{\n    throw new ArgumentException($\"Base URL must be an absolute URI, got: {baseUrl}\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always include the scheme (http/https) when configuring the server URL.","Centralize URL construction/validation so callers cannot pass bare host:port strings.","Surface a friendly UI validation error in Advanced Settings before the transport starts."],"tags":["websocket","config","uri","transport"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}