Context7 MCP: Stop LLM Hallucinations with Live Docs

Context7 MCP server pulls version-specific library docs into Claude Code, Cursor, and other AI editors. Setup guide and how it works.

Trevor I. Lasn Trevor I. Lasn
Updated 4 min read

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.

Update: get-library-docs is now query-docs

Context7 MCP 2.0.0, released on December 29, 2025, replaced the get-library-docs tool with query-docs. It takes a libraryId and a plain-language query about what you’re trying to do, and the topic, page and token-limit options are gone.

resolve-library-id now needs your question as well as the library name.

The Context7 README also offers a command that configures your agent in one step (Node.js 22.13 or newer):

Terminal window
npx ctx7 setup

The 2.0.0 release notes list every change.

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:

Terminal window
# 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_KEY

VS 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 identifier
2. Use `query-docs` to pull current documentation
3. 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 query-docs
- Never rely on training data for framework APIs (Next.js, React, Vue, etc.)
- Pull docs first, then code
- Use version-specific documentation when available

Windsurf (.windsurfrules):

Use Context7 MCP for all library/framework code:
1. Resolve library ID first
2. Fetch current docs with query-docs
3. Use retrieved docs for code generation
4. Never guess API patterns from training data

This 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.


Trevor I. Lasn

Trevor I. Lasn

Building whiteheap.com and 0xinsider.com.



Related Articles

Check out these related articles that might be useful for you. They cover similar topics and provide additional insights.

MCP
3 min read

Give your AI agent access to your running application. They can see errors, inspect the network tab, check the DOM, and debug issues while you work.

Nov 10, 2025
Read article
Security
4 min read

DeepSeek Harness sends your session log, plugin list and device id to DeepSeek by default. The documented opt-out stops one of four uploads.

Nov 11, 2026
Read article
Tech companies
20 min read

Anthropic's IPO values it near $1.4 trillion. What a moat is, why the Claude models don't have one, whether a rival can crush it, and why I wouldn't short it.

Nov 10, 2026
Read article
MCP
6 min read

Build an MCP server in a Next.js route with mcp-handler and createMcpHandler, then connect it to Claude Code, Gemini CLI, Cursor and other MCP clients.

Jan 28, 2026
Read article
AI agents
6 min read

Superpowers is a plugin for Claude Code that enforces planning, TDD, and debugging workflows. Setup guide with real examples.

Nov 4, 2025
Read article
AI agents
7 min read

What AI agents are, how the agent loop works, and why they're different from chatbots.

Jan 30, 2026
Read article
MCP
3 min read

The Next.js DevTools MCP connects Claude and Cursor to your running dev server. I use it every day.

Nov 2, 2025
Read article
MCP
5 min read

The sequential thinking MCP server has an AI agent reason one numbered thought at a time, revising or branching as it goes. What it does and when it helps.

Sep 7, 2025
Read article
MCP
7 min read

Connect Google Search Console to Claude Code with the mcp-gsc MCP server: setup with uvx, the tools it adds, and the indexing and CTR problems it found.

Feb 15, 2026
Read article

This article was originally published on https://www.trevorlasn.com/blog/context7-mcp. It was written by a human and polished using grammar tools for clarity.