All images, scripts and skills

Codex: connect to Context7 (MCP)

sh

Registers Context7 for Codex as a non-interactive stdio MCP server using `npx -y @upstash/context7-mcp`. If Context7 is already configured with another non-HTTP registration, the script leaves it untouched. If it finds the old `https://mcp.context7.com/mcp` registration that starts an OAuth callback flow in headless containers, it replaces that entry with the stdio transport. Requires `codex` and `npx` on PATH. After it runs, restart Codex to use Context7 for current library and framework documentation.

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
set -eu
umask 077

log() { printf '[context7-mcp] %s\n' "$*"; }
die() { printf '[context7-mcp] ERROR: %s\n' "$*" >&2; exit 1; }

CODEX_DIR="${CODEX_HOME:-$HOME/.codex}"
NEED_CONTEXT7="yes"
CONTEXT7_INFO="$CODEX_DIR/context7.devgrail.tmp"

command -v codex >/dev/null 2>&1 \
    || die "the 'codex' CLI is not on PATH — run this in a workspace that has Codex installed"
command -v npx >/dev/null 2>&1 \
    || die "Context7 setup requires 'npx', but it is not on PATH"

mkdir -p "$CODEX_DIR"
trap 'rm -f "$CONTEXT7_INFO"' 0

if codex mcp get context7 >"$CONTEXT7_INFO" 2>/dev/null; then
    if grep -Fq 'https://mcp.context7.com/mcp' "$CONTEXT7_INFO"; then
        # Migrate the old HTTP registration, which starts an OAuth callback
        # flow and stalls in headless containers.
        codex mcp remove context7 </dev/null >/dev/null 2>&1 \
            || die "could not remove the previous HTTP Context7 registration"
        log "removed the previous HTTP Context7 registration"
    else
        NEED_CONTEXT7="no"
        log "MCP server 'context7' is already registered — nothing to do"
    fi
fi

rm -f "$CONTEXT7_INFO"
trap - 0

if [ "$NEED_CONTEXT7" = "yes" ]; then
    codex mcp add context7 -- npx -y @upstash/context7-mcp </dev/null \
        || die "codex mcp add context7 failed"
    log "added MCP server 'context7' using the non-interactive stdio transport"
fi

log "done. Restart Codex, then use Context7 for current library and framework documentation."

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.