#!/usr/bin/env node
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { SERVER_CONFIG } from "./constants.js";
import { logError } from "./errors.js";
import { setupResourceHandlers } from "./resources.js";
import { setupToolHandlers } from "./tools.js";
import { getPackageVersion } from "./utils.js";
async function main() {
  const packageVersion = await getPackageVersion();
  const server = new McpServer(
    {
      name: SERVER_CONFIG.SERVER_NAME,
      version: packageVersion
    },
    {
      capabilities: {
        resources: {},
        tools: {}
      }
    }
  );
  setupResourceHandlers(server.server);
  setupToolHandlers(server.server);
  server.server.onerror = (error) => {
    logError(error, "mcpServer");
  };
  process.on("SIGINT", async () => {
    await server.close();
    process.exit(0);
  });
  const transport = new StdioServerTransport();
  await server.connect(transport);
  console.error(`Green Core MCP Server started`);
  console.error(`Version: ${packageVersion}`);
  console.error("Waiting for requests...");
}
main().catch((error) => {
  console.error("Failed to start server:", error);
  process.exit(1);
});
