#!/bin/bash
# KGraph launcher — sets up PYTHONPATH and delegates to the right module.
set -euo pipefail
DIR="$(cd "$(dirname "$0")/.." && pwd)"
PYTHON="$DIR/python"

export PYTHONPATH="$DIR/lib/kgraph/src:$DIR/lib/kgraph/scripts:$DIR/lib/site-packages"
export PATH="$DIR/bin:$PATH"

# Default: run MCP server (what npm-shim invokes)
# Subcommands are routed by the CLI module
CMD="${1:-serve}"
shift || true

case "$CMD" in
  init|install|uninstall|detect|serve|status|ingest)
    exec "$PYTHON" -m mcp.server "$CMD" "$@"
    ;;
  *)
    exec "$PYTHON" -m mcp.server "$@"
    ;;
esac
