All images and scripts

Opencode controller setup

sh1 included script

What it asks for

What it runs

The whole script, exactly as it will execute in your workspace. Nothing is hidden — read it before you run it.

#!/usr/bin/env sh
# Add the "DevGrail" MCP server to OpenCode (user/global scope)

set -eu

if [ -z "${DEVGRAIL_MCP_URL:-}" ]; then
  echo "Error: DEVGRAIL_MCP_URL is not set." >&2
  echo "This container predates the variable — recreate it (or upgrade its image) to pick it up." >&2
  exit 1
fi

CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/opencode"
CONFIG_FILE="$CONFIG_DIR/opencode.json"

mkdir -p "$CONFIG_DIR"

DEVGRAIL="$(cat <<EOF
{
  "type": "remote",
  "url": "$DEVGRAIL_MCP_URL",
  "enabled": true,
  "headers": {
    "Authorization": "Bearer $API_KEY"
  }
}
EOF
)"

if [ -f "$CONFIG_FILE" ]; then
  echo "Found existing config: $CONFIG_FILE"
  cp "$CONFIG_FILE" "$CONFIG_FILE.bak"
  echo "Backed up to $CONFIG_FILE.bak"
else
  echo "No config found; creating $CONFIG_FILE"
  printf '%s\n' '{ "$schema": "https://opencode.ai/config.json" }' > "$CONFIG_FILE"
fi

if command -v jq >/dev/null 2>&1; then
  tmp="$(mktemp)"
  jq --argjson srv "$DEVGRAIL" \
    '.["$schema"] //= "https://opencode.ai/config.json"
     | .mcp //= {}
     | .mcp.devgrail = $srv' \
    "$CONFIG_FILE" > "$tmp"
  mv "$tmp" "$CONFIG_FILE"
  echo "DEVGRAIL added via jq."
else
  if [ -s "$CONFIG_FILE" ] && grep -q '"mcp"' "$CONFIG_FILE" 2>/dev/null; then
    echo "jq not installed and an 'mcp' block already exists." >&2
    echo "Install jq, or add this under 'mcp' in $CONFIG_FILE manually:" >&2
    echo "  \"DEVGRAIL\": $DEVGRAIL" >&2
    exit 1
  fi
  cat > "$CONFIG_FILE" <<EOF
{
  "\$schema": "https://opencode.ai/config.json",
  "mcp": {
    "DEVGRAIL": $DEVGRAIL
  }
}
EOF
  echo "DEVGRAIL written (jq not found, used full template)."
fi

echo
echo "Done. Current config:"
cat "$CONFIG_FILE"
echo
echo "Restart OpenCode (or start a new session) to load DEVGRAIL."

Included scripts

These come along automatically when you add this script.

Opencode setup
#!/usr/bin/env sh
# Set up the context7 MCP server for OpenCode (no API key).
# Merges into ~/.config/opencode/opencode.json, preserving existing config.

set -eu

# Install jq if missing
if ! command -v jq >/dev/null 2>&1; then
    if command -v apt-get >/dev/null 2>&1; then
        sudo apt-get update
        sudo apt-get install -y jq
    elif command -v dnf >/dev/null 2>&1; then
        sudo dnf install -y jq
    elif command -v yum >/dev/null 2>&1; then
        sudo yum install -y jq
    elif command -v pacman >/dev/null 2>&1; then
        sudo pacman -Sy --noconfirm jq
    elif command -v zypper >/dev/null 2>&1; then
        sudo zypper install -y jq
    elif command -v brew >/dev/null 2>&1; then
        brew install jq
    else
        echo "Error: could not find a supported package manager to install jq."
        exit 1
    fi
fi

CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/opencode"
CONFIG_FILE="$CONFIG_DIR/opencode.json"

mkdir -p "$CONFIG_DIR"

# The context7 server entry we want to ensure exists.
CONTEXT7='{
  "type": "remote",
  "url": "https://mcp.context7.com/mcp",
  "enabled": true
}'

if [ -f "$CONFIG_FILE" ]; then
  echo "Found existing config: $CONFIG_FILE"
  cp "$CONFIG_FILE" "$CONFIG_FILE.bak"
  echo "Backed up to $CONFIG_FILE.bak"
else
  echo "No config found; creating $CONFIG_FILE"
  printf '%s\n' '{ "$schema": "https://opencode.ai/config.json" }' > "$CONFIG_FILE"
fi

if command -v jq >/dev/null 2>&1; then
  tmp="$(mktemp)"
  jq --argjson srv "$CONTEXT7" \
    '.["$schema"] //= "https://opencode.ai/config.json"
     | .mcp //= {}
     | .mcp.context7 = $srv' \
    "$CONFIG_FILE" > "$tmp"
  mv "$tmp" "$CONFIG_FILE"
  echo "context7 added via jq."
else
  # No jq: only safe to write if the file is empty/new. Otherwise bail.
  if [ -s "$CONFIG_FILE" ] && grep -q '"mcp"' "$CONFIG_FILE" 2>/dev/null; then
    echo "jq not installed and an 'mcp' block already exists." >&2
    echo "Install jq, or add this to 'mcp' in $CONFIG_FILE manually:" >&2
    echo "  \"context7\": $CONTEXT7" >&2
    exit 1
  fi
  cat > "$CONFIG_FILE" <<'EOF'
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "context7": {
      "type": "remote",
      "url": "https://mcp.context7.com/mcp",
      "enabled": true
    }
  }
}
EOF
  echo "context7 written (jq not found, used full template)."
fi

echo
echo "Done. Current config:"
cat "$CONFIG_FILE"
echo
echo "Restart OpenCode (or start a new session) to load context7."

How to get it

Open your DevGrail workspace, go to Scripts → Official scripts, and choose Download. It is copied into your own library, where you can edit it, run it, or set it as a workspace default — the copy is yours, and later changes here do not touch it.