refactor: remove inactivity timer and enhance server shutdown handling
This commit is contained in:
parent
9846ccc695
commit
8f0a4fe71b
1 changed files with 6 additions and 25 deletions
|
|
@ -246,41 +246,22 @@ const PromptsListRequestSchema = z.object({
|
||||||
params: z.object({}),
|
params: z.object({}),
|
||||||
});
|
});
|
||||||
|
|
||||||
let inactivityTimer: NodeJS.Timeout | null = null;
|
|
||||||
const INACTIVITY_TIMEOUT = 60000; // 1 minute
|
|
||||||
|
|
||||||
function resetInactivityTimer() {
|
|
||||||
if (inactivityTimer) {
|
|
||||||
clearTimeout(inactivityTimer);
|
|
||||||
}
|
|
||||||
inactivityTimer = setTimeout(() => {
|
|
||||||
// console.log("No activity detected for 30 seconds. Shutting down server...");
|
|
||||||
process.exit(0);
|
|
||||||
}, INACTIVITY_TIMEOUT);
|
|
||||||
}
|
|
||||||
|
|
||||||
server.setRequestHandler(PromptsListRequestSchema, async () => {
|
server.setRequestHandler(PromptsListRequestSchema, async () => {
|
||||||
resetInactivityTimer();
|
|
||||||
return {
|
return {
|
||||||
prompts,
|
prompts,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on("SIGINT", async () => {
|
|
||||||
console.log("Received SIGINT. Shutting down server...");
|
|
||||||
process.exit(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
process.on("SIGTERM", async () => {
|
|
||||||
console.log("Received SIGTERM. Shutting down server...");
|
|
||||||
process.exit(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
async function runServer() {
|
async function runServer() {
|
||||||
await initializePool(connectionString); // Initialize the pool before starting the server
|
await initializePool(connectionString); // Initialize the pool before starting the server
|
||||||
const transport = new StdioServerTransport();
|
const transport = new StdioServerTransport();
|
||||||
await server.connect(transport);
|
await server.connect(transport);
|
||||||
resetInactivityTimer(); // Start the inactivity timer when the server starts
|
|
||||||
}
|
}
|
||||||
|
|
||||||
runServer().catch(console.error);
|
runServer().catch(console.error);
|
||||||
|
|
||||||
|
process.stdin.on("close", () => {
|
||||||
|
console.error("Oracle MCP Server closed");
|
||||||
|
server.close();
|
||||||
|
process.exit(0);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue