/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/atlas-mcp-server@2.8.15/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
#!/usr/bin/env node
import{McpServer}from"@modelcontextprotocol/sdk/server/mcp.js";import http from"http";import{config,environment}from"./config/index.js";import{initializeAndStartServer}from"./mcp/server.js";import{closeNeo4jConnection}from"./services/neo4j/index.js";import{logger,requestContextService}from"./utils/index.js";let serverInstance;const shutdown=async e=>{const r=requestContextService.createRequestContext({operation:"Shutdown",signal:e,appName:config.mcpServerName});logger.info(`Received ${e}. Starting graceful shutdown for ${config.mcpServerName}...`,r);try{if(serverInstance){if(serverInstance instanceof McpServer)logger.info("Closing main MCP server (stdio) instance...",r),await serverInstance.close(),logger.info("Main MCP server (stdio) instance closed successfully.",r);else if(serverInstance instanceof http.Server){logger.info("Closing HTTP server instance...",r);const e=serverInstance;await new Promise(((n,t)=>{e.close((e=>{if(e)return logger.error("Error closing HTTP server",e,r),t(e);logger.info("HTTP server instance closed successfully.",r),n()}))}))}}else logger.info("No global MCP server instance to close (expected for HTTP transport or if not yet initialized).",r);logger.info("Closing Neo4j driver connection...",r),await closeNeo4jConnection(),logger.info("Neo4j driver connection closed successfully.",r),logger.info(`Graceful shutdown for ${config.mcpServerName} completed successfully. Exiting.`,r),process.exit(0)}catch(e){logger.error("Critical error during shutdown",e,{...r}),process.exit(1)}},start=async()=>{const e=config.logLevel;let r="info";["debug","info","notice","warning","error","crit","alert","emerg"].includes(e)?r=e:process.stdout.isTTY&&console.warn(`Invalid MCP_LOG_LEVEL "${e}" provided via config/env. Defaulting to "info".`),await logger.initialize(r);const n=requestContextService.createRequestContext({operation:"ConfigLoad"});logger.debug("Configuration loaded successfully",{...n,configValues:config});const t=config.mcpTransportType,o=requestContextService.createRequestContext({operation:`AtlasServerStartup_${t}`,appName:config.mcpServerName,appVersion:config.mcpServerVersion,environment:environment});logger.info(`Starting ${config.mcpServerName} v${config.mcpServerVersion} (Transport: ${t})...`,o);try{logger.debug("Initializing and starting MCP server transport...",o);const e=await initializeAndStartServer();"stdio"===t&&e instanceof McpServer?(serverInstance=e,logger.debug("Stored McpServer instance for stdio transport.",o)):"http"===t&&e instanceof http.Server?(serverInstance=e,logger.debug("Stored HTTP server instance. MCP sessions are per-request.",o)):"http"!==t||e||logger.debug("HTTP transport started. Server instance not returned by initializeAndStartServer. MCP sessions are per-request.",o),logger.info(`${config.mcpServerName} is running with ${t} transport.`,{...o,startTime:(new Date).toISOString()}),process.on("SIGTERM",(()=>shutdown("SIGTERM"))),process.on("SIGINT",(()=>shutdown("SIGINT"))),process.on("uncaughtException",(async e=>{const r={...o,event:"uncaughtException",error:e instanceof Error?e.message:String(e),stack:e instanceof Error?e.stack:void 0};logger.error("Uncaught exception detected. Initiating shutdown...",r),await shutdown("uncaughtException")})),process.on("unhandledRejection",(async e=>{const r={...o,event:"unhandledRejection",reason:e instanceof Error?e.message:String(e),stack:e instanceof Error?e.stack:void 0};logger.error("Unhandled promise rejection detected. Initiating shutdown...",r),await shutdown("unhandledRejection")}))}catch(e){logger.error("Critical error during ATLAS MCP Server startup, exiting.",{...o,finalErrorContext:"Startup Failure",error:e instanceof Error?e.message:String(e),stack:e instanceof Error?e.stack:void 0}),process.exit(1)}};(async()=>{await start()})();
//# sourceMappingURL=/sm/711586e7856baa69c858e19966f44c97ff38e9713ccfef594097e7e88eb0aefc.map