Update index.ts

This commit is contained in:
Barry Yip 2025-05-15 01:20:37 +08:00
parent a3e9af1a65
commit c2096ae746
1 changed files with 23 additions and 0 deletions

View File

@ -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);