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 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
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.
- UI
- CLI
- Kubernetes
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.
Enable outbound network filtering on the Network Isolation tab to restrict the server's network access using the default profile contained in the registry.
Run with the default configuration (no API key required for basic usage):
thv run context7
If you have a Context7 API key for higher rate limits, you can pass it directly as a command-line argument. You can store the key in a ToolHive secret and retrieve it when starting the server:
thv secret set context7
thv run context7 -- --api-key $(thv secret get context7)
Enable network isolation using the default profile from the registry to restrict the server's network access:
thv run --isolate-network context7
Combine API key with network isolation:
thv run --isolate-network context7 -- --api-key $(thv secret get context7)
For basic usage without authentication:
apiVersion: toolhive.stacklok.dev/v1alpha1
kind: MCPServer
metadata:
name: context7
namespace: toolhive-system
spec:
image: ghcr.io/stacklok/dockyard/npx/context7:1.0.14
transport: stdio
port: 8080
permissionProfile:
type: builtin
name: network
Apply the manifest to your cluster:
kubectl apply -f context7.yaml
For higher rate limits, add your API key as a command-line argument:
apiVersion: toolhive.stacklok.dev/v1alpha1
kind: MCPServer
metadata:
name: context7
namespace: toolhive-system
spec:
image: ghcr.io/stacklok/dockyard/npx/context7:1.0.14
args:
- '--api-key'
- 'YOUR_API_KEY'
transport: stdio
port: 8080
permissionProfile:
type: builtin
name: network
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"
Recommended practices
- 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.