All images, scripts and skills

OpenCode: connect to Context7 (MCP)

sh

Registers Context7 as a user-scoped remote MCP server for OpenCode, providing access to current library and framework documentation. The script preserves the existing OpenCode configuration, creates a backup, installs `jq` when needed, and writes the Context7 entry to `~/.config/opencode/opencode.json` (or `$XDG_CONFIG_HOME/opencode/opencode.json`). After it runs, restart OpenCode to load Context7.

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
# Register Context7 as a remote MCP server in OpenCode's user-level config.

set -eu

CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/opencode"
CONFIG_FILE="$CONFIG_DIR/opencode.json"
CONTEXT7_URL="https://mcp.context7.com/mcp"

install_jq() {
  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 apk >/dev/null 2>&1; then
    sudo apk add 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 --non-interactive install jq
  elif command -v brew >/dev/null 2>&1; then
    brew install jq
  else
    echo "Error: jq is required, and no supported package manager was found." >&2
    exit 1
  fi
}

if ! command -v jq >/dev/null 2>&1; then
  echo "jq is not installed; installing it now."
  install_jq
fi

mkdir -p "$CONFIG_DIR"

if [ -f "$CONFIG_FILE" ]; then
  cp "$CONFIG_FILE" "$CONFIG_FILE.bak"
  echo "Existing config backed up to $CONFIG_FILE.bak"
else
  printf '%s\n' '{}' > "$CONFIG_FILE"
fi

if ! jq empty "$CONFIG_FILE" >/dev/null 2>&1; then
  echo "Error: $CONFIG_FILE is not valid JSON; the original file was not changed." >&2
  exit 1
fi

tmp="$(mktemp)"
trap 'rm -f "$tmp"' EXIT HUP INT TERM

jq --arg url "$CONTEXT7_URL" '
  .["$schema"] //= "https://opencode.ai/config.json"
  | .mcp //= {}
  | .mcp.context7 = {
      "type": "remote",
      "url": $url,
      "enabled": true
    }
' "$CONFIG_FILE" > "$tmp"

mv "$tmp" "$CONFIG_FILE"
trap - EXIT HUP INT TERM
chmod 600 "$CONFIG_FILE"

echo "Configured Context7 MCP in $CONFIG_FILE"
echo "Restart OpenCode to load the new MCP server."

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.