Tools

Context7: stop AI from coding against outdated APIs

TL;DR

Context7 (Upstash, MIT) fetches up-to-date, version-specific docs and code examples into your agent's context. Install with npx ctx7 setup (choose CLI + Skill or MCP mode), or point an MCP client at https://mcp.context7.com/mcp with an API key. Especially useful for fast-moving frameworks.

You ask an AI to write Next.js middleware and get code using an API that was removed two versions ago. Or it calls a perfectly plausible function… that doesn’t exist. The cause: models have a training cutoff while libraries ship new versions every month. Upstash’s Context7 fixes this by fetching current, version-specific documentation and code examples and putting them straight into the agent’s context when it needs them.

The problems it solves

  • Example code using deprecated or renamed APIs.
  • Hallucinated functions and parameters.
  • Generic answers that don’t match the version you actually use.

How it works

  1. The agent receives a question involving a library (Next.js, Prisma, Tailwind…).
  2. It calls resolve-library-id to identify the right library in Context7 (IDs such as /vercel/next.js).
  3. It calls the docs tool (query-docs) for the topic it needs, optionally pinned to a version.
  4. Context7 returns only the relevant documentation snippets and examples — not the whole docs site — and the agent writes code from them.

The library catalogue is community-contributed and covers thousands of libraries across languages (JavaScript/TypeScript, Python, Ruby…); maintainers can claim and manage their library’s entry.

Installation

Quick: CLI setup

npx ctx7 setup            # OAuth login, creates an API key, configures your clients
npx ctx7 setup --claude   # target Claude Code specifically

Setup offers two modes:

ModeHow it worksChoose when
CLI + SkillInstalls a skill; the agent runs ctx7 commands when it needs docsYou don’t want another MCP server and want a lean context
MCPThe agent calls Context7’s docs tools directlyShared across several clients (Cursor, Claude Desktop, VS Code…)

Manual: remote MCP

claude mcp add --transport http context7 https://mcp.context7.com/mcp \
  --header "CONTEXT7_API_KEY: $CONTEXT7_API_KEY"

Free for personal and educational use; an API key (from the Context7 dashboard) gives higher rate limits and private-repo access. It needs an internet connection, since docs come from Context7’s API.

Usage

The simplest way: add use context7 to the end of your prompt.

Create Next.js middleware that checks a JWT in a cookie
and redirects to /login if the user isn't signed in. use context7

Mention the version in the question to get matching docs:

Set up class-based dark mode with Tailwind CSS 4.0. use context7

Or give the library ID directly to skip the lookup: use library /vercel/next.js.

Tired of typing “use context7”?

Add a rule to CLAUDE.md (or your Cursor rules):

When writing code that uses external libraries/frameworks, or when configuring them,
always look up the docs through Context7 first instead of relying on prior knowledge.

Limitations

  • Community content: documentation is collected and contributed by the community — quality varies; for niche libraries, double-check against official docs.
  • It’s still external content entering your agent’s context — in principle a possible prompt-injection source; keep permission prompts on as usual.
  • It doesn’t replace reading changelogs when upgrading major versions.

How to apply it

  • Developers: Enable Context7 on projects using fast-moving frameworks (Next.js, LangChain, AI SDKs). Add the CLAUDE.md rule so you don’t have to remember.
  • Tech Leads: When the team complains that “AI writes outdated code”, Context7 is the cheapest fix before investing in internal docs for agents.
  • PMs: Fewer “AI writes → build fails → fix” loops means less waiting per feature — especially during library upgrades.

Sources & references

  1. upstash/context7 — GitHub
  2. Context7 guide: stop AI hallucinations with live docs — DeployHQ
  3. context7.com — Upstash