Context7 MCP: Install and Use with Claude Code
Learn what Context7 MCP does, how to install it, and how to connect it with Claude Code or Cursor using API keys or OAuth 2.0.
Understanding Context7 MCP
Context7 MCP connects coding clients to current library documentation. It helps an AI tool find useful docs before it writes or changes code. MCP means Model Context Protocol. It sets a shared way for clients and servers to exchange requests and responses.
Context7 acts as a multi-client platform for programming tools. Claude Code, Cursor, and other MCP clients can use the same service. The Context7 MCP server receives a library request. It then returns focused reference content for the client.
This approach can cut down on old examples and guessed APIs. A model can ask for a library, feature, or version. Context7 then supplies matching context when that library is available. Results still depend on the library index and the request you send.
- Client: The coding tool that sends the request.
- Server: The Context7 service that finds and returns documentation.
- Transport: The connection type, such as local or remote HTTP.
- Credential: An API key or approved OAuth 2.0 session.
For the latest server details, see Context7's official documentation. The service may change its setup commands or endpoint names.

How to Install Context7 MCP
The quickest setup uses the Context7 command line tool. From a shell, run npx ctx7 setup. The command can detect supported clients and add a suitable server entry. Review each change before you use the client.
Automatic setup is helpful on a new machine. Manual setup gives you more control over the server URL and headers. It also helps when your client stores settings in a project folder. Keep secrets outside shared files when your client supports environment variables.
- Open a shell in your project or home folder.
- Run npx ctx7 setup and follow the prompts.
- Choose the client that should use Context7.
- Add your key when the setup tool asks for one.
- Restart the client and test one library request.
A manual entry often needs three fields. These are the server name, the remote URL, and an authentication header. A typical remote endpoint uses https://mcp.context7.com/mcp. Check the current docs before copying that value into production settings.
Local and remote setups are not the same. A local server runs through a command on your computer. A remote server uses an HTTPS address. The client settings must match the transport that the server expects.

How to Add Context7 MCP to Claude Code
Claude Code can add MCP servers from its command line. A common remote setup uses the claude mcp add command. The exact flags can vary by Claude Code release. Use the built-in help command if your version rejects a flag.
One common pattern looks like this:
claude mcp add --transport http context7 https://mcp.context7.com/mcp --x7a1-w831 "CONTEXT7_API_KEY: $CONTEXT7_API_KEY"
Set the environment variable before you run that command. Do not paste a live key into a public script. You can use a project scope when only one codebase needs the server. Use a user scope when several projects need the same connection.
After adding the server, ask Claude Code to find docs for a known library. Name the library and the task in one clear request. For example, ask for current routing setup steps for a named framework. Then check whether the answer uses the returned library context.
- Run claude mcp list to inspect saved servers.
- Run claude mcp get context7 when your version supports that command.
- Use claude mcp remove context7 to delete a bad entry.
- Restart Claude Code after changing credentials or transport settings.
This is the practical answer to how to install Context7 MCP in Claude Code. Add the server, set its header, then test a small documentation request. A small test exposes bad URLs and missing keys early.

Configuring Context7 MCP in Cursor
Cursor usually reads MCP settings from a JSON configuration file. The file may be global or tied to one project. Open Cursor's MCP settings to confirm the path used by your current release.
A remote server entry commonly follows this shape:
{ "mcpServers": { "context7": { "url": "https://mcp.context7.com/mcp", "headers": { "CONTEXT7_API_KEY": "YOUR_KEY" } } } }
Use an environment variable instead of a real key when Cursor supports variable expansion. JSON syntax is strict. Check every quote, comma, and brace if the server fails to load.
Save the file, then reload Cursor or restart its MCP process. Open the MCP panel and confirm that Context7 shows as connected. If the client offers a tool list, look for the Context7 search and documentation tools.
- Use a project setting for a team-specific server.
- Use a global setting for your own repeated work.
- Keep the server URL on HTTPS for remote connections.
- Match the header name shown in the current Context7 guide.
Cursor integration can differ from Claude Code in two key ways. Cursor may expect JSON, while Claude Code may accept a shell command. Cursor may also show connection errors inside its settings panel.

Authentication Options for Context7 MCP
Context7 access can use an API key or OAuth 2.0. An API key is a secret value sent with each approved request. OAuth 2.0 uses a sign-in flow that grants a client limited access.
API keys suit scripts and stable development tools. Store the key in an environment variable or a secret store. Avoid putting it in a repository, screenshot, shell history, or shared configuration file.
OAuth 2.0 can suit clients with built-in browser sign-in. The client opens an approval flow, then stores a token for later requests. The exact steps depend on Context7 and the MCP client version.
| Method | Best fit | Main care point |
|---|---|---|
| API key | Shell commands and fixed setups | Protect and rotate the secret |
| OAuth 2.0 | Clients with account sign-in | Review scope and token expiry |
Do not mix both methods in one test unless the guide says to do so. A stale header can hide a new OAuth problem. Remove old credentials before you test a different method.
Common Problems and Fast Fixes
A failed connection often comes from a small setting error. Start by checking the server URL, transport type, and header name. Then confirm that the client has reloaded its settings.
An authentication error usually means the key is missing, expired, or placed in the wrong field. Test the environment variable in the same shell that runs the setup command. If the value contains special characters, use the quoting rules for your shell.
- Server missing: Check the file path and JSON structure.
- 401 or 403 response: Check the key, scope, or OAuth session.
- Timeout: Check network access and the HTTPS URL.
- No tools appear: Restart the client and inspect its MCP log.
- Old results: Name the library and version in your request.
Remote and local connections also fail in different ways. A local process may lack a runtime or permission. A remote connection may face a firewall, proxy, or DNS issue.
Change one setting at a time. Keep the smallest working request. This makes each error easier to trace.
How to Use Context7 MCP Well
After setup, ask for documentation before asking for a large code change. Include the library name, version, and feature you need. Clear requests give the server better search terms.
A useful request might say, “Find the current authentication guide for package X version Y. Then show a small server example.” This request sets a source, version, and output goal. It also gives Claude Code or Cursor a clear next step.
- Name the library or framework.
- State the version when version choice matters.
- Describe the feature you need to build.
- Ask for a short example or setup plan.
- Check the returned details against your project.
Context7 does not replace code review or tests. Its answer can still miss a breaking change. Treat the returned docs as a strong starting point, not as proof that code will run.
Keep requests narrow when you need reliable output. Ask one focused question first. Then ask for a change after you understand the relevant API.
Additional Context7 MCP Resources
The best source for current commands is the official Context7 guide. Client commands can change faster than server concepts. Check the guide when an example stops working.
Use your client's own MCP help and log tools as a second source. They reveal local paths, scope rules, and transport errors. These details differ between operating systems and client releases.
For the protocol background, the Model Context Protocol documentation explains how clients and servers connect. Read its transport and authorization sections when you need a deeper setup. This helps separate a Context7 issue from a client issue.
In short, install Context7 with the setup command or a manual entry. Add the server URL and a safe credential. Then test a focused library request in Claude Code or Cursor.
Frequently asked questions
- What is Context7 MCP?
- Context7 MCP connects coding clients with focused library documentation. It uses the Model Context Protocol to share requests and responses.
- How do I install Context7 MCP?
- Run npx ctx7 setup for guided setup. You can also add the server URL and authentication header by hand.
- How do I add Context7 MCP to Claude Code?
- Use claude mcp add with the Context7 remote URL and an API key header. Then restart Claude Code and test a focused library request.
- How do I add Context7 MCP to Cursor?
- Add a context7 entry to Cursor's MCP JSON settings. Include the server URL and the required API key header.
- Does Context7 MCP use an API key or OAuth 2.0?
- It can use an API key or OAuth 2.0, depending on the client and current server setup. Follow the current Context7 guide for the chosen flow.
- Why is my Context7 MCP server not connecting?
- Check the URL, transport, header name, and credential first. Then reload the client and inspect its MCP logs.
Related reading
MCP in AI Explained: Meaning, Features, and Uses
Learn what MCP means in AI and why it simplifies data access.
Adding MCP Servers to Claude Code, Desktop, and Cursor
Set up MCP servers with clear steps, safe access, and quick fixes.
RPA and AI: How They Differ and Work Together
See how RPA and AI differ, then learn how they work as one.