Skip to main content

Claude Code Setup

Install Context7 MCP Server in Claude Code to access up-to-date documentation and code examples directly in your AI coding sessions.

Prerequisites

While Context7 works without an API key, we recommend getting a free API key for higher rate limits.

Installation Methods

Claude Code supports both local and remote MCP server connections via the claude mcp add command.

Automated Setup

Use the Context7 CLI for automated setup:
npx ctx7 setup --claude
This command:
  • Authenticates via OAuth
  • Generates an API key
  • Configures the MCP server via claude mcp add
  • Sets up recommended rules in CLAUDE.md

Verify Installation

1

List MCP Servers

Check that Context7 is installed:
claude mcp list
You should see context7 in the list of configured servers.
2

Start Claude Code Session

Start a new coding session:
claude
3

Test with a Prompt

Try a prompt like:
Create a Next.js middleware that checks for a valid JWT. use context7
You should see Context7 tools being invoked and documentation being retrieved.
To avoid typing use context7 in every prompt, add an automatic invocation rule to your CLAUDE.md file.

Global Rule

Create or edit ~/.config/claude/CLAUDE.md:
CLAUDE.md
# Context7 Auto-Invocation

Always use Context7 MCP when I need library/API documentation, code generation, 
setup or configuration steps without me having to explicitly ask.

Project-Specific Rule

Create CLAUDE.md in your project root:
CLAUDE.md
# Project Rules

Always use Context7 MCP when I need library/API documentation, code generation, 
setup or configuration steps without me having to explicitly ask.

Managing Installation

Update Context7

For local installations using npx, Context7 automatically uses the latest version. For pinned versions:
# Remove existing installation
claude mcp remove context7

# Reinstall latest version
claude mcp add --scope user context7 -- npx -y @upstash/context7-mcp --api-key YOUR_API_KEY

Remove Context7

claude mcp remove context7

View Configuration

claude mcp show context7

Troubleshooting

  1. Verify the installation command completed successfully
  2. Run claude mcp list to check registered servers
  3. Try removing and reinstalling: claude mcp remove context7 then reinstall
  1. Verify your API key is correct (should start with ctx7sk)
  2. Ensure the API key is properly quoted in the command
  3. Try regenerating your API key at context7.com/dashboard
  4. For remote connections, check the header name is CONTEXT7_API_KEY
  1. Ensure Node.js is installed: node --version
  2. Clear npx cache: npx clear-npx-cache
  3. Test manual execution: npx -y @upstash/context7-mcp
  4. Check Claude Code logs for error messages
  1. Verify internet connectivity
  2. Check that the URL is correct: https://mcp.context7.com/mcp
  3. Test the endpoint: curl https://mcp.context7.com/ping
  4. Ensure firewall allows HTTPS connections
  1. Get a free API key at context7.com/dashboard
  2. Check your usage and quota on the dashboard
  3. Consider upgrading to a paid plan at context7.com/plans
  1. Add use context7 explicitly to your prompt
  2. Check that your CLAUDE.md rule is properly formatted
  3. Verify Context7 server is running: claude mcp list
  4. Try restarting Claude Code

Advanced Configuration

Using Environment Variables

Store your API key in an environment variable:
# Add to ~/.bashrc or ~/.zshrc
export CONTEXT7_API_KEY="your_api_key_here"
Then install without specifying the key in the command:
claude mcp add --scope user context7 -- npx -y @upstash/context7-mcp
The server will automatically read from the CONTEXT7_API_KEY environment variable.

Multiple Configurations

You can have different configurations for different projects:
# Global configuration (no API key)
claude mcp add --scope user context7-global -- npx -y @upstash/context7-mcp

# Project-specific with API key
cd ~/projects/my-project
claude mcp add context7 -- npx -y @upstash/context7-mcp --api-key YOUR_API_KEY

Learn More

For more details on Claude Code MCP integration, see:

Next Steps

Configuration

Learn about advanced configuration options

Tools Reference

Explore available MCP tools

Build docs developers (and LLMs) love