#!/usr/bin/env node

/**
 * Monday.com MCP Server Entry Point
 * Dual transport (stdio/SSE) with graceful shutdown
 */

import { MondayMCPServer } from "./server.js";

// Validate environment
const MONDAY_API_KEY = process.env.MONDAY_API_KEY;

if (!MONDAY_API_KEY) {
  console.error("Error: MONDAY_API_KEY environment variable is required");
  process.exit(1);
}

// Create and start server
const server = new MondayMCPServer(MONDAY_API_KEY);

// Graceful shutdown
process.on("SIGINT", () => {
  console.error("Received SIGINT, shutting down gracefully...");
  process.exit(0);
});

process.on("SIGTERM", () => {
  console.error("Received SIGTERM, shutting down gracefully...");
  process.exit(0);
});

// Start server
server.run().catch((error) => {
  console.error("Fatal error:", error);
  process.exit(1);
});
