From c2096ae74664ab9b8fd6c8c2146bf7b8d8851851 Mon Sep 17 00:00:00 2001 From: Barry Yip Date: Thu, 15 May 2025 01:20:37 +0800 Subject: [PATCH] Update index.ts --- src/index.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/index.ts b/src/index.ts index 3df61c1..d02a6df 100644 --- a/src/index.ts +++ b/src/index.ts @@ -111,6 +111,29 @@ const mcpServer = new DiscordMCPServer(client, transport); try { await mcpServer.start(); info('MCP server started successfully'); + + // Keep the Node.js process running + if (config.TRANSPORT.toLowerCase() === 'http') { + // Send a heartbeat every 30 seconds to keep the process alive + setInterval(() => { + info('MCP server is running'); + }, 30000); + + // Handle termination signals + process.on('SIGINT', async () => { + info('Received SIGINT. Shutting down server...'); + await mcpServer.stop(); + process.exit(0); + }); + + process.on('SIGTERM', async () => { + info('Received SIGTERM. Shutting down server...'); + await mcpServer.stop(); + process.exit(0); + }); + + info('Server running in keep-alive mode. Press Ctrl+C to stop.'); + } } catch (err) { error('Failed to start MCP server: ' + String(err)); process.exit(1);