#!/usr/bin/env node
"use strict";

/**
 * OpenClaw MCP Tools — entry point.
 *
 * Provides MCP knowledge base utilities.
 * Usage: openclaw-mcp <command> [options]
 */

const VERSION = require("../package.json").version;

function printUsage() {
  console.log(`OpenClaw MCP Tools v${VERSION}`);
  console.log("");
  console.log("Usage: openclaw-mcp <command> [options]");
  console.log("");
  console.log("Commands:");
  console.log("  serve     Start the MCP tool server");
  console.log("  list      List available MCP tools");
  console.log("");
  console.log("Options:");
  console.log("  --version    Show version number");
  console.log("  --help       Show this help message");
}

const args = process.argv.slice(2);

if (args.includes("--version") || args.includes("-v")) {
  console.log(`openclaw-mcp v${VERSION}`);
  process.exit(0);
}

if (args.length === 0 || args.includes("--help") || args.includes("-h")) {
  printUsage();
  process.exit(0);
}

const command = args[0];
const subArgs = args.slice(1);

switch (command) {
  case "serve":
    require("../lib/server").serve(subArgs);
    break;
  case "list":
    require("../lib/server").list(subArgs);
    break;
  default:
    console.error(`Unknown command: ${command}`);
    console.error('Run "openclaw-mcp --help" for usage.');
    process.exit(1);
}
