Documentation · Blog Post

Context7: the fix for coding agents that hallucinate APIs

Your model was trained on last year's docs, and your dependencies weren't frozen there with it. Context7 pipes current, version-specific documentation into the prompt at request time — so the code your agent writes calls APIs that actually exist.

By Mehadi Hasan 6 min read

What it is

Context7, built by Upstash, is an MCP server that solves the most common everyday failure of AI coding: the confident answer written against an outdated or nonexistent API. It maintains parsed, indexed documentation for thousands of libraries and frameworks, and injects the relevant, version-matched slice into your agent's context at prompt time. Over 60k stars, MIT-licensed, and supported in Claude Code, Cursor, Windsurf, Cline, OpenCode, and 30+ other MCP clients.

Usage is almost embarrassingly simple: you write your prompt and append "use context7". The agent resolves the library, pulls the current docs and working code examples, and writes against those instead of its training data.

At a glance

60k+ GitHub stars
1000s Libraries covered
2 MCP tools exposed
MIT License
Upstash Maintainer
Free API key tier

Beyond the MCP server (@upstash/context7-mcp), the project ships a CLI (ctx7), a TypeScript SDK, and a Vercel AI SDK integration — so the same docs pipeline works in agents you build, not just agents you use. Coverage is community-extendable: any public library can be submitted at context7.com.

How it works

Context7 exposes exactly two MCP tools, and the agent chains them on its own:

  1. resolve-library-id — turns a plain library name ("next.js", "supabase") into a Context7 ID like /vercel/next.js, ranked by relevance to your query
  2. query-docs — fetches the documentation for that ID that's relevant to your specific question, version-matched when you name a version in the prompt

The important design choice is that this is retrieval into context, not a search engine the agent has to browse. The docs arrive as focused, pre-cleaned text — no scraping, no nav bars, no token-burning full pages — so the agent reads exactly the part of the manual that answers your question and starts coding.

Example prompts

Create a Next.js middleware that checks for a valid JWT
in cookies and redirects unauthenticated users to /login.
use context7

Configure a Cloudflare Worker to cache JSON responses
for five minutes. use library /cloudflare/docs

Installation

The guided setup detects your client and handles the API key via OAuth:

Guided setup (any client)

npx ctx7 setup

Or wire the hosted server up manually in any MCP client:

Manual (remote MCP server)

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

The API key is free from context7.com/dashboard and buys you higher rate limits; the server works without one at lower limits. Node.js 18+ is the only requirement for the CLI.

Using it day to day

The habit that sticks: any time you're asking for code against a fast-moving dependency — Next.js, Supabase, Tailwind, any AI SDK — append "use context7". It costs two tool calls and saves the debugging session where you discover the suggested config option was renamed two majors ago. If you know exactly which library you mean, skip resolution with use library /supabase/supabase.

Many people go further and put a standing rule in their agent config (CLAUDE.md or equivalent): "when generating code for external libraries, consult Context7 first." That turns it from a habit into infrastructure.

Pricing

The MCP server, CLI, and SDK are MIT-licensed. The hosted docs service has a free tier with a free API key for reasonable personal-use limits; heavier usage tiers are sold at context7.com. For an individual developer, the free tier is realistically all you'll touch.

My take

Context7 attacks the highest-frequency annoyance in AI-assisted coding, and it does it with the least ceremony of anything in this directory — two words appended to a prompt. The quality difference is most visible on recently-released majors: ask for App Router code, Tailwind v4 config, or a current AI SDK integration with and without it, and you'll see exactly what the training-data gap costs.

Its limits are honest ones: it helps with library knowledge, not your private codebase, and coverage quality varies with how good a library's docs are upstream. But as a default-on layer for any project with modern dependencies, it's the cheapest accuracy upgrade available.

Frequently asked questions

Why does my agent need this if it was trained on the docs?

Training data has a cutoff, and libraries don't. A model trained on Next.js 14 will confidently generate Next.js 14 patterns in your Next.js 16 project. Context7 fetches the current, version-matched documentation at prompt time, so the code the agent writes matches the API that actually exists.

Do I need an API key?

A free key from context7.com/dashboard is recommended for higher rate limits, and the npx ctx7 setup flow handles it via OAuth automatically. Without a key you can still use the server at lower limits.

How does the agent actually use it?

Two MCP tools: resolve-library-id turns a library name ("supabase", "next.js") into a Context7 ID, then query-docs pulls the relevant documentation for your specific question into context. In practice you just add "use context7" to a prompt and the agent orchestrates both calls itself.

Which libraries are covered?

Thousands of popular libraries and frameworks, with version-specific docs for the major ones. Coverage is community-extendable — you can submit any project at context7.com if something you depend on is missing.