|
1 | | - |
| 1 | +# Context7 Local |
2 | 2 |
|
3 | | -[](https://cursor.com/en/install-mcp?name=context7&config=eyJ1cmwiOiJodHRwczovL21jcC5jb250ZXh0Ny5jb20vbWNwIn0%3D) |
| 3 | +A local-first, Context7-compatible MCP server for current library documentation. |
4 | 4 |
|
5 | | -# Context7 Platform - Up-to-date Code Docs For Any Prompt |
| 5 | +It keeps documentation indexes on your machine, builds missing libraries automatically, and refreshes stale libraries from their public GitHub repositories. It does not use the hosted Context7 API, so there are no Context7 API keys, quotas, or rate limits. |
6 | 6 |
|
7 | | -> [!IMPORTANT] |
8 | | -> This checkout is a quota-free local-first fork. It serves commit-pinned SQLite |
9 | | -> indexes from `C:\Apps\System\Context7\index`, performs no Context7 telemetry or |
10 | | -> hosted authentication, and automatically builds or refreshes missing libraries. |
11 | | -> See [the MCP local-first guide](packages/mcp/README.md#local-first-index). |
| 7 | +## What it does |
12 | 8 |
|
13 | | -[](https://context7.com) [](https://smithery.ai/server/@upstash/context7-mcp) [](https://www.npmjs.com/package/@upstash/context7-mcp) [](./LICENSE) |
| 9 | +- Supports the standard `resolve-library-id` and `query-docs` workflow. |
| 10 | +- Discovers and indexes a missing public GitHub library during the first request. |
| 11 | +- Stores each index with the exact source commit and refreshes it every 24 hours by default. |
| 12 | +- Publishes rebuilt indexes atomically so existing documentation remains available during updates. |
| 13 | +- Uses local SQLite full-text search, rank fusion, and optional local Ollama embeddings. |
| 14 | +- Includes a catalog for prebuilding 1,000 commonly queried libraries. |
| 15 | +- Sends no Context7 telemetry and has no hosted authentication path. |
14 | 16 |
|
15 | | -[](./i18n/README.zh-TW.md) [](./i18n/README.zh-CN.md) [](./i18n/README.ja.md) [](./i18n/README.ko.md) [](./i18n/README.es.md) [](./i18n/README.fr.md) [-purple>)](./i18n/README.pt-BR.md) [](./i18n/README.it.md) [](./i18n/README.id-ID.md) [](./i18n/README.de.md) [](./i18n/README.ru.md) [](./i18n/README.uk.md) [](./i18n/README.tr.md) [](./i18n/README.ar.md) [](./i18n/README.vi.md) |
| 17 | +On Windows, indexes are stored in `C:\Apps\System\Context7\index` by default. On other platforms, the default is `~/.cache/context7-local`. |
16 | 18 |
|
17 | | -## ❌ Without Context7 |
| 19 | +## Requirements |
18 | 20 |
|
19 | | -LLMs rely on outdated or generic information about the libraries you use. You get: |
| 21 | +- Node.js 22.12 or newer |
| 22 | +- pnpm |
| 23 | +- Git |
| 24 | +- Optional: Ollama with `qwen3-embedding:0.6b` for local semantic reranking |
20 | 25 |
|
21 | | -- ❌ Code examples are outdated and based on year-old training data |
22 | | -- ❌ Hallucinated APIs that don't even exist |
23 | | -- ❌ Generic answers for old package versions |
| 26 | +## Build |
24 | 27 |
|
25 | | -## ✅ With Context7 |
26 | | - |
27 | | -Context7 pulls up-to-date, version-specific documentation and code examples straight from the source — and places them directly into your prompt. |
28 | | - |
29 | | -```txt |
30 | | -Create a Next.js middleware that checks for a valid JWT in cookies |
31 | | -and redirects unauthenticated users to `/login`. use context7 |
| 28 | +```powershell |
| 29 | +git clone https://github.com/sm18lr88/context7-local.git |
| 30 | +cd context7-local |
| 31 | +pnpm install --frozen-lockfile |
| 32 | +pnpm --filter @upstash/context7-mcp build |
32 | 33 | ``` |
33 | 34 |
|
34 | | -```txt |
35 | | -Configure a Cloudflare Worker script to cache |
36 | | -JSON API responses for five minutes. use context7 |
37 | | -``` |
| 35 | +Run the MCP server over stdio: |
38 | 36 |
|
39 | | -```txt |
40 | | -Show me the Supabase auth API for email/password sign-up. |
| 37 | +```powershell |
| 38 | +node packages/mcp/dist/index.js --transport stdio |
41 | 39 | ``` |
42 | 40 |
|
43 | | -Context7 fetches up-to-date code examples and documentation right into your LLM's context. No tab-switching, no hallucinated APIs that don't exist, no outdated code generation. |
| 41 | +## MCP configuration |
44 | 42 |
|
45 | | -Works in two modes: |
| 43 | +Replace the path below if you cloned the repository somewhere else. |
46 | 44 |
|
47 | | -- **CLI + Skills** — installs a skill that guides your agent to fetch docs using `ctx7` CLI commands (no MCP required) |
48 | | -- **MCP** — registers a Context7 MCP server so your agent can call documentation tools natively |
| 45 | +Codex, in `~/.codex/config.toml`: |
49 | 46 |
|
50 | | -## Installation |
| 47 | +```toml |
| 48 | +[mcp_servers.context7] |
| 49 | +command = "node" |
| 50 | +args = [ |
| 51 | + "D:\\Apps\\LLM\\context7-local\\packages\\mcp\\dist\\index.js", |
| 52 | + "--transport", |
| 53 | + "stdio" |
| 54 | +] |
51 | 55 |
|
52 | | -> [!NOTE] |
53 | | -> **API Key Recommended**: Get a free API key at [context7.com/dashboard](https://context7.com/dashboard) for higher rate limits. |
54 | | -
|
55 | | -Set up Context7 for your coding agents with a single command. The `ctx7` CLI requires Node.js 18 or newer. |
56 | | - |
57 | | -```bash |
58 | | -npx ctx7 setup |
| 56 | +[mcp_servers.context7.env] |
| 57 | +CONTEXT7_LOCAL_STORAGE_DIR = "C:\\Apps\\System\\Context7\\index" |
59 | 58 | ``` |
60 | 59 |
|
61 | | -Authenticates via OAuth, generates an API key, and installs the appropriate skill. You can choose between CLI + Skills or MCP mode. Use `--cursor`, `--claude`, or `--opencode` to target a specific agent. |
62 | | - |
63 | | -To remove the generated setup later, run `npx ctx7 remove`. If you globally installed the CLI with `npm install -g ctx7`, remove that package separately with `npm uninstall -g ctx7`. |
64 | | - |
65 | | -To configure manually, use the Context7 server URL `https://mcp.context7.com/mcp` with your MCP client and pass your API key via the `CONTEXT7_API_KEY` header. See the link below for client-specific setup instructions. |
66 | | - |
67 | | -**[Manual Installation / Other Clients →](https://context7.com/docs/resources/all-clients)** |
68 | | - |
69 | | -## Important Tips |
70 | | - |
71 | | -### Use Library Id |
72 | | - |
73 | | -If you already know exactly which library you want to use, add its Context7 ID to your prompt. That way, Context7 can skip the library-matching step and directly retrieve docs. |
74 | | - |
75 | | -```txt |
76 | | -Implement basic authentication with Supabase. use library /supabase/supabase for API and docs. |
| 60 | +VS Code, in the user or workspace `mcp.json`: |
| 61 | + |
| 62 | +```json |
| 63 | +{ |
| 64 | + "servers": { |
| 65 | + "context7": { |
| 66 | + "type": "stdio", |
| 67 | + "command": "node", |
| 68 | + "args": [ |
| 69 | + "D:\\Apps\\LLM\\context7-local\\packages\\mcp\\dist\\index.js", |
| 70 | + "--transport", |
| 71 | + "stdio" |
| 72 | + ], |
| 73 | + "env": { |
| 74 | + "CONTEXT7_LOCAL_STORAGE_DIR": "C:\\Apps\\System\\Context7\\index" |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | +} |
77 | 79 | ``` |
78 | 80 |
|
79 | | -The slash syntax tells Context7 exactly which library to load docs for. |
80 | | - |
81 | | -### Specify a Version |
82 | | - |
83 | | -To get documentation for a specific library version, just mention the version in your prompt: |
84 | | - |
85 | | -```txt |
86 | | -How do I set up Next.js 14 middleware? use context7 |
| 81 | +OpenCode, in `~/.config/opencode/opencode.json`: |
| 82 | + |
| 83 | +```json |
| 84 | +{ |
| 85 | + "mcp": { |
| 86 | + "context7": { |
| 87 | + "type": "local", |
| 88 | + "command": [ |
| 89 | + "node", |
| 90 | + "D:\\Apps\\LLM\\context7-local\\packages\\mcp\\dist\\index.js", |
| 91 | + "--transport", |
| 92 | + "stdio" |
| 93 | + ], |
| 94 | + "environment": { |
| 95 | + "CONTEXT7_LOCAL_STORAGE_DIR": "C:\\Apps\\System\\Context7\\index" |
| 96 | + }, |
| 97 | + "enabled": true |
| 98 | + } |
| 99 | + } |
| 100 | +} |
87 | 101 | ``` |
88 | 102 |
|
89 | | -Context7 will automatically match the appropriate version. |
| 103 | +Restart or reload clients that were already running when their configuration changed. |
90 | 104 |
|
91 | | -### Add a Rule |
| 105 | +## Tools |
92 | 106 |
|
93 | | -If you installed via `ctx7 setup`, a skill is configured automatically that triggers Context7 for library-related questions. To set up a rule manually instead, add one to your coding agent: |
| 107 | +- `resolve-library-id`: finds a Context7-compatible library ID. |
| 108 | +- `query-docs`: returns answer-ready documentation and builds the library first when needed. |
| 109 | +- `search-docs`: returns ranked previews with commit-bound result keys. |
| 110 | +- `read-docs`: reads a selected result with adjacent sections. |
| 111 | +- `grep-docs`: searches locally for an exact API name, option, or error. |
| 112 | +- `local-index-status`: reports freshness, migration, prewarm, and semantic-cache state. |
| 113 | +- `refresh-local-index`: refreshes a library to its current upstream commit. |
94 | 114 |
|
95 | | -- **Cursor**: `Cursor Settings > Rules` |
96 | | -- **Claude Code**: `CLAUDE.md` |
97 | | -- Or the equivalent in your coding agent |
| 115 | +## Index maintenance |
98 | 116 |
|
99 | | -**Example rule:** |
| 117 | +Prebuild the common-library catalog: |
100 | 118 |
|
101 | | -```txt |
102 | | -Always use Context7 when I need library/API documentation, code generation, setup or configuration steps without me having to explicitly ask. |
| 119 | +```powershell |
| 120 | +node packages/mcp/dist/prewarm.js --target 1000 --candidates 1600 --concurrency 2 |
103 | 121 | ``` |
104 | 122 |
|
105 | | -## Available Tools |
106 | | - |
107 | | -### CLI Commands |
108 | | - |
109 | | -- `ctx7 library <name> <query>`: Searches the Context7 index by library name and returns matching libraries with their IDs. |
110 | | -- `ctx7 docs <libraryId> <query>`: Retrieves documentation for a library using a Context7-compatible library ID (e.g., `/mongodb/docs`, `/vercel/next.js`). |
111 | | - |
112 | | -### MCP Tools |
| 123 | +Upgrade existing indexes after a parser change: |
113 | 124 |
|
114 | | -- `resolve-library-id`: Resolves a general library name into a Context7-compatible library ID. |
115 | | - - `query` (required): The user's question or task (used to rank results by relevance) |
116 | | - - `libraryName` (required): The name of the library to search for |
117 | | -- `query-docs`: Retrieves documentation for a library using a Context7-compatible library ID. |
118 | | - - `libraryId` (required): Exact Context7-compatible library ID (e.g., `/mongodb/docs`, `/vercel/next.js`) |
119 | | - - `query` (required): The question or task to get relevant documentation for |
120 | | -- `search-docs`: Returns concise fused/hybrid results with commit-bound keys. |
121 | | -- `read-docs`: Reads one result with adjacent document sections. |
122 | | -- `grep-docs`: Finds exact API names, options, and error fragments locally. |
123 | | -- `local-index-status`: Reports freshness, parser migration, prewarm, and semantic-cache state. |
124 | | -- `refresh-local-index`: Atomically refreshes one library to its current upstream commit. |
125 | | - |
126 | | -## More Documentation |
127 | | - |
128 | | -- [CLI Reference](https://context7.com/docs/clients/cli) - Full CLI documentation |
129 | | -- [MCP Clients](https://context7.com/docs/resources/all-clients) - Manual MCP installation for 30+ clients |
130 | | -- [Adding Libraries](https://context7.com/docs/adding-libraries) - Submit your library to Context7 |
131 | | -- [Troubleshooting](https://context7.com/docs/resources/troubleshooting) - Common issues and solutions |
132 | | -- [API Reference](https://context7.com/docs/api-guide) - REST API documentation |
133 | | -- [Developer Guide](https://context7.com/docs/resources/developer) - Run Context7 MCP locally |
134 | | - |
135 | | -## Packages |
136 | | - |
137 | | -- [`@upstash/context7-mcp`](https://www.npmjs.com/package/@upstash/context7-mcp) - MCP server |
138 | | -- [`ctx7`](https://www.npmjs.com/package/ctx7) - CLI |
139 | | -- [`@upstash/context7-sdk`](https://www.npmjs.com/package/@upstash/context7-sdk) - TypeScript SDK |
140 | | -- [`@upstash/context7-tools-ai-sdk`](https://www.npmjs.com/package/@upstash/context7-tools-ai-sdk) - Vercel AI SDK tools |
141 | | -- [`@upstash/context7-pi`](https://www.npmjs.com/package/@upstash/context7-pi) - pi.dev extension |
| 125 | +```powershell |
| 126 | +node packages/mcp/dist/migrate-index.js --concurrency 2 |
| 127 | +``` |
142 | 128 |
|
143 | | -## Disclaimer |
| 129 | +Run the retrieval regression suite: |
144 | 130 |
|
145 | | -1- Context7 projects are community-contributed and while we strive to maintain high quality, we cannot guarantee the accuracy, completeness, or security of all library documentation. Projects listed in Context7 are developed and maintained by their respective owners, not by Context7. If you encounter any suspicious, inappropriate, or potentially harmful content, please use the "Report" button on the project page to notify us immediately. We take all reports seriously and will review flagged content promptly to maintain the integrity and safety of our platform. By using Context7, you acknowledge that you do so at your own discretion and risk. |
| 131 | +```powershell |
| 132 | +node packages/mcp/dist/evaluate-retrieval.js |
| 133 | +``` |
146 | 134 |
|
147 | | -2- This repository hosts the MCP server’s source code. The supporting components — API backend, parsing engine, and crawling engine — are private and not part of this repository. |
| 135 | +Progress and evaluation history are kept inside the index directory, so interrupted jobs can resume and retrieval changes can be compared over time. |
148 | 136 |
|
149 | | -## 🤝 Connect with Us |
| 137 | +## Configuration |
150 | 138 |
|
151 | | -Stay updated and join our community: |
| 139 | +The most useful environment variables are: |
152 | 140 |
|
153 | | -- 📢 Follow us on [X](https://x.com/context7ai) for the latest news and updates |
154 | | -- 🌐 Visit our [Website](https://context7.com) |
155 | | -- 💬 Join our [Discord Community](https://upstash.com/discord) |
| 141 | +| Variable | Default | Purpose | |
| 142 | +| ------------------------------ | ----------------------------- | -------------------------------------------------- | |
| 143 | +| `CONTEXT7_LOCAL_STORAGE_DIR` | Platform-specific local cache | Index location | |
| 144 | +| `CONTEXT7_REFRESH_INTERVAL_MS` | `86400000` | Upstream freshness-check interval | |
| 145 | +| `CONTEXT7_LOCAL_EMBEDDINGS` | Enabled | Set to `off` for lexical retrieval only | |
| 146 | +| `CONTEXT7_EMBEDDING_MODEL` | `qwen3-embedding:0.6b` | Local Ollama embedding model | |
| 147 | +| `CONTEXT7_EMBEDDING_BASE_URL` | `http://127.0.0.1:11434` | Local Ollama endpoint | |
| 148 | +| `GITHUB_TOKEN` or `GH_TOKEN` | Unset | Optional GitHub search and metadata authentication | |
156 | 149 |
|
157 | | -## 📺 Context7 In Media |
| 150 | +All limits and architecture details are documented in [packages/mcp/README.md](packages/mcp/README.md) and [packages/mcp/LOCAL_ARCHITECTURE.md](packages/mcp/LOCAL_ARCHITECTURE.md). |
158 | 151 |
|
159 | | -- [Better Stack: "Free Tool Makes Cursor 10x Smarter"](https://youtu.be/52FC3qObp9E) |
160 | | -- [Cole Medin: "This is Hands Down the BEST MCP Server for AI Coding Assistants"](https://www.youtube.com/watch?v=G7gK8H6u7Rs) |
161 | | -- [Income Stream Surfers: "Context7 + SequentialThinking MCPs: Is This AGI?"](https://www.youtube.com/watch?v=-ggvzyLpK6o) |
162 | | -- [Julian Goldie SEO: "Context7: New MCP AI Agent Update"](https://www.youtube.com/watch?v=CTZm6fBYisc) |
163 | | -- [JeredBlu: "Context 7 MCP: Get Documentation Instantly + VS Code Setup"](https://www.youtube.com/watch?v=-ls0D-rtET4) |
164 | | -- [Income Stream Surfers: "Context7: The New MCP Server That Will CHANGE AI Coding"](https://www.youtube.com/watch?v=PS-2Azb-C3M) |
165 | | -- [AICodeKing: "Context7 + Cline & RooCode: This MCP Server Makes CLINE 100X MORE EFFECTIVE!"](https://www.youtube.com/watch?v=qZfENAPMnyo) |
166 | | -- [Sean Kochel: "5 MCP Servers For Vibe Coding Glory (Just Plug-In & Go)"](https://www.youtube.com/watch?v=LqTQi8qexJM) |
| 152 | +## Security |
167 | 153 |
|
168 | | -## ⭐ Star History |
| 154 | +Repository documentation is treated as untrusted input. Agent-instruction files are excluded, file and response sizes are bounded, Git hooks and filters are disabled, and returned source links are pinned to the indexed commit. |
169 | 155 |
|
170 | | -[](https://www.star-history.com/#upstash/context7&Date) |
| 156 | +HTTP transport binds to loopback by default. Use an authenticated reverse proxy or SSH tunnel if another machine needs access. |
171 | 157 |
|
172 | | -## 📄 License |
| 158 | +## License |
173 | 159 |
|
174 | | -MIT |
| 160 | +MIT. This project is based on [Upstash Context7](https://github.com/upstash/context7). |
0 commit comments