#!/usr/bin/env bash
# Self-diagnosing launcher for the metalworks MCP server.
#
# The plugin's .mcp.json calls `uvx` directly, which works whenever uv is on
# PATH. If you prefer a clearer error when uv is missing, point the .mcp.json
# command at this script instead:
#
#   "command": "${CLAUDE_PLUGIN_ROOT}/bin/launch"
#
# (Bash only; Windows users keep the direct `uvx` command in .mcp.json.)
set -euo pipefail

if ! command -v uvx >/dev/null 2>&1; then
  echo "metalworks: 'uv' is required but was not found on PATH." >&2
  echo "Install it, then restart Claude Code:" >&2
  echo "  curl -LsSf https://astral.sh/uv/install.sh | sh" >&2
  exit 127
fi

export UV_CACHE_DIR="${CLAUDE_PLUGIN_DATA:-$HOME/.cache}/uv-cache"
exec uvx --from "metalworks[mcp,arctic,reddit] @ git+https://github.com/Lab2A/metalworks@main" \
  metalworks mcp serve --transport stdio
