Skip to content

feat(mcp-context7): Add Context7 MCP Optional API Key Configuration #8

@divideby0

Description

@divideby0

Overview

Add instructions for obtaining and configuring the optional Context7 API key for @upstash/context7-mcp. The server works without an API key, but providing one enables higher rate limits and private repository access.

Current State

  • Context7 MCP server is a core toolkit server
  • Works without authentication (basic functionality)
  • Optional API key support via CONTEXT7_API_KEY environment variable
  • No guidance on obtaining or configuring the API key

Requirements

Optional API Key Benefits

  1. Higher Rate Limits: Increased API call limits compared to free tier
  2. Private Repositories: Access to private repository documentation
  3. Enhanced Features: Additional capabilities for authenticated users

Account Registration

  1. Free Account: Create account at https://context7.com/dashboard
  2. Authentication Method: Standard account registration

[TODO: USER INPUT NEEDED - Please verify the exact registration process at context7.com/dashboard, including whether it requires email verification, OAuth options, etc.]

API Key Retrieval

  1. Navigate to https://context7.com/dashboard
  2. Locate API key management section

[TODO: USER INPUT NEEDED - Please confirm the exact steps to create/retrieve an API key from the Context7 dashboard. Where is the API key section? Is there a "Create API Key" button? Can you name keys?]

Pricing Information

  • Free Tier: Available with limited rate limits
  • With API Key: Enhanced rate limits (specific limits need confirmation)
  • Private Repos: Requires API key

[TODO: USER INPUT NEEDED - Please confirm any pricing tiers or payment requirements for Context7 API keys]

Implementation

Documentation Updates

registry/mcp-servers/context7/claude.md:

## Context7 MCP Server Setup

### Basic Usage (No API Key)

Context7 works out of the box without an API key. The server will use public rate limits and can access public library documentation.

### Optional: Enhanced Access with API Key

For higher rate limits and private repository access, you can configure an optional API key:

#### Getting Your API Key

1. **Create a Context7 account** (if you don't have one):
   - Go to https://context7.com/dashboard
   - [TODO: Add registration steps]
   - Free account available

2. **Create an API Key**:
   - Navigate to https://context7.com/dashboard
   - [TODO: Add specific steps to access API key management]
   - [TODO: Add steps to create/copy API key]
   - Store the key securely

3. **Configure the key**:
   - The key will be stored in `.env.mcp.secrets` as `CONTEXT7_API_KEY`
   - Never commit this file to version control

#### Benefits of Using an API Key

- **Higher Rate Limits**: [TODO: Specify exact limits]
- **Private Repositories**: Access documentation for private repos
- **Reliability**: Better service availability during peak usage

### Usage

Context7 provides up-to-date, version-specific documentation:

Create a Next.js middleware that checks for a valid JWT in cookies. use context7


The MCP server automatically:
1. Resolves library names to Context7-compatible IDs
2. Fetches current documentation for the library
3. Provides version-specific code examples

Interactive Configuration

Update registry/mcp-servers/context7/index.ts configure() method:

async configure(ctx: ConfigContext): Promise<ServerConfig> {
  // Ask if user wants to configure optional API key
  const useApiKey = await Confirm.prompt({
    message: "Configure Context7 API key? (optional, enables higher rate limits)",
    default: false
  });

  let apiKey: string | undefined;
  
  if (useApiKey) {
    apiKey = await Input.prompt({
      message: "Enter your Context7 API key:",
      hint: "Get one at https://context7.com/dashboard (optional)",
      validate: (value) => {
        if (!value || value.trim().length === 0) {
          return "API key cannot be empty. Press Ctrl+C to skip.";
        }
        // [TODO: Confirm key format/validation if applicable]
        return true;
      }
    });
  }

  const config: ServerConfig = {
    command: "npx",
    args: ["-y", `@upstash/context7-mcp@${this.version}`]
  };

  // Only add env if API key provided
  if (apiKey) {
    config.env = {
      CONTEXT7_API_KEY: apiKey
    };
  }

  return config;
}

Help Text

Add to init command when Context7 is selected:

ℹ️  Context7 API Key (Optional)
   
   Context7 works without an API key, but you can optionally configure one for:
   - Higher rate limits
   - Private repository access
   
   To get an API key:
   1. Create an account at https://context7.com/dashboard (free)
   2. [TODO: Add key retrieval steps]
   3. Configure during setup when prompted
   
   You can skip this step and use Context7 without authentication.

.mcp.json Configuration

Without API Key (default):

{
  "mcpServers": {
    "context7": {
      "command": "npx",
      "args": ["-y", "@upstash/[email protected]"]
    }
  }
}

With API Key (optional):

{
  "mcpServers": {
    "context7": {
      "command": "npx",
      "args": ["-y", "@upstash/[email protected]"],
      "env": {
        "CONTEXT7_API_KEY": "${CONTEXT7_API_KEY}"
      }
    }
  }
}

Testing

  • Verify registration flow at context7.com/dashboard
  • Confirm API key creation/retrieval steps
  • Test Context7 without API key (baseline functionality)
  • Test Context7 with API key (enhanced features)
  • Document rate limit differences
  • Verify private repo access with API key

Design Considerations

Optional vs Required

  • Context7 API key is optional, unlike Exa which requires a key
  • Default behavior should be "no API key" for simplicity
  • User should be prompted but can easily skip
  • Documentation should clearly state this is optional

User Experience

  • Make it clear that basic functionality works without a key
  • Don't block setup if user chooses not to provide a key
  • Provide clear benefits of using an API key
  • Allow reconfiguration later if needed

Related Issues

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions