use localhost to ping server if server binds to 0.0.0.0 (#542)
Co-authored-by: vladimir.ivanov <terakriper@gmail.com>main
parent
d2408f07b4
commit
abd596ff4a
|
|
@ -682,16 +682,18 @@ namespace MCPForUnity.Editor.Services.Transport.Transports
|
||||||
throw new InvalidOperationException($"Invalid MCP base URL: {baseUrl}");
|
throw new InvalidOperationException($"Invalid MCP base URL: {baseUrl}");
|
||||||
}
|
}
|
||||||
|
|
||||||
string scheme = httpUri.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase) ? "wss" : "ws";
|
// Replace 0.0.0.0 with localhost for client connections
|
||||||
string builder = $"{scheme}://{httpUri.Authority}";
|
// 0.0.0.0 is only valid for server binding, not client connections
|
||||||
if (!string.IsNullOrEmpty(httpUri.AbsolutePath) && httpUri.AbsolutePath != "/")
|
string host = httpUri.Host == "0.0.0.0" ? "localhost" : httpUri.Host;
|
||||||
|
|
||||||
|
var builder = new UriBuilder(httpUri)
|
||||||
{
|
{
|
||||||
builder += httpUri.AbsolutePath.TrimEnd('/');
|
Scheme = httpUri.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase) ? "wss" : "ws",
|
||||||
}
|
Host = host,
|
||||||
|
Path = httpUri.AbsolutePath.TrimEnd('/') + "/hub/plugin"
|
||||||
|
};
|
||||||
|
|
||||||
builder += "/hub/plugin";
|
return builder.Uri;
|
||||||
|
|
||||||
return new Uri(builder);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue