Context7 MCP: Up-to-Date Library Docs for AI Coding Assistants
If you've been using AI coding assistants like Claude Code, Cursor, or VS Code Copilot, you've probably hit this frustrating scenario: you ask for help with a modern framework, and the AI confidently generates code using APIs that no longer exist or were deprecated months ago.
This happens because large language models are trained on data from the past, and frameworks like Next.js, React, and Rails evolve rapidly. The model doesn't know the method it's suggesting was removed six months ago.
Context7 solves this by injecting up-to-date, version-specific documentation directly into your AI's context window. It's an MCP (Model Context Protocol) server from Upstash that fetches the latest official docs and code examples in real time, so your assistant generates working code instead of hallucinated APIs.
This guide walks through installing and configuring Context7 in Cursor, Claude Code, and VS Code, plus how to wire it into an automated deployment from Git workflow once your code is generating cleanly.
Why Every Web Developer Needs Context7
Before the setup, here's why this matters for daily work.
The Problem with AI-Generated Code
When you ask an AI assistant to implement authentication with Supabase or middleware in Next.js 15, it pulls from training data that may be a year or more stale. The result looks correct but fails: the API changed, the method was renamed, or the approach was deprecated. You end up debugging hallucinated code and tab-switching to cross-check docs — losing the productivity AI was supposed to buy you.
How Context7 Changes This
Context7 sits between your AI assistant and current library documentation. When you include "use context7" in a prompt (or set up automatic invocation), the server identifies which library you're asking about, fetches the latest official documentation, and injects the relevant snippets into the model's context. The AI then answers from actual current APIs rather than guessing.
When Context7 Helps — and When It Doesn't
Context7 is not free of cost: each get-library-docs call pulls a chunk of documentation (5000 tokens by default) into your context window, which uses budget and adds latency. Spend it where it pays off:
| Use Context7 for | Skip it for |
|---|---|
| Fast-moving frameworks: Next.js, React, Vue, Astro, Supabase, Tailwind | Stdlib and stable, slow-changing libraries where training data is already accurate |
| Version-specific questions ("App Router in Next.js 15") | Language syntax and well-established patterns |
| Libraries released or majorly revised after the model's training cutoff | Conceptual/architecture questions with no API surface |
Knowing when to skip the doc pull keeps your context window lean and responses fast.
Step 1: Prerequisites
Context7 runs as an MCP server via npx, so you'll need:
- Node.js 18 or higher
- An MCP-compatible client (Cursor, Claude Code, Claude Desktop, VS Code with an MCP extension, Windsurf, or similar)
If you're not sure whether your assistant supports MCP, check its documentation for "MCP servers."
Step 2: Install Context7 for Your Client
The configuration is nearly identical across clients — you're registering the same MCP server. Below are the most common setups.
For Cursor
Cursor is one of the most popular AI-powered editors, and Context7 integrates in a couple of clicks. (If you're new to Cursor's agent and rules workflow, see our full guide on how to use Cursor.)
- Open Settings → Cursor Settings → MCP
- Click Add new global MCP server
- Add this configuration:
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp@latest"]
}
}
}
- Save and restart Cursor
For Claude Code / Claude Desktop
For Claude Desktop, edit your configuration file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
For Claude Code, add the server from the terminal:
claude mcp add context7 -- npx -y @upstash/context7-mcp@latest
To install it for all your projects and pass an API key in one step, use the user scope:
claude mcp add --scope user context7 -- npx -y @upstash/context7-mcp --api-key YOUR_API_KEY
Or add the same JSON block used for Cursor to your config, then restart the client.
For VS Code (with an MCP extension)
- Open your extension's MCP configuration (often
.vscode/mcp.jsonor the extension settings) - Add the same
mcpServersblock shown above
Remote / Hosted Endpoint (no local Node required)
If you can't or don't want to run a local npx process, Context7 also exposes a hosted MCP endpoint at https://mcp.context7.com/mcp. In clients that support remote MCP servers, register the hosted URL instead of the command/args block and pass your key via the CONTEXT7_API_KEY header:
{
"mcpServers": {
"context7": {
"url": "https://mcp.context7.com/mcp",
"headers": {
"CONTEXT7_API_KEY": "YOUR_API_KEY"
}
}
}
}
This is useful in locked-down environments and cloud IDEs where spawning a local process isn't allowed.
Using Smithery CLI (Alternative Method)
You can also install Context7 automatically with the Smithery CLI:
npx -y @smithery/cli@latest install @upstash/context7-mcp --client <CLIENT_NAME> --key <YOUR_SMITHERY_KEY>
Replace <CLIENT_NAME> with your client (e.g. cursor, claude) and get your key from the Smithery.ai dashboard.
Step 3: Configure Automatic Invocation
By default you add "use context7" to trigger a doc fetch. You can instead have your client invoke it automatically for code questions.
In Cursor
Add a rule in .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, Rails, etc.)
- Pull docs first, then code
- Use version-specific documentation when available
In Claude
Add a system prompt or rule:
Always use context7 when I need code generation, setup or configuration steps, or library/API documentation. Automatically use the Context7 MCP tools to resolve library id and get library docs without me asking.
Step 4: Using Context7 in Practice
Basic Usage
Add "use context7" to any coding question:
Create a Next.js middleware that checks for a valid JWT in cookies and redirects unauthenticated users to /login. use context7
Implement basic authentication with Supabase including signup and login. use context7
Specifying Library Versions
For a specific version, use the slash syntax:
Implement data fetching in Next.js using the App Router. use library /vercel/next.js/v15.0.0 for API and docs
A common failure mode: the version you pin doesn't exist in Context7's index, and the tool silently falls back to the latest. If the generated code doesn't match the version you expected, check the tool output — Context7 reports which library ID and version it actually resolved. Verify that before trusting the answer.
How It Works Behind the Scenes
Context7 exposes two MCP tools:
- resolve-library-id — takes a library name ("next.js", "supabase") and returns a Context7 ID pointing to that library's docs
- get-library-docs — takes the Context7 ID and an optional topic filter, returns documentation chunks and code examples (5000 tokens by default, configurable up to your context limit)
When you ask a coding question, the assistant calls these in sequence, retrieves current docs, and answers from them.
Step 5: Best Practices for Context7
- Be specific. "How do I invalidate a query in React Query?" retrieves far more useful docs than "How do I use React?"
- Trust automatic invocation. If you've set up rules, let the AI fetch docs before writing code — the small latency cost buys first-try accuracy.
- Reserve it for fast-moving libraries (see the table above) to keep your context window lean.
- Check library availability. Less common libraries may not be indexed; you can request additions through Context7's project-addition guide.
Step 6: Integrate with Your Deployment Workflow
Once Context7 has you generating accurate, working code, you need a reliable way to ship it.
DeployHQ provides automated deployment from Git to any server — the natural companion to AI-assisted development.
- Create a project in your DeployHQ account
- Connect your repository — deploy from GitHub to your server, GitLab, or Bitbucket
- Configure your server with SSH or SFTP. Unlike platform-locked hosting, you deploy to any VPS or server you control
- Add a build pipeline to compile assets or run tests before release, and enable automatic deployments on push to your main branch
Because DeployHQ ships only changed files and supports zero downtime deployments, the code Context7 helped you get right lands in production cleanly, with full visibility into what changed.
Troubleshooting
Context7 Not Loading
- Verify the configuration JSON (missing commas or brackets are the usual culprits)
- Restart your client after editing the config
- Confirm Node.js 18+ is installed and on your PATH
- Run
npx @upstash/context7-mcp@latestdirectly to confirm the package resolves
Rate Limits
If you hit rate limits, get an API key from context7.com/dashboard for higher limits and private-repo access, then add it to your config with the --api-key flag:
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}
Documentation Not Found
If Context7 can't find a library, check whether it's in the index and submit a request through the project's GitHub repository.
Conclusion
Context7 fixes one of the most frustrating parts of AI-assisted coding: confident-but-broken suggestions built on stale training data. By injecting current, version-specific documentation into the model's context, it turns your assistant into a reliable pair-programming partner. Setup takes a few minutes; the payoff — working code on the first try — is immediate.
Pair it with automated deployment from Git and you get a clean path from editor to production. Start a free DeployHQ trial and connect your first repository in minutes.