#!/bin/sh
# Start Claude Code with only this room's CRAB MCP server registered:
#   observer room -> the observe server over HTTP (through the egress proxy)
#   clean room    -> the clean server, which talks to the gate
set -e
cfg=/tmp/crab-mcp.json
if [ -n "$CRAB_OBSERVE_URL" ]; then
  python3 - "$cfg" <<'PY'
import json, os, sys
json.dump({"mcpServers": {"crab": {"type": "http", "url": os.environ["CRAB_OBSERVE_URL"],
           "headers": {"Authorization": "Bearer " + os.environ["CRAB_OBSERVE_TOKEN"]}}}}, open(sys.argv[1], "w"))
PY
else
  python3 - "$cfg" <<'PY'
import json, os, sys
json.dump({"mcpServers": {"crab": {"type": "stdio", "command": "crab", "args": [
    "clean", "--gate-url", os.environ["CRAB_GATE_URL"], "--token", os.environ["CRAB_GATE_TOKEN"]]}}},
          open(sys.argv[1], "w"))
PY
fi
exec claude --mcp-config "$cfg" --strict-mcp-config "$@"
