UNPKG

okta-mcp-server

Version:

Model Context Protocol (MCP) server for Okta API operations with support for bulk operations and caching

80 lines 2.56 kB
#!/usr/bin/env node /** * MCP Server Wrapper with Enhanced Stability * * This wrapper ensures the server: * 1. Stays alive between requests * 2. Doesn't interfere with stdio protocol * 3. Provides proper error handling * 4. Monitors server health */ import { OktaMCPServer } from './core/server.js'; import { protocolSafeLogger as logger } from './utils/protocol-safe-logger.js'; import { loadConfig } from './config/index.js'; // Set MCP server mode to prevent console logging process.env.MCP_SERVER_MODE = 'true'; process.env.MCP_LOG_FILE = 'true'; // Track server state let server = null; let isShuttingDown = false; async function startServer() { try { // Load configuration const config = loadConfig(); // Create server instance server = new OktaMCPServer(config); // Start the server await server.start(); logger.info('Okta MCP Server started successfully'); // Keep the process alive setInterval(() => { // Heartbeat to keep process alive logger.debug('Server heartbeat'); }, 30000); // Every 30 seconds } catch (error) { logger.error('Failed to start server:', error); // Don't output to console to avoid protocol corruption process.exit(1); } } // Graceful shutdown handler async function handleShutdown(signal) { if (isShuttingDown) return; isShuttingDown = true; logger.info(`Received ${signal}, shutting down gracefully...`); if (server) { try { await server.stop(); logger.info('Server stopped successfully'); } catch (error) { logger.error('Error during shutdown:', error); } } process.exit(0); } // Register shutdown handlers process.on('SIGINT', () => handleShutdown('SIGINT')); process.on('SIGTERM', () => handleShutdown('SIGTERM')); process.on('SIGHUP', () => handleShutdown('SIGHUP')); // Handle uncaught errors without outputting to console process.on('uncaughtException', (error) => { logger.error('Uncaught exception:', error); if (!isShuttingDown) { handleShutdown('uncaughtException'); } }); process.on('unhandledRejection', (reason, promise) => { logger.error('Unhandled rejection at:', promise, 'reason:', reason); if (!isShuttingDown) { handleShutdown('unhandledRejection'); } }); // Start the server startServer().catch((error) => { logger.error('Fatal error:', error); process.exit(1); }); //# sourceMappingURL=server-wrapper.js.map