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
This commit is contained in:
cliffhall 2025-06-03 17:46:43 -04:00
commit c485e57a39
2 changed files with 12 additions and 1 deletions

View file

@ -197,7 +197,7 @@ app.post("/mcp", async (req, res) => {
onsessioninitialized: (sessionId) => {
webAppTransports.set(sessionId, webAppTransport);
serverTransports.set(sessionId, serverTransport!);
console.log("New client <-> proxy server sessionId: " + sessionId);
console.log("Client <-> Proxy sessionId: " + sessionId);
},
});
console.log("Created StreamableHttp client transport");

View file

@ -27,6 +27,8 @@ export default function mcpProxy({
let transportToClientClosed = false;
let transportToServerClosed = false;
let reportedServerSession = false;
transportToClient.onmessage = (message) => {
transportToServer.send(message).catch((error) => {
// 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({
};
transportToServer.onmessage = (message) => {
if (!reportedServerSession) {
if (transportToServer.sessionId) {
// Can only report for StreamableHttp
console.error(
"Proxy <-> Server sessionId: " + transportToServer.sessionId,
);
}
reportedServerSession = true;
}
transportToClient.send(message).catch(onClientError);
};