Skip to main content

Opencode Setup

Install Context7 MCP Server in Opencode to access up-to-date documentation and code examples directly in your AI coding assistant.

Prerequisites

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

Installation Methods

Opencode supports both remote and local MCP server connections via its configuration file.

Configuration File Location

The Opencode configuration file location varies by platform:
  • Linux: ~/.config/opencode/config.json
  • macOS: ~/Library/Application Support/opencode/config.json
  • Windows: %APPDATA%\opencode\config.json
Refer to the Opencode MCP documentation for the exact path on your system.

Automated Setup

Use the Context7 CLI for automated setup:
npx ctx7 setup --opencode
This command:
  • Authenticates via OAuth
  • Generates an API key
  • Configures the MCP server in your Opencode config
  • Sets up recommended rules

Verify Installation

1

Restart Opencode

Close and reopen Opencode for the configuration changes to take effect.
2

Check MCP Status

Look for Context7 in the MCP status indicator or settings panel.
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, configure Opencode to automatically invoke Context7 for code-related questions. Add the following to your Opencode rules configuration:
Always use Context7 MCP when I need library/API documentation, code generation, 
setup or configuration steps without me having to explicitly ask.
See Opencode Rules Documentation for details on configuring rules.

Advanced Configuration

Conditional Enablement

Enable Context7 only for specific projects:
{
  "mcp": {
    "context7": {
      "type": "remote",
      "url": "https://mcp.context7.com/mcp",
      "headers": {
        "CONTEXT7_API_KEY": "YOUR_API_KEY"
      },
      "enabled": false  // Disabled by default
    }
  }
}
Then enable it in project-specific configuration files.

Custom Timeout

For slow network connections, increase the timeout:
{
  "mcp": {
    "context7": {
      "type": "remote",
      "url": "https://mcp.context7.com/mcp",
      "headers": {
        "CONTEXT7_API_KEY": "YOUR_API_KEY"
      },
      "enabled": true,
      "timeout": 30000  // 30 seconds
    }
  }
}

Multiple Profiles

Configure different Context7 instances for different use cases:
{
  "mcp": {
    "context7-free": {
      "type": "remote",
      "url": "https://mcp.context7.com/mcp",
      "enabled": true
    },
    "context7-pro": {
      "type": "remote",
      "url": "https://mcp.context7.com/mcp",
      "headers": {
        "CONTEXT7_API_KEY": "YOUR_PRO_API_KEY"
      },
      "enabled": false
    }
  }
}

Troubleshooting

  1. Verify JSON syntax in your configuration file
  2. Check that "enabled": true is set
  3. Restart Opencode completely
  4. Check Opencode logs for error messages
  1. Verify your API key is correct (should start with ctx7sk)
  2. Ensure the API key is properly formatted in the configuration
  3. Try regenerating your API key at context7.com/dashboard
  4. Check that 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 that the command array is properly formatted
  1. Verify internet connectivity
  2. Test the endpoint: curl https://mcp.context7.com/ping
  3. Check firewall settings
  4. Ensure proxy settings are configured if required
  1. Get a free API key at context7.com/dashboard
  2. Check your usage on the dashboard
  3. Consider upgrading to a paid plan at context7.com/plans

Learn More

For more details on Opencode MCP integration:

Next Steps

Configuration

Learn about advanced configuration options

Tools Reference

Explore available MCP tools

Build docs developers (and LLMs) love