Preserve original URL

This commit is contained in:
olaservo 2025-04-29 21:32:21 -07:00
commit d16e89df1e
2 changed files with 8 additions and 2 deletions

View file

@ -15,7 +15,11 @@ export type TransportOptions = {
function createSSETransport(options: TransportOptions): Transport { function createSSETransport(options: TransportOptions): Transport {
const baseUrl = new URL(options.url ?? ""); const baseUrl = new URL(options.url ?? "");
// Create new URL while preserving the port from baseUrl
const sseUrl = new URL("/sse", baseUrl); const sseUrl = new URL("/sse", baseUrl);
if (baseUrl.port) {
sseUrl.port = baseUrl.port;
}
return new SSEClientTransport(sseUrl); return new SSEClientTransport(sseUrl);
} }

View file

@ -280,6 +280,8 @@ export function useConnection({
return; return;
} }
let mcpProxyServerUrl; let mcpProxyServerUrl;
const originalUrl = new URL(sseUrl);
switch (transportType) { switch (transportType) {
case "stdio": case "stdio":
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/stdio`); mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/stdio`);
@ -290,12 +292,12 @@ export function useConnection({
case "sse": case "sse":
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/sse`); mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/sse`);
mcpProxyServerUrl.searchParams.append("url", sseUrl); mcpProxyServerUrl.searchParams.append("url", originalUrl.toString());
break; break;
case "streamable-http": case "streamable-http":
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/mcp`); mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/mcp`);
mcpProxyServerUrl.searchParams.append("url", sseUrl); mcpProxyServerUrl.searchParams.append("url", originalUrl.toString());
break; break;
} }
(mcpProxyServerUrl as URL).searchParams.append( (mcpProxyServerUrl as URL).searchParams.append(