fix: send ping every 60 seconds, to keep the connection alive

This commit is contained in:
Harshith Mullapudi 2025-08-24 15:52:53 +05:30
parent c488d08483
commit ebf9a0b05e

View File

@ -127,8 +127,20 @@ async function createTransport(
},
});
const keepAlive = setInterval(() => {
try {
transport.send({ jsonrpc: "2.0", method: "ping" });
} catch (e) {
// If sending a ping fails, the connection is likely broken.
// Log the error and clear the interval to prevent further attempts.
logger.error("Failed to send keep-alive ping, cleaning up interval." + e);
clearInterval(keepAlive);
}
}, 60000); // Send ping every 60 seconds
// Setup cleanup on close
transport.onclose = async () => {
clearInterval(keepAlive);
await MCPSessionManager.deleteSession(sessionId);
await TransportManager.cleanupSession(sessionId);
};