Fix a lifecycle bug with server everything in stdio mode (#2848)

This commit is contained in:
Nick Pape 2025-11-25 15:50:31 -06:00 • committed by GitHub
commit 76dcff0617
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -9,14 +9,18 @@ async function main() {
const transport = new StdioServerTransport(); const transport = new StdioServerTransport();
const {server, cleanup, startNotificationIntervals} = createServer(); const {server, cleanup, startNotificationIntervals} = createServer();
// Cleanup when client disconnects
server.onclose = async () => {
await cleanup();
process.exit(0);
};
await server.connect(transport); await server.connect(transport);
startNotificationIntervals(); startNotificationIntervals();
// Cleanup on exit // Cleanup on exit
process.on("SIGINT", async () => { process.on("SIGINT", async () => {
await cleanup(); await server.close();
await server.close();
process.exit(0);
}); });
} }