finops-mcp-server
Version:
MCP server for FinOps Center cost optimization integration
2 lines • 2.23 kB
JavaScript
import{configManager}from"./config-manager.js";import{AuthManager}from"./auth-manager.js";import{FinOpsAPIClient}from"./api-client.js";import{FinOpsMCPHandler}from"./mcp-handler.js";import{createLogger,createPerformanceMonitor}from"./utils/index.js";async function main(){let e,r,n;try{const o=configManager.createConfig();e=createLogger(o),r=createPerformanceMonitor(e),e.info("Starting FinOps MCP Server",{operation:"server_start",version:"1.0.0",environment:o.environment,apiUrl:o.apiUrl}),r.start(6e4);const i=new AuthManager(e);i.initializeWithApiKey(o.apiKey);const s=new FinOpsAPIClient(o,i,e,r);n=new FinOpsMCPHandler(s,o,e),await n.initialize(),await n.start(),e.info("FinOps MCP Server started successfully",{operation:"server_start_success"});const t=async r=>{e.info(`Received ${r}, shutting down gracefully`,{operation:"server_shutdown",signal:r});try{n&&await n.shutdown(),e.info("FinOps MCP Server shutdown completed",{operation:"server_shutdown_success"}),process.exit(0)}catch(r){e.error("Error during shutdown",r,{operation:"server_shutdown_error"}),process.exit(1)}};process.on("SIGINT",()=>t("SIGINT")),process.on("SIGTERM",()=>t("SIGTERM")),process.on("SIGQUIT",()=>t("SIGQUIT")),process.on("uncaughtException",r=>{e.error("Uncaught exception",r,{operation:"uncaught_exception"}),process.exit(1)}),process.on("unhandledRejection",(r,n)=>{e.error("Unhandled promise rejection",new Error(String(r)),{operation:"unhandled_rejection",promise:n.toString()}),process.exit(1)})}catch(r){const n=r instanceof Error?r.message:String(r);if(e&&e.error("Failed to start FinOps MCP Server",r,{operation:"server_start_error"}),(n.includes("Invalid command-line arguments")||n.includes("Configuration validation failed"))&&configManager.showHelp(),"test"===process.env.NODE_ENV)throw r;process.exit(1)}}function handleSpecialFlags(){const e=process.argv.slice(2);(e.includes("--help")||e.includes("-h"))&&(configManager.showHelp(),process.exit(0)),(e.includes("--version")||e.includes("-V"))&&process.exit(0),e.includes("config-examples")&&process.exit(0),0===e.length&&process.exit(1)}export{main,handleSpecialFlags};handleSpecialFlags(),"test"!==process.env.NODE_ENV&&main().catch(e=>{process.exit(1)});