How to Install Context7 MCP in Claude Code (2026)
A. Frans
Published June 6, 2026
Table of Contents
Last week I watched Claude Code write a next/og import that has not existed since Next.js 13. It looked right. It compiled in its head. It would have failed the moment I ran it, because the API moved and Claude's training data did not. That gap between what the model remembers and what the library actually ships today is the whole reason Context7 exists.
Context7 is an MCP server from Upstash that fetches current, version-specific documentation and code samples and drops them into Claude's context before it answers. You add four words to a prompt, use context7, and instead of guessing from a months-old snapshot, Claude reads the real docs for the version you are on. The repo lives at github.com/upstash/context7, it is open-source, and you can have it running in about three minutes.
The failure it fixes is specific. A model's training has a cutoff date. Libraries do not stop shipping after that date, so every renamed method, removed export, and changed default that lands afterward is invisible to the model. It fills the gap with its best guess, and a confident wrong guess is worse than an error, because it reads as correct until you run it. Context7 closes that gap by going to the source at request time.
This guide covers all three install paths, how to confirm it loaded, and the one prompt that proves it works.
Pick your install method
There are three ways to wire Context7 into Claude Code. Most people want the first one.
| Method | Command | When to use |
|---|---|---|
| Local (npx) | claude mcp add context7 -- npx -y @upstash/context7-mcp | Default. Runs locally, no account needed. |
| Remote (HTTP) | claude mcp add --transport http context7 https://mcp.context7.com/mcp | You want Upstash to host it, or npx is blocked. |
| Manual config | Edit .mcp.json or claude_desktop_config.json | You version-control your MCP setup or share it with a team. |
npx, so you are running the package directly. The remote method points at Upstash's hosted endpoint, which means no local process but a dependency on their uptime. Manual config is the same thing written to a file you can commit.
If you are deciding between local and remote, here is the short version. Local is fastest to debug because you can run the exact npx command yourself and watch it fail. Remote is better on a corporate laptop where you cannot install Node or where IT blocks npm. Either way the tools Claude sees are identical, so you can switch later without changing how you prompt.
Step 1: Check your prerequisites
You need Claude Code installed and working. Run claude --version to confirm. If that errors, install Claude Code first and come back.
For the local npx method you also need Node.js 18 or newer, since npx ships with it. Check it:
node --version
If you see v18 or higher, you are set. The remote HTTP method skips Node entirely, so it is a good fallback on a locked-down machine where you cannot install runtimes.
Step 2: Install the local (npx) server
This is the path I use. One command from any terminal:
claude mcp add context7 -- npx -y @upstash/context7-mcp
The -- separates Claude's own flags from the command it should run. Everything after it (npx -y @upstash/context7-mcp) is the actual server process. The -y tells npx to install the package without a confirmation prompt, which matters because Claude launches this non-interactively.
By default this adds the server at the local scope, available in the current project. To make it available everywhere, add a user scope:
claude mcp add --scope user context7 -- npx -y @upstash/context7-mcp
Step 3: Or install the remote (HTTP) server
If you would rather not run a local process, point Claude at the hosted endpoint:
claude mcp add --transport http context7 https://mcp.context7.com/mcp
Hit rate limits on the shared endpoint? Generate a free key at context7.com and pass it as a header:
claude mcp add --transport http context7 https://mcp.context7.com/mcp --header "CONTEXT7_API_KEY: your_key_here"
The key travels in the request header, not in any file Claude writes, so it stays out of your project history.
Step 4: Or write the config by hand
When you want the setup committed to the repo so teammates inherit it, drop a .mcp.json at the project root. Local npx version:
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp"]
}
}
}
For Claude Desktop the file is claude_desktop_config.json (on macOS: ~/Library/Application Support/Claude/, on Windows: %APPDATA%\Claude\). The shape is the same. To use the hosted endpoint with a key, reference an environment variable instead of pasting the secret:
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp"],
"env": {
"CONTEXT7_API_KEY": "${CONTEXT7_API_KEY}"
}
}
}
}
That keeps the actual value in your shell environment, so the committed file holds a placeholder and nothing sensitive.
Step 5: Verify it loaded
Open Claude Code and type:
/mcp
You should see context7 in the list of connected servers. Expand it and you will find two tools:
resolve-library-id— turns a library name like "next.js" into the exact ID Context7 indexesget-library-docs— pulls the docs for that ID, scoped to a version and topic
If context7 shows up but the tools do not, the server failed to start. Check that npx runs on its own (npx -y @upstash/context7-mcp in a terminal should print a startup line), and confirm Node is on your PATH. On the remote method, a missing entry usually means a typo in the URL or a network block on mcp.context7.com.
How to use it
Write your prompt as normal, then append use context7. That phrase is the trigger. Try this one:
Create a Next.js 15 middleware that rate-limits by IP. use context7
Claude will call resolve-library-id to match "Next.js 15", then get-library-docs to pull the current middleware and rate-limiting docs, and write the code against what Next.js actually ships, not what it half-remembers. You can also be explicit about the topic: "...rate-limits by IP, use the Upstash ratelimit library. use context7" narrows the fetch.
The difference shows up in the output. Without Context7, Claude might reach for an Express-style req/res signature that Next.js middleware does not use. With it, the docs land first, so the code uses the NextRequest object and the matcher config that the current version expects. You stop being the one who catches the mistake at runtime.
If you forget the trigger phrase, Claude falls back to memory and you lose the benefit. Some people add a line to their project's CLAUDE.md telling Claude to use Context7 for any third-party library work, which makes the behavior automatic instead of something you remember per prompt.
One habit worth building: reach for Context7 whenever you name a specific version. "React 19", "Tailwind v4", "Prisma 6" are exactly the cases where the model's memory and reality drift apart. If you want a wider view of what pairs well with Claude Code, see our roundup for developers.
Security and when it is overkill
Context7 is third-party code. The local method runs @upstash/context7-mcp through npx, which downloads and executes a package on your machine every time it starts. Read the source before you trust it, the repo is public for that reason. If you want a fixed, audited version, pin it: npx -y @upstash/context7-mcp@1.0.0 instead of letting npx grab the latest.
The API key, if you use one, belongs in an environment variable or a request header. Never paste it into a .mcp.json you commit. A leaked Context7 key is low-stakes compared to a cloud credential, but the habit matters across every MCP server you add.
And sometimes you do not need it at all. If you are writing against Python's standard library, plain SQL, or a stable API that has not changed in years, the model already knows it cold. Bolting on a doc fetcher there just spends tokens and adds a step. Context7 earns its place on fast-moving libraries and version-specific work. For a for loop, skip it.
FAQ
Is Context7 free? Yes. It is open-source under MIT and the MCP server costs nothing to run. The hosted endpoint and the npx package both work without payment. The optional API key from context7.com only raises rate limits.
Do I need an API key for Context7? No, not for normal use. Add one only if you start hitting rate-limit errors under heavy or shared traffic. Generate it at context7.com and pass it as a header or env variable, never in a committed file.
Why not just use WebFetch to read the docs? WebFetch grabs one page you name and dumps the raw HTML into context. Context7 resolves the library, finds the version-matched docs, and returns trimmed code examples. Fewer tokens, cleaner snippets, no hunting for the right URL.
Does Context7 work outside Claude Code? Yes. It is a standard MCP server, so Cursor, Windsurf, VS Code with the MCP extension, and Claude Desktop all run it. The config keys differ a little per client, but the same npx command or hosted URL drives every one.
Share this article
⚙Related Tools
📄Related Articles
Get More AI Tool Guides
New comparisons and guides every week. Join thousands of professionals staying ahead of the AI curve.