Skip to main content

Context7 MCP server guide

Overview

The Context7 MCP server provides up-to-date, version-specific documentation and code examples straight from the source for any library or framework. Instead of relying on outdated training data, Context7 fetches current documentation and API references directly into your LLM's context, ensuring you get working code examples and accurate information.

Context7 eliminates common issues like hallucinated APIs that don't exist, outdated code patterns, and generic answers based on old package versions. It supports thousands of popular libraries including Next.js, React, MongoDB, Supabase, and many more.

Learn more at context7.com and view the project documentation for additional details.

Metadata

Error: Failed to fetch metadata for MCP server "context7".
Error details
# Error fetching data for context7
# Failed to fetch MCP server data. See logs for details.
# Please check that the server exists in the registry and thv command is available

Usage

While Context7 works without an API key, registering at context7.com/dashboard provides:

  • Higher rate limits
  • Priority access during peak usage
  • Better performance for frequent queries
note

Currently, the Context7 MCP server only supports a CLI argument for the API key. This means ToolHive's secrets management cannot be used to inject the key as an environment variable. Instead, you must pass the API key directly as a command-line argument when starting the server.

Select the context7 MCP server in the ToolHive registry. The server works without authentication for basic usage, but you can add an API key for higher rate limits.

In the Command arguments section, optionally add --api-key YOUR_API_KEY if you have a Context7 API key. This provides higher rate limits and priority access.

Security tip

Enable outbound network filtering on the Network Isolation tab to restrict the server's network access using the default profile contained in the registry.

Sample prompts

Here are practical prompts you can use with the Context7 MCP server:

  • "Create a Next.js middleware that checks for a valid JWT in cookies and redirects unauthenticated users to /login. Use context7"
  • "Show me how to set up MongoDB connection pooling with the latest MongoDB Node.js driver. Use context7"
  • "Configure a Supabase client with TypeScript types for a user authentication system. Use context7"
  • "Create a React component using the latest Tailwind CSS utility classes for a responsive navigation bar. Use context7"
  • "Show me how to implement server-side rendering with the current version of Nuxt.js. Use context7"
  • "Configure Redis caching with the Upstash Redis SDK for serverless functions. Use context7"
  • Add use context7 to your prompts to automatically fetch up-to-date documentation for the libraries you're working with.
  • When you know the exact library, you can specify it directly using the Context7 ID format: use library /supabase/supabase for api and docs
  • Consider setting up a rule in your MCP client to automatically invoke Context7 for code-related queries, eliminating the need to manually add use context7 to each prompt.
  • Use the topic parameter when requesting documentation to focus on specific areas like "routing", "authentication", or "deployment".
  • Register for an API key at context7.com/dashboard if you plan to make frequent requests or need higher rate limits.
  • Enable network isolation to restrict the server's outbound access.