|
| 1 | +--- |
| 2 | +title: Context7 MCP server guide |
| 3 | +sidebar_label: Context7 |
| 4 | +description: |
| 5 | + Using the Context7 MCP server with ToolHive for up-to-date documentation. |
| 6 | +last_update: |
| 7 | + author: danbarr |
| 8 | + date: 2025-08-27 |
| 9 | +--- |
| 10 | + |
| 11 | +import Tabs from '@theme/Tabs'; |
| 12 | +import TabItem from '@theme/TabItem'; |
| 13 | + |
| 14 | +## Overview |
| 15 | + |
| 16 | +The [Context7 MCP server](https://github.com/upstash/context7) provides |
| 17 | +up-to-date, version-specific documentation and code examples straight from the |
| 18 | +source for any library or framework. Instead of relying on outdated training |
| 19 | +data, Context7 fetches current documentation and API references directly into |
| 20 | +your LLM's context, ensuring you get working code examples and accurate |
| 21 | +information. |
| 22 | + |
| 23 | +Context7 eliminates common issues like hallucinated APIs that don't exist, |
| 24 | +outdated code patterns, and generic answers based on old package versions. It |
| 25 | +supports thousands of popular libraries including Next.js, React, MongoDB, |
| 26 | +Supabase, and many more. |
| 27 | + |
| 28 | +Learn more at [context7.com](https://context7.com) and view the |
| 29 | +[project documentation](https://github.com/upstash/context7) for additional |
| 30 | +details. |
| 31 | + |
| 32 | +## Metadata |
| 33 | + |
| 34 | +<MCPMetadata name='context7' /> |
| 35 | + |
| 36 | +## Usage |
| 37 | + |
| 38 | +While Context7 works without an API key, registering at |
| 39 | +[context7.com/dashboard](https://context7.com/dashboard) provides: |
| 40 | + |
| 41 | +- Higher rate limits |
| 42 | +- Priority access during peak usage |
| 43 | +- Better performance for frequent queries |
| 44 | + |
| 45 | +:::note |
| 46 | + |
| 47 | +Currently, the Context7 MCP server only supports a CLI argument for the API key. |
| 48 | +This means ToolHive's secrets management cannot be used to inject the key. |
| 49 | +Instead, you must pass the API key directly as a command-line argument when |
| 50 | +starting the server. |
| 51 | + |
| 52 | +::: |
| 53 | + |
| 54 | +<Tabs groupId='mode' queryString='mode'> |
| 55 | +<TabItem value='ui' label='UI' default> |
| 56 | + |
| 57 | +Select the `context7` MCP server in the ToolHive registry. The server works |
| 58 | +without authentication for basic usage, but you can add an API key for higher |
| 59 | +rate limits. |
| 60 | + |
| 61 | +In the **Command arguments** section, optionally add `--api-key YOUR_API_KEY` if |
| 62 | +you have a Context7 API key. This provides higher rate limits and priority |
| 63 | +access. |
| 64 | + |
| 65 | +:::tip[Security tip] |
| 66 | + |
| 67 | +Enable outbound network filtering on the **Network Isolation** tab to restrict |
| 68 | +the server's network access using the default profile contained in the registry. |
| 69 | + |
| 70 | +::: |
| 71 | + |
| 72 | +</TabItem> |
| 73 | +<TabItem value='cli' label='CLI'> |
| 74 | + |
| 75 | +Run with the default configuration (no API key required for basic usage): |
| 76 | + |
| 77 | +```bash |
| 78 | +thv run context7 |
| 79 | +``` |
| 80 | + |
| 81 | +If you have a Context7 API key for higher rate limits, pass it as an argument: |
| 82 | + |
| 83 | +```bash |
| 84 | +thv run context7 -- --api-key <YOUR_API_KEY> |
| 85 | +``` |
| 86 | + |
| 87 | +Enable [network isolation](../guides-cli/network-isolation.mdx) using the |
| 88 | +default profile from the registry to restrict the server's network access: |
| 89 | + |
| 90 | +```bash |
| 91 | +thv run --isolate-network context7 |
| 92 | +``` |
| 93 | + |
| 94 | +Combine API key with network isolation: |
| 95 | + |
| 96 | +```bash |
| 97 | +thv run --isolate-network context7 -- --api-key <YOUR_API_KEY> |
| 98 | +``` |
| 99 | + |
| 100 | +</TabItem> |
| 101 | +<TabItem value='k8s' label='Kubernetes'> |
| 102 | + |
| 103 | +For basic usage without authentication: |
| 104 | + |
| 105 | +```yaml title="context7.yaml" |
| 106 | +apiVersion: toolhive.stacklok.dev/v1alpha1 |
| 107 | +kind: MCPServer |
| 108 | +metadata: |
| 109 | + name: context7 |
| 110 | + namespace: toolhive-system |
| 111 | +spec: |
| 112 | + image: ghcr.io/stacklok/dockyard/npx/context7:1.0.14 |
| 113 | + transport: stdio |
| 114 | + port: 8080 |
| 115 | + permissionProfile: |
| 116 | + type: builtin |
| 117 | + name: network |
| 118 | +``` |
| 119 | +
|
| 120 | +Apply the manifest to your cluster: |
| 121 | +
|
| 122 | +```bash |
| 123 | +kubectl apply -f context7.yaml |
| 124 | +``` |
| 125 | + |
| 126 | +For higher rate limits, add your API key as a command-line argument: |
| 127 | + |
| 128 | +```yaml {8} title="context7-with-auth.yaml" |
| 129 | +apiVersion: toolhive.stacklok.dev/v1alpha1 |
| 130 | +kind: MCPServer |
| 131 | +metadata: |
| 132 | + name: context7 |
| 133 | + namespace: toolhive-system |
| 134 | +spec: |
| 135 | + image: ghcr.io/stacklok/dockyard/npx/context7:1.0.14 |
| 136 | + args: |
| 137 | + - '--api-key' |
| 138 | + - 'YOUR_API_KEY' |
| 139 | + transport: stdio |
| 140 | + port: 8080 |
| 141 | + permissionProfile: |
| 142 | + type: builtin |
| 143 | + name: network |
| 144 | +``` |
| 145 | +
|
| 146 | +</TabItem> |
| 147 | +</Tabs> |
| 148 | +
|
| 149 | +## Sample prompts |
| 150 | +
|
| 151 | +Here are practical prompts you can use with the Context7 MCP server: |
| 152 | +
|
| 153 | +- "Create a Next.js middleware that checks for a valid JWT in cookies and |
| 154 | + redirects unauthenticated users to `/login`. Use context7" |
| 155 | +- "Show me how to set up MongoDB connection pooling with the latest MongoDB |
| 156 | + Node.js driver. Use context7" |
| 157 | +- "Configure a Supabase client with TypeScript types for a user authentication |
| 158 | + system. Use context7" |
| 159 | +- "Create a React component using the latest Tailwind CSS utility classes for a |
| 160 | + responsive navigation bar. Use context7" |
| 161 | +- "Show me how to implement server-side rendering with the current version of |
| 162 | + Nuxt.js. Use context7" |
| 163 | +- "Configure Redis caching with the Upstash Redis SDK for serverless functions. |
| 164 | + Use context7" |
| 165 | + |
| 166 | +## Recommended practices |
| 167 | + |
| 168 | +- Add `use context7` to your prompts to automatically fetch up-to-date |
| 169 | + documentation for the libraries you're working with. |
| 170 | +- When you know the exact library, you can specify it directly using the |
| 171 | + Context7 ID format: `use library /supabase/supabase for api and docs` |
| 172 | +- Consider setting up a rule in your MCP client to automatically invoke Context7 |
| 173 | + for code-related queries, eliminating the need to manually add `use context7` |
| 174 | + to each prompt. |
| 175 | +- Use the `topic` parameter when requesting documentation to focus on specific |
| 176 | + areas like "routing", "authentication", or "deployment". |
| 177 | +- Register for an API key at |
| 178 | + [context7.com/dashboard](https://context7.com/dashboard) if you plan to make |
| 179 | + frequent requests or need higher rate limits. |
| 180 | +- Enable network isolation to restrict the server's outbound access. |
0 commit comments