Context7 MCP: Real-Time Documentation Access for Claude Code
Set up Context7 MCP server for Claude Code. Access up-to-date library documentation directly in your AI coding sessions with Context7.
Problem: Claude Code's training data has a knowledge cutoff. When you ask about React 19, Next.js 15, or any library updated in the last few months, you get outdated patterns or hallucinated APIs that no longer exist.
Quick Win: Add Context7 MCP to your configuration and append "use context7" to any prompt. Claude Code will fetch current documentation before generating code.
What is Context7 MCP?
Context7 MCP is an MCP server that fetches up-to-date, version-specific documentation and code examples directly from library sources. Instead of relying on training data that may be months old, Context7 pulls current docs at query time.
The server works by indexing documentation from official sources. When you reference a library in your prompt, Context7 resolves it to a library ID, fetches the relevant documentation sections, and injects that context into your conversation before Claude generates a response.
Why Context7 for Claude Code?
The core problem Context7 solves: AI models hallucinate APIs. They suggest functions that were renamed, deprecated, or never existed. This happens because training data lags behind library releases.
Context7 MCP eliminates this by providing:
- Current documentation: Fetches docs at query time, not training time
- Version-specific examples: Matches the version you mention in your prompt
- Working code patterns: Examples from official docs that actually compile
- Reduced hallucinations: Claude references real APIs instead of inventing them
When you ask Claude Code about Next.js 15 app router patterns, Context7 fetches the current Next.js 15 documentation. Claude then references actual APIs instead of guessing based on Next.js 13 patterns from its training data.
Installation and Setup
Context7 MCP requires Node.js 18 or higher. The package is @upstash/context7-mcp.
Claude Code CLI
The fastest setup for Claude Code uses the CLI command:
Or add manually to your .mcp.json in your project root:
Claude Desktop
For Claude Desktop on macOS, edit ~/Library/Application Support/Claude/claude_desktop_config.json:
On Windows, the config file is at %APPDATA%\Claude\claude_desktop_config.json.
Alternative: Bun Runtime
If you prefer Bun over Node.js:
Restart Claude Code after adding the configuration.
Using Context7 MCP in Practice
Once installed, Context7 provides two tools that Claude can use:
resolve-library-id: Converts a general library name into a Context7-compatible identifier. Claude uses this when you mention a library by name.
query-docs: Fetches documentation for a specific library. Returns current docs, code examples, and API references.
Basic Usage
Append "use context7" to any prompt where you need current documentation:
Claude Code will:
- Resolve "Next.js" to the library ID
/vercel/next.js - Query Context7 for middleware documentation
- Generate code using current API patterns
Version-Specific Queries
Context7 automatically detects version numbers in your prompt:
The server matches your version mention and returns documentation specific to that release.
Common Library IDs
Context7 uses library IDs in the format /organization/repository. Some frequently used IDs:
| Library | Context7 ID |
|---|---|
| Next.js | /vercel/next.js |
| React | /facebook/react |
| Prisma | /prisma/prisma |
| Supabase | /supabase/supabase |
| Drizzle | /drizzle-team/drizzle-orm |
| tRPC | /trpc/trpc |
| Tailwind | /tailwindlabs/tailwindcss |
| Zod | /colinhacks/zod |
You can skip the resolution step by specifying the library ID directly:
Supported Libraries
Context7 indexes documentation from thousands of libraries. Major supported frameworks include:
Frontend: React, Vue, Svelte, Angular, Solid, Qwik
Meta-frameworks: Next.js, Nuxt, SvelteKit, Astro, Remix
Backend: Express, Fastify, Hono, NestJS, Koa
Databases: Prisma, Drizzle, Mongoose, TypeORM, Supabase
Utilities: Zod, tRPC, React Query, SWR, Zustand, Jotai
Testing: Vitest, Jest, Playwright, Cypress
If a library has public documentation, Context7 likely indexes it. The system continuously updates as libraries release new versions.
Context7 MCP with MCP Tool Search
Claude Code's MCP Tool Search feature works seamlessly with Context7 MCP. With tool search enabled, Context7's tools load on-demand rather than consuming context at session start.
This matters because you can configure Context7 alongside other MCP servers without hitting context limits:
MCP Tool Search loads Context7 only when you mention documentation or use the "use context7" trigger. The rest of the time, it sits idle and costs zero context tokens.
Troubleshooting
ERR_MODULE_NOT_FOUND: Try switching from npx to bunx for better package resolution. Some environments have issues with npm's caching.
Library not found: Not all libraries are indexed. If Context7 cannot resolve a library, it will tell you. Fall back to web search MCP servers for unlisted libraries.
Outdated results: Context7 indexes periodically. Very recent releases (within days) may not be available yet. Check the library's official docs directly for bleeding-edge features.
Next Steps
Context7 MCP transforms Claude Code from a static knowledge base into a research-capable assistant. Combine it with other MCP servers for a complete development environment:
- Learn MCP fundamentals if you are new to the protocol
- Browse 50+ MCP servers for additional capabilities
- Set up web search MCPs for general research beyond library docs
- Enable MCP Tool Search to optimize context usage across all your servers
With Context7 MCP configured, you can trust that Claude Code references current APIs instead of hallucinating deprecated patterns. The "use context7" trigger becomes second nature once you experience the difference in code quality.
Last updated on