From 2730926ba6ed035dac1d5887d75ea62d5b0fd294 Mon Sep 17 00:00:00 2001 From: enesgules Date: Tue, 9 Sep 2025 16:14:38 +0300 Subject: [PATCH] feat: add cleanup handlers for transport and server on request close --- src/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/index.ts b/src/index.ts index 5a81cc3..310e339 100644 --- a/src/index.ts +++ b/src/index.ts @@ -320,6 +320,10 @@ async function main() { const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined, }); + res.on("close", () => { + transport.close(); + requestServer.close(); + }); await requestServer.connect(transport); await transport.handleRequest(req, res); } else if (url === "/sse" && req.method === "GET") { @@ -330,6 +334,8 @@ async function main() { // Clean up transport when connection closes res.on("close", () => { delete sseTransports[sseTransport.sessionId]; + sseTransport.close(); + requestServer.close(); }); await requestServer.connect(sseTransport); } else if (url === "/messages" && req.method === "POST") {