The Context7 MCP server solves a specific problem: LLMs have stale training data. When you’re working with Next.js 15, React 19, or any library that’s evolved since the model’s cutoff date, you get hallucinated APIs and deprecated patterns.
Context7 is an MCP server that injects up-to-date documentation directly into your LLM’s context window. It pulls version-specific docs and code examples from a curated database of library documentation.
The server exposes two MCP tools:
resolve-library-id: Takes a library name (e.g., “next.js”) and returns a Context7 ID (e.g., “/vercel/next.js/v15.0.0”). It matches against a database of libraries, prioritizing by trust score and documentation coverage.
get-library-docs: Takes a Context7 ID and optional topic filter, returns relevant documentation chunks and code examples. You can specify token limits (default 5000, configurable up to your context window).
When your LLM needs library information, it calls these tools automatically. The documentation gets injected into the prompt, so responses are based on current APIs instead of guessing.
Two transport options: HTTP (remote) or stdio (local).
Claude Code:
# Remote (HTTP transport)claude mcp add --transport http context7 https://mcp.context7.com/mcp \ --header "CONTEXT7_API_KEY: YOUR_API_KEY"
# Local (stdio transport)claude mcp add context7 -- npx -y @upstash/context7-mcp --api-key YOUR_API_KEYVS Code / Cursor (~/.cursor/mcp.json):
{ "mcpServers": { "context7": { "command": "npx", "args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"] } }}Windsurf:
{ "mcpServers": { "context7": { "serverUrl": "https://mcp.context7.com/mcp", "headers": { "CONTEXT7_API_KEY": "YOUR_API_KEY" } } }}Get an API key at context7.com.
To make your AI agent automatically use Context7 before planning and coding, add this rule to your project:
Claude Code (CLAUDE.md):
## Context7 Integration
Always use Context7 MCP tools before planning or implementing code that involves external libraries or frameworks:
1. Use `resolve-library-id` to get the correct library identifier2. Use `get-library-docs` to pull current documentation3. Base all code suggestions on the retrieved documentation, not training data
This applies to any library usage, API integration, or framework-specific patterns.Cursor (.cursorrules or Cursor Settings > Rules for AI):
Always use Context7 for library documentation:
- Before suggesting code for any external library, use resolve-library-id and get-library-docs- Never rely on training data for framework APIs (Next.js, React, Vue, etc.)- Pull docs first, then code- Use version-specific documentation when availableWindsurf (.windsurfrules):
Use Context7 MCP for all library/framework code:1. Resolve library ID first2. Fetch current docs with get-library-docs3. Use retrieved docs for code generation4. Never guess API patterns from training dataThis ensures your AI always pulls fresh docs before writing code instead of hallucinating from stale training data.
Say you ask your AI to implement data fetching in Next.js 16. Without Context7, it might suggest:
// Outdated Pages Router pattern (deprecated)export async function getServerSideProps() { const res = await fetch('https://api.example.com/data') const data = await res.json() return { props: { data } }}
export default function Page({ data }) { return <div>{data.title}</div>}With Context7, it queries /vercel/next.js (resolves to latest version), gets current docs, and suggests:
// Current App Router pattern (async Server Components)export default async function Page() { const data = await fetch('https://api.example.com/data') const posts = await data.json()
return ( <ul> {posts.map((post) => ( <li key={post.id}>{post.title}</li> ))} </ul> )}The difference: one works with the current App Router, one doesn’t. Context7 pulled actual API patterns from Next.js 16 docs instead of hallucinating from stale training data.
Most valuable with frameworks that iterate quickly: Next.js, React, Vue, Astro. Also helpful when exploring libraries you haven’t used before—you get working examples on first try instead of debugging hallucinated method signatures.
You can skip the resolution step and specify exact library IDs in your prompts:
Use library /vercel/next.js/v15.4.0-canary.82 for implementing the app router.This bypasses resolve-library-id and goes straight to the version-specific docs you need.