How to Install Context7 MCP Server

Community Article Published April 25, 2025

Large Language Models (LLMs) have revolutionized coding assistance, offering remarkable capabilities in code generation, explanation, and debugging. However, they often operate with a significant limitation: their knowledge is frozen at the time of their last training. This means they frequently rely on outdated documentation, suggest deprecated functions, or even hallucinate APIs that never existed for the specific library versions you're using. This leads to frustration, wasted time, and broken code.

Enter Context7, an innovative MCP (Model Context Protocol) server developed by Upstash. Context7 tackles the problem of stale information head-on. It acts as a dynamic bridge between your coding prompt and the real-time world of software documentation. When invoked, Context7 fetches up-to-date, version-specific documentation and relevant code examples directly from the source and injects them into your LLM's context before it generates an answer.

The result?

  • Accurate, Up-to-Date Code: Examples and suggestions based on the latest library versions.
  • No More Hallucinated APIs: Rely on documented, existing functions.
  • Version-Specific Guidance: Get answers tailored to the library versions you are actually using.
  • Seamless Workflow: Integrate directly into your existing AI coding assistant (like Cursor, VS Code with MCP extensions, etc.) without constant tab-switching to documentation sites.

This tutorial provides a comprehensive guide on how to install, configure, and effectively use the Context7 MCP server to significantly enhance the accuracy and reliability of your AI coding assistant.

Tired of Postman? Want a decent postman alternative that doesn't suck?

Apidog is a powerful all-in-one API development platform that's revolutionizing how developers design, test, and document their APIs.

Unlike traditional tools like Postman, Apidog seamlessly integrates API design, automated testing, mock servers, and documentation into a single cohesive workflow. With its intuitive interface, collaborative features, and comprehensive toolset, Apidog eliminates the need to juggle multiple applications during your API development process.

Whether you're a solo developer or part of a large team, Apidog streamlines your workflow, increases productivity, and ensures consistent API quality across your projects.

image/png

The Core Idea: use context7

The magic of Context7 lies in its simplicity. You interact with it by adding a simple instruction to your natural language prompts: use context7.

For example:

  • Create a basic Next.js project with app router. use context7
  • Write a Python script using requests to fetch data from an API, include error handling. use context7
  • How do I set up a Redis client using the 'redis-py' library? use context7

When your MCP-enabled editor sees use context7, it routes the relevant parts of your request to the Context7 server. The server intelligently identifies the libraries mentioned, fetches the most current and relevant documentation snippets or code examples for the task described, and bundles this fresh context with your original prompt before sending it to the LLM. The LLM then generates its response based on this enriched, accurate information.

Prerequisites

Before installing Context7, ensure you have the following:

  1. Node.js: Version 18.0.0 or higher. Context7 relies on the Node.js ecosystem, primarily using npx (or alternatives like bunx, deno) to execute. You can check your Node.js version by running node -v in your terminal. Download Node.js from nodejs.org if needed.
  2. MCP-Compatible Client: Context7 is an MCP server. It needs a client application to interact with. Popular choices include:
    • Cursor IDE
    • VS Code (with an MCP extension like "MCP Support")
    • Windsurf
    • Claude Code (CLI tool)
    • Claude Desktop

Installation and Configuration

Context7 needs to be registered as an MCP server within your chosen client application. The setup involves telling the client how to run the Context7 server, typically using npx, bunx, or deno to fetch and execute the latest version of the @upstash/context7-mcp package.

Below are detailed instructions for various popular clients. The recommended approach generally uses npx as it comes bundled with Node.js.

Important Note: The command npx -y @upstash/context7-mcp@latest tells npx to execute (x) the @upstash/context7-mcp package, automatically downloading it if necessary (-y confirms installation), and ensures it uses the most recent version (@latest).

1. Cursor

Cursor has built-in support for MCP servers.

  1. Open Settings: Go to File -> Settings (or Code -> Settings on macOS), then navigate to Extensions -> Cursor.
  2. Find MCP Settings: Scroll down to the "MCP" section.
  3. Add Server Manually (UI): Click on Add new global MCP server.
    • Name: context7 (or any name you prefer)
    • Command: npx
    • Args: Add -y and @upstash/context7-mcp@latest as separate arguments.
  4. Add Server via mcp.json (Recommended):
    • Locate your Cursor configuration directory (usually ~/.cursor/ on Linux/macOS or %USERPROFILE%\.cursor\ on Windows).

    • Open or create the mcp.json file.

    • Add the following configuration:

      {
        "mcpServers": {
          "context7": {
            "command": "npx",
            "args": ["-y", "@upstash/context7-mcp@latest"]
          }
        }
      }
      
    • Save the file and restart Cursor for the changes to take effect.

Alternatives for Cursor (using Bun or Deno):

