Skip to content

Commit 3628abc

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 f22aa1f commit 3628abc

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
@@ -409,11 +409,20 @@ export function useConnection({
409409

410410
let mcpProxyServerUrl;
411411
switch (transportType) {
412-
case "stdio":
412+
case "stdio": {
413413
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/stdio`);
414414
mcpProxyServerUrl.searchParams.append("command", command);
415415
mcpProxyServerUrl.searchParams.append("args", args);
416416
mcpProxyServerUrl.searchParams.append("env", JSON.stringify(env));
417+
418+
const proxyFullAddress = config.MCP_PROXY_FULL_ADDRESS
419+
.value as string;
420+
if (proxyFullAddress) {
421+
mcpProxyServerUrl.searchParams.append(
422+
"proxyFullAddress",
423+
proxyFullAddress,
424+
);
425+
}
417426
transportOptions = {
418427
authProvider: serverAuthProvider,
419428
eventSourceInit: {
@@ -431,10 +440,20 @@ export function useConnection({
431440
},
432441
};
433442
break;
443+
}
434444

435-
case "sse":
445+
case "sse": {
436446
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/sse`);
437447
mcpProxyServerUrl.searchParams.append("url", sseUrl);
448+
449+
const proxyFullAddressSSE = config.MCP_PROXY_FULL_ADDRESS
450+
.value as string;
451+
if (proxyFullAddressSSE) {
452+
mcpProxyServerUrl.searchParams.append(
453+
"proxyFullAddress",
454+
proxyFullAddressSSE,
455+
);
456+
}
438457
transportOptions = {
439458
eventSourceInit: {
440459
fetch: (
@@ -451,6 +470,7 @@ export function useConnection({
451470
},
452471
};
453472
break;
473+
}
454474

455475
case "streamable-http":
456476
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);
@@ -511,7 +515,11 @@ app.get(
511515
}
512516

513517
if (serverTransport) {
514-
const webAppTransport = new SSEServerTransport("/message", res);
518+
const proxyFullAddress = (req.query.proxyFullAddress as string) || "";
519+
const prefix = proxyFullAddress || "";
520+
const endpoint = `${prefix}/message`;
521+
522+
const webAppTransport = new SSEServerTransport(endpoint, res);
515523
webAppTransports.set(webAppTransport.sessionId, webAppTransport);
516524
console.log("Created client transport");
517525
serverTransports.set(webAppTransport.sessionId, serverTransport!);

0 commit comments

Comments
 (0)