lokalise-mcp
Version:
The Lokalise MCP Server brings Lokalise's localization power to Claude and AI assistants—manage projects, keys, and translations by chat.
51 lines (50 loc) • 1.54 kB
JavaScript
/**
* Server Lifecycle Management
* Handles graceful shutdown and cleanup
*/
import { Logger } from "../shared/utils/logger.util.js";
const logger = Logger.forContext("server/lifecycle.ts");
/**
* Set up graceful shutdown handlers
*/
export function setupGracefulShutdown(serverInstance, transportInstance) {
const shutdown = async () => {
try {
logger.info("Shutting down gracefully...");
// Close transport if available
if (transportInstance &&
"close" in transportInstance &&
typeof transportInstance.close === "function") {
await transportInstance.close();
}
// Close server if available
if (serverInstance && typeof serverInstance.close === "function") {
await serverInstance.close();
}
process.exit(0);
}
catch (err) {
logger.error("Error during shutdown", err);
process.exit(1);
}
};
// Register shutdown handlers
["SIGINT", "SIGTERM"].forEach((signal) => {
process.on(signal, () => {
shutdown();
});
});
}
/**
* Set up global error handlers
*/
export function setupErrorHandlers() {
process.on("uncaughtException", (error) => {
logger.error("Uncaught Exception:", error);
process.exit(1);
});
process.on("unhandledRejection", (reason) => {
logger.error("Unhandled Rejection:", reason);
process.exit(1);
});
}