If you prefer or encounter issues with npx, you can use bunx or deno.

  • Using Bun:

    {
      "mcpServers": {
        "context7": {
          "command": "bunx",
          "args": ["-y", "@upstash/context7-mcp@latest"]
        }
      }
    }
    
  • Using Deno:

    {
      "mcpServers": {
        "context7": {
          "command": "deno",
          "args": ["run", "--allow-net", "npm:@upstash/context7-mcp"]
        }
      }
    }
    

    (Note: Deno requires explicit network permissions (--allow-net)).

2. VS Code (with MCP Extension)

You'll need an extension that adds MCP support to VS Code, such as the generically named "MCP Support" or others that might emerge. Configuration is typically done in your VS Code settings.json file.

  1. Open Settings: File -> Preferences -> Settings (or Code -> Preferences -> Settings on macOS).

  2. Open settings.json: Click the "Open Settings (JSON)" icon in the top-right corner.

  3. Add MCP Server Configuration: Add the following snippet within the main JSON object. The exact structure (servers vs. mcpServers, type field) might vary slightly depending on the specific MCP extension you are using. Refer to your extension's documentation, but the core command and args remain the same. This example assumes a common structure:

    {
      // ... your other settings ...
    
      "mcp.servers": { // Or the key specified by your MCP extension
        "Context7": { // Or any name you prefer
          "type": "stdio", // Common transport type for MCP
          "command": "npx",
          "args": ["-y", "@upstash/context7-mcp@latest"]
        }
      }
    
      // ... rest of your settings ...
    }
    
  4. Save settings.json and restart VS Code.

3. Windsurf

Windsurf uses a configuration file similar to Cursor's mcp.json.

  1. Locate your Windsurf MCP configuration file (refer to Windsurf documentation if unsure of the location).

  2. Add the Context7 server definition:

    {
      "mcpServers": {
        "context7": {
          "command": "npx",
          "args": ["-y", "@upstash/context7-mcp@latest"]
        }
      }
    }
    
  3. Save the file and restart Windsurf.

4. Claude Code (CLI)

Claude Code provides a command-line interface for managing MCP servers.

  1. Open your terminal.

  2. Run the following command:

    claude mcp add context7 -- npx -y @upstash/context7-mcp@latest
    

    This registers context7 as an MCP server, instructing Claude Code to run the npx command whenever use context7 is encountered.

5. Claude Desktop

Claude Desktop uses a configuration file, typically claude_desktop_config.json.

  1. Locate your claude_desktop_config.json file (refer to Claude Desktop documentation for its location).

  2. Add the Context7 server configuration:

    {
      // ... other configurations ...
    
      "mcpServers": {
        "Context7": { // Or any name you prefer
          "command": "npx",
          "args": ["-y", "@upstash/context7-mcp@latest"]
        }
      }
    
      // ... rest of configurations ...
    }
    
  3. Save the file and restart Claude Desktop.

6. Smithery (Automated Installation)

Smithery is a tool that can simplify MCP server installations, particularly for Claude Desktop.

  1. Open your terminal.

  2. Run the installation command:

    npx -y @smithery/cli install @upstash/context7-mcp --client claude
    

    This command uses Smithery to automatically configure Context7 for Claude Desktop.

7. Using Docker

If you prefer containerization or encounter environment issues with Node.js/npx locally, you can run Context7 in a Docker container.

  1. Create a Dockerfile: Create a file named Dockerfile (no extension) in a convenient location with the following content:

    FROM node:18-alpine
    WORKDIR /app
    # Install the latest version globally within the container
    RUN npm install -g @upstash/context7-mcp@latest
    # Default command to run when the container starts
    CMD ["context7-mcp"]
    
  2. Build the Docker Image: Open a terminal in the same directory as your Dockerfile and run (ensure Docker Desktop or the Docker daemon is running):

    docker build -t context7-mcp .
    

    This builds an image named context7-mcp.

  3. Configure Your MCP Client: Update your client's MCP configuration to execute the Docker command instead of npx directly. The key is to run the container interactively (-i) and remove it automatically when it exits (--rm).

    Example for a client using a mcp.json or similar structure:

    {
      "mcpServers": {
        "Context7": { // Or your preferred name
          "command": "docker",
          "args": ["run", "-i", "--rm", "context7-mcp"], // Command + Args to run the container
          "transportType": "stdio" // Often required for Docker interaction
          // Add other client-specific settings like timeout, disabled, etc. if needed
        }
      }
    }
    

    Important: Adapt this JSON structure (mcpServers vs servers, transportType, etc.) based on the specific configuration requirements of your MCP client (Cursor, VS Code extension, etc.). The crucial part is replacing the npx command/args with the docker run ... command/args. Ensure the image name in the args (context7-mcp) matches the tag used during the docker build command. Restart your MCP client after configuration.

Using Context7

Once installed and configured, using Context7 is straightforward:

  1. Write Your Prompt: Formulate your coding request or question naturally in your MCP client.
  2. Add the Trigger: Append use context7 to your prompt.
  3. Get Enhanced Results: The client will invoke the Context7 server, which fetches relevant, up-to-date context. This context is combined with your prompt and sent to the LLM, leading to more accurate and reliable responses.

Available Context7 Tools

Context7 exposes specific tools that the LLM (or you, indirectly) can utilize:

  1. resolve-library-id:

    • Purpose: Translates a common library name (e.g., "react", "nextjs", "requests") into an internal ID that Context7 uses to find documentation. This is mostly an internal step but useful to understand.
    • Parameters:
      • libraryName (string, required): The general name of the library.
  2. get-library-docs:

    • Purpose: Fetches the actual documentation snippets or code examples for a specific library.
    • Parameters:
      • context7CompatibleLibraryID (string, required): The internal ID obtained from resolve-library-id.
      • topic (string, optional): Narrows down the documentation search to a specific topic (e.g., "routing", "hooks", "authentication", "error handling").
      • tokens (integer, optional, default: 5000): Specifies the maximum number of tokens (roughly, words or parts of words) to return. Values below 5000 are automatically increased to 5000. This prevents overwhelming the LLM's context window.

You generally don't call these tools directly. Simply using use context7 allows the system (client, Context7 server, LLM working together) to potentially use these tools behind the scenes to fulfill your request. Mentioning specific libraries and tasks in your prompt helps Context7 determine what to fetch.

Practical Examples

  • Request: How do I make a POST request with JSON data using the Python 'requests' library? use context7

    • Context7 Action: Identifies "requests" library, fetches relevant docs/examples for POST requests with JSON.
    • LLM Result: Provides accurate, up-to-date Python code using requests.post() with the json= parameter.
  • Request: Explain how to use the useState hook in React. use context7

    • Context7 Action: Identifies "React", focuses on the "useState" topic, fetches current documentation for the hook.
    • LLM Result: Gives a clear explanation and code example based on the latest React documentation for useState.
  • Request: Configure a basic Express.js server to listen on port 3000. use context7

    • Context7 Action: Identifies "Express.js", fetches basic server setup examples.
    • LLM Result: Generates a correct and minimal Express.js server code snippet.

Troubleshooting

If Context7 doesn't seem to be working:

  1. Check Prerequisites: Ensure Node.js v18+ is installed and accessible in the environment where your MCP client is launched.
  2. Verify Configuration: Double-check the MCP server configuration in your client (mcp.json, settings.json, etc.). Ensure the command and args are correct. Typos are common!
  3. Restart Client: Always restart your MCP client (Cursor, VS Code, etc.) after modifying MCP configurations.
  4. ERR_MODULE_NOT_FOUND: This error sometimes occurs with npx.
    • Solution 1: Try bunx: If you have Bun installed (npm install -g bun), change the command in your config from npx to bunx.
    • Solution 2: Try deno: If you have Deno installed, change the command to deno and args to ["run", "--allow-net", "npm:@upstash/context7-mcp"].
  5. General MCP Client Errors:
    • Try removing @latest: Change @upstash/context7-mcp@latest to @upstash/context7-mcp in the args. This might help if there's a temporary issue with the absolute latest version.
    • Try bunx or deno: As mentioned above, these can sometimes resolve package resolution issues.
  6. Check for Output/Errors: Some MCP clients might show output or errors from MCP servers in a specific panel or log file. Check your client's documentation. You can also try running the command directly in your terminal (e.g., npx -y @upstash/context7-mcp@latest) to see if it executes without errors.
  7. Docker Issues: If using Docker, ensure the Docker daemon is running. Check that the image name in the client configuration matches the name used during docker build. Try running the docker run -i --rm context7-mcp command directly in the terminal to test the container.

Development (For Contributors)

If you wish to contribute to Context7 or run it locally from source:

  1. Clone: git clone https://github.com/upstash/context7.git

  2. Navigate: cd context7

  3. Install Dependencies: bun install (Requires Bun)

  4. Build: bun run build

  5. Local Configuration: Configure your MCP client to run the local script directly using tsx (part of the development dependencies, often installed via bun install).

    Example mcp.json for local development:

    {
      "mcpServers": {
        "context7-local": { // Use a different name to avoid conflicts
          "command": "npx", // Or bunx
          // Replace with the ACTUAL absolute or relative path to index.ts
          "args": ["tsx", "/full/path/to/your/cloned/context7/src/index.ts"]
        }
      }
    }
    

Conclusion

Context7 MCP Server is a powerful tool for overcoming one of the primary limitations of current LLM-based coding assistants: their reliance on potentially outdated training data. By dynamically fetching and injecting up-to-date documentation and code examples directly into the LLM's context, Context7 ensures you receive more accurate, reliable, and version-aware coding assistance.

Following the installation steps for your preferred MCP client and remembering to add use context7 to your prompts will significantly enhance your AI pair programming experience, saving you time and reducing frustration caused by inaccurate or hallucinated code.

Community

Your need to confirm your account before you can post a new comment.

Sign up or log in to comment