From 659b08aae2271c6d0cae992f3465dfdb58cdad90 Mon Sep 17 00:00:00 2001 From: devjiwonchoi Date: Sun, 22 Mar 2026 23:01:45 +0100 Subject: [PATCH] fix: exit server process when client disconnects Add transport.onclose handler so the server exits when the MCP client closes its stdio connection, preventing orphaned processes from accumulating. --- src/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/index.ts b/src/index.ts index ed9ff03..2737c2a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -330,6 +330,11 @@ async function main() { process.exit(0) } + // Exit when the client disconnects (transport closes) + transport.onclose = () => { + shutdown() + } + process.on('SIGINT', shutdown) process.on('SIGTERM', shutdown) }