Skip to content

Commit c485e57

Browse files
committed
Add reporting of the Proxy <-> Server sessionId. It's only possible to get the session id for this leg of the proxy if it is a StreamableHttp connection.
* In server/src/index.ts - slight format tweak of the Client <-> Proxy message so that the two messages will line up when displayed * In server/src/mcpProxy.ts - add reportedServerSession boolean initialized to false - in transportToServer.onmessage, - if reportedServerSession isn't set yet, report the sessionId if present on the transport, and then set reportedServerSession to true
1 parent 789c90c commit c485e57

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

server/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ app.post("/mcp", async (req, res) => {
197197
onsessioninitialized: (sessionId) => {
198198
webAppTransports.set(sessionId, webAppTransport);
199199
serverTransports.set(sessionId, serverTransport!);
200-
console.log("New client <-> proxy server sessionId: " + sessionId);
200+
console.log("Client <-> Proxy sessionId: " + sessionId);
201201
},
202202
});
203203
console.log("Created StreamableHttp client transport");

server/src/mcpProxy.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export default function mcpProxy({
2727
let transportToClientClosed = false;
2828
let transportToServerClosed = false;
2929

30+
let reportedServerSession = false;
31+
3032
transportToClient.onmessage = (message) => {
3133
transportToServer.send(message).catch((error) => {
3234
// Send error response back to client if it was a request (has id) and connection is still open
@@ -46,6 +48,15 @@ export default function mcpProxy({
4648
};
4749

4850
transportToServer.onmessage = (message) => {
51+
if (!reportedServerSession) {
52+
if (transportToServer.sessionId) {
53+
// Can only report for StreamableHttp
54+
console.error(
55+
"Proxy <-> Server sessionId: " + transportToServer.sessionId,
56+
);
57+
}
58+
reportedServerSession = true;
59+
}
4960
transportToClient.send(message).catch(onClientError);
5061
};
5162

0 commit comments

Comments
 (0)