home / mcp / context7 mcp server

Context7 MCP Server

Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "upstash-context7": {
      "url": "https://mcp.context7.com/mcp",
      "headers": {
        "CONTEXT7_API_KEY": "YOUR_API_KEY"
      }
    }
  }
}

Context7 MCP injects up-to-date, version-specific library documentation and code examples directly into your prompts. It helps you avoid outdated snippets and hallucinated APIs by bringing current docs from source libraries into your workflow.

How to use

You load Context7 MCP into your prompt flow to automatically fetch documentation and code examples for libraries you specify. When you mention a library or a task, Context7 will retrieve relevant, up-to-date material and present it in place, so you can copy, adapt, or run the code directly.

To use it with an MCP client, point your client to the Context7 MCP server configuration and ensure authentication is set (API key for remote connections). You can also run Context7 locally to keep everything self-contained. The server supports both remote HTTP access and local stdio transport.

How to install

Prerequisites: you need Node.js and npm (or yarn) installed on your system.

Option A — Remote HTTP server (preferred): configure the MCP client to connect to the remote server endpoint and provide your API key.

Option B — Local stdio server (self-contained): install and run the MCP server locally using the npm package.

{
  "mcpServers": {
    "context7": {
      "url": "https://mcp.context7.com/mcp",
      "headers": {
        "CONTEXT7_API_KEY": "YOUR_API_KEY"
      }
    }
  }
}
{
  "mcpServers": {
    "context7": {
      "command": "npx",
      "args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
    }
  }
}

Additional installation options for different clients

Context7 MCP can also be installed and used from other tooling environments listed below.

// Claude Code Local Server Connection
claude mcp add context7 -- npx -y @upstash/context7-mcp --api-key YOUR_API_KEY
// Claude Code Remote Server Connection
claude mcp add --header "CONTEXT7_API_KEY: YOUR_API_KEY" --transport http context7 https://mcp.context7.com/mcp
// Opencode Remote Server Connection
"mcp": {
  "context7": {
    "type": "remote",
    "url": "https://mcp.context7.com/mcp",
    "headers": {
      "CONTEXT7_API_KEY": "YOUR_API_KEY"
    },
    "enabled": true
  }
}
// Opencode Local Server Connection
{
  "mcp": {
    "context7": {
      "type": "local",
      "command": ["npx", "-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"],
      "enabled": true
    }
  }
}

OAuth Authentication

If your MCP client supports OAuth 2.0, you can enable it by using the OAuth endpoint variant for remote HTTP connections. Use the /mcp/oauth path in your client configuration.

Note that OAuth is only available for remote HTTP connections. Local stdio connections should use API key authentication.

Important tips

To avoid repeating prompts, add a rule in your MCP client to auto-invoke Context7 for library or API documentation whenever you need it.

If you already know the exact library you want, specify its Context7 ID to skip library matching and go straight to documentation.

For version-specific docs, mention the version in your request and Context7 will target the correct release.

Available Tools

Context7 MCP provides tools to resolve library IDs and fetch documentation.

Available tools

resolve-library-id

Resolves a general library name into a Context7-compatible library ID using the user's query and libraryName.

query-docs

Retrieves documentation for a library using a Context7-compatible library ID and the user's query.