Skip to content

Commit 3e7c4b2

Browse files
Use MCP_PROXY_FULL_ADDRESS for SSE transport backed endpoints
The STDIO and SSE transports use SSE between the client and the proxy server. SSE requires the client to initiate the MCP conversation (event-stream) at the endpoint provided by the server. The endpoint provided by the server must obey where the client sees the server, rather than being assumed to be server-root `/message`. The Streamable HTTP endpoint does not need the full proxy address because the response is an event-stream directly, and does not use SSE.
1 parent 618370d commit 3e7c4b2

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

client/src/lib/hooks/useConnection.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,20 @@ export function useConnection({
389389

390390
let mcpProxyServerUrl;
391391
switch (transportType) {
392-
case "stdio":
392+
case "stdio": {
393393
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/stdio`);
394394
mcpProxyServerUrl.searchParams.append("command", command);
395395
mcpProxyServerUrl.searchParams.append("args", args);
396396
mcpProxyServerUrl.searchParams.append("env", JSON.stringify(env));
397+
398+
const proxyFullAddress = config.MCP_PROXY_FULL_ADDRESS
399+
.value as string;
400+
if (proxyFullAddress) {
401+
mcpProxyServerUrl.searchParams.append(
402+
"proxyFullAddress",
403+
proxyFullAddress,
404+
);
405+
}
397406
transportOptions = {
398407
authProvider: serverAuthProvider,
399408
eventSourceInit: {
@@ -411,10 +420,20 @@ export function useConnection({
411420
},
412421
};
413422
break;
423+
}
414424

415-
case "sse":
425+
case "sse": {
416426
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/sse`);
417427
mcpProxyServerUrl.searchParams.append("url", sseUrl);
428+
429+
const proxyFullAddressSSE = config.MCP_PROXY_FULL_ADDRESS
430+
.value as string;
431+
if (proxyFullAddressSSE) {
432+
mcpProxyServerUrl.searchParams.append(
433+
"proxyFullAddress",
434+
proxyFullAddressSSE,
435+
);
436+
}
418437
transportOptions = {
419438
eventSourceInit: {
420439
fetch: (
@@ -431,6 +450,7 @@ export function useConnection({
431450
},
432451
};
433452
break;
453+
}
434454

435455
case "streamable-http":
436456
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/mcp`);

server/src/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,11 @@ app.get(
391391
throw error;
392392
}
393393

394-
const webAppTransport = new SSEServerTransport("/message", res);
394+
const proxyFullAddress = (req.query.proxyFullAddress as string) || "";
395+
const prefix = proxyFullAddress || "";
396+
const endpoint = `${prefix}/message`;
397+
398+
const webAppTransport = new SSEServerTransport(endpoint, res);
395399
console.log("Created client transport");
396400

397401
webAppTransports.set(webAppTransport.sessionId, webAppTransport);
@@ -469,7 +473,11 @@ app.get(
469473
}
470474

471475
if (serverTransport) {
472-
const webAppTransport = new SSEServerTransport("/message", res);
476+
const proxyFullAddress = (req.query.proxyFullAddress as string) || "";
477+
const prefix = proxyFullAddress || "";
478+
const endpoint = `${prefix}/message`;
479+
480+
const webAppTransport = new SSEServerTransport(endpoint, res);
473481
webAppTransports.set(webAppTransport.sessionId, webAppTransport);
474482
console.log("Created client transport");
475483
serverTransports.set(webAppTransport.sessionId, serverTransport!);

0 commit comments

Comments
 (0)