Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -682,16 +682,18 @@ private static Uri BuildWebSocketUri(string baseUrl)
throw new InvalidOperationException($"Invalid MCP base URL: {baseUrl}");
}

string scheme = httpUri.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase) ? "wss" : "ws";
string builder = $"{scheme}://{httpUri.Authority}";
if (!string.IsNullOrEmpty(httpUri.AbsolutePath) && httpUri.AbsolutePath != "/")
{
builder += httpUri.AbsolutePath.TrimEnd('/');
}
// 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;

builder += "/hub/plugin";
var builder = new UriBuilder(httpUri)
{
Scheme = httpUri.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase) ? "wss" : "ws",
Host = host,
Path = httpUri.AbsolutePath.TrimEnd('/') + "/hub/plugin"
};

return new Uri(builder);
return builder.Uri;
}
}
}