Skip to content

Commit fc2b310

Browse files
committed
fix: graceful shutdown logic
1 parent 059cfe1 commit fc2b310

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
55
import express from 'express';
66
import { stdin as input, stdout as output } from 'node:process';
77
import { createInterface } from 'node:readline/promises';
8+
import { promisify } from 'node:util';
89
import { config } from './config/config.js';
910
import { fetchPrompt } from './fetch.prompt.js';
1011
import { fetchTool } from './fetch.tool.js';
@@ -69,8 +70,14 @@ const expressServer = app.listen(config.port);
6970

7071
console.log(`Server is running on port ${config.port.toString()}`);
7172

72-
await createInterface({ input, output }).question('Press enter to exit...\n');
73+
const readline = createInterface({ input, output });
7374

74-
expressServer.close();
75+
await readline.question('Press enter to exit...\n');
76+
77+
readline.close();
78+
79+
expressServer.closeAllConnections();
80+
81+
await promisify(expressServer.close)();
7582

7683
await server.close();

0 commit comments

Comments
 (0)