Catalog My learning Blog
MCP Setup Guides: Cursor, Codex, Gemini CLI and Top Servers · Phase 2 · Lesson 8 · 3 min read

Context7 MCP Server Setup Guide

On this page
  1. The problem it fixes
  2. Get an API key (optional, but recommended)
  3. Add it to your tool
  4. How the agent uses it
  5. Make the agent actually use it
  6. Check it works
  7. Check yourself

The problem it fixes

You ask an agent to add middleware to a Next.js app and it confidently writes code for an API that was renamed two releases ago. Models learn from a snapshot of the web, and fast-moving libraries change after that snapshot. Context7 fixes this by fetching the current docs for the exact library and version you're using and putting the relevant part into the agent's context.

It's run by Upstash, and it's one of the three servers (with GitHub and Playwright) that nearly every 2026 recommendation list starts with.

Context7 works without a key, with lower rate limits. For daily use, create a free key in the dashboard at context7.com and keep it in an environment variable:

Shell
export CONTEXT7_API_KEY=your-key

Add it to your tool

Context7 is a good server for user scope: you want it in every project, and it doesn't touch your code. Pick the hosted endpoint or the local package.

Claude Code (hosted):

Code
claude mcp add --scope user --transport http context7 https://mcp.context7.com/mcp \
  --header "Authorization: Bearer YOUR_API_KEY"

Claude Code (local package instead):

Code
claude mcp add --scope user context7 -- npx -y @upstash/context7-mcp@4.5.1 --api-key YOUR_API_KEY

Cursor (~/.cursor/mcp.json):

JSON
{
  "mcpServers": {
    "context7": {
      "url": "https://mcp.context7.com/mcp",
      "headers": { "Authorization": "Bearer ${env:CONTEXT7_API_KEY}" }
    }
  }
}

VS Code (.vscode/mcp.json):

JSON
{
  "servers": {
    "context7": {
      "type": "http",
      "url": "https://mcp.context7.com/mcp",
      "headers": { "Authorization": "Bearer YOUR_API_KEY" }
    }
  }
}

Codex CLI passes the key to the local package as an environment variable:

Code
codex mcp add context7 --env CONTEXT7_API_KEY=your-key -- npx -y @upstash/context7-mcp@4.5.1

Gemini CLI:

Code
gemini mcp add -s user -t http context7 https://mcp.context7.com/mcp -H 'Authorization: Bearer $CONTEXT7_API_KEY'

If your client supports MCP OAuth, you can skip the key and use https://mcp.context7.com/mcp/oauth instead. You sign in through the browser on first use.

How the agent uses it

Context7 has just two tools. Listing version 4.5.1's tools with the MCP Inspector returned exactly these:

  1. resolve-library-id turns a name like "supabase" or "next.js" into a Context7 library ID.
  2. query-docs fetches the docs for that library ID that match your question.

The agent calls them in that order. You'll see it look up the library, then pull a few focused sections of the docs before writing code.

Make the agent actually use it

Agents don't always reach for a docs tool on their own. Two habits help:

  • Ask for it. End a prompt with "use context7": "Add a middleware that redirects logged-out users to /login. use context7."
  • Name the library ID when you know it, to skip the lookup: "use library /supabase/supabase for API and docs."

Better still, make it a standing rule. Add a line like this to your CLAUDE.md, or to Cursor's rules under Cursor Settings, Rules:

Code
Always use Context7 when I need library/API documentation, code generation, setup or configuration steps without me having to explicitly ask.

Context7 also has a one-step setup command, npx ctx7 setup, which signs you in, creates a key and installs a matching skill for Cursor or Claude Code. It needs Node.js 22.13 or newer.

Check it works

Ask: "How do I create a server action in the current version of Next.js? use context7." You should see resolve-library-id, then query-docs, then an answer based on the current docs. If you see rate limit errors, add an API key.

Check yourself

Add "use context7" to the prompt, or add the rule to CLAUDE.md or Cursor's rules so the agent checks current docs by default.

It's useful in every project and doesn't depend on any one codebase. User scope sets it up once.

resolve-library-id first, to find the library's ID, then query-docs with that ID and the question.