@upstash/context7-mcp 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +161 -16
- package/dist/index.js +41 -7
- package/dist/lib/utils.js +6 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
# Context7 MCP - Up-to-date Docs For Any
|
|
2
|
-
|
|
1
|
+
# Context7 MCP - Up-to-date Code Docs For Any Prompt
|
|
2
|
+
|
|
3
|
+
[](https://context7.com) [](https://smithery.ai/server/@upstash/context7-mcp) [<img alt="Install in VS Code (npx)" src="https://img.shields.io/badge/VS_Code-VS_Code?style=flat-square&label=Install%20Context7%20MCP&color=0098FF">](https://insiders.vscode.dev/redirect?url=vscode%3Amcp%2Finstall%3F%7B%22name%22%3A%22context7%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40upstash%2Fcontext7-mcp%40latest%22%5D%7D)
|
|
4
|
+
|
|
5
|
+
[](./docs/README.zh-CN.md) [](./docs/README.ko.md) [](./docs/README.es.md) [](./docs/README.fr.md) [-purple)](./docs/README.pt-BR.md) [](./docs/README.it.md) [](./docs/README.id-ID.md) [](./docs/README.de.md) [](./docs/README.ru.md)
|
|
3
6
|
|
|
4
7
|
## ❌ Without Context7
|
|
5
8
|
|
|
@@ -13,23 +16,19 @@ LLMs rely on outdated or generic information about the libraries you use. You ge
|
|
|
13
16
|
|
|
14
17
|
Context7 MCP pulls up-to-date, version-specific documentation and code examples straight from the source — and places them directly into your prompt.
|
|
15
18
|
|
|
16
|
-
Add `use context7` to your
|
|
17
|
-
|
|
18
|
-
```txt
|
|
19
|
-
How do I use the new Next.js `after` function? use context7
|
|
20
|
-
```
|
|
19
|
+
Add `use context7` to your prompt in Cursor:
|
|
21
20
|
|
|
22
21
|
```txt
|
|
23
|
-
|
|
22
|
+
Create a basic Next.js project with app router. use context7
|
|
24
23
|
```
|
|
25
24
|
|
|
26
25
|
```txt
|
|
27
|
-
|
|
26
|
+
Create a script to delete the rows where the city is "" given PostgreSQL credentials. use context7
|
|
28
27
|
```
|
|
29
28
|
|
|
30
|
-
Context7 fetches up-to-date
|
|
29
|
+
Context7 fetches up-to-date code examples and documentation right into your LLM's context.
|
|
31
30
|
|
|
32
|
-
- 1️⃣
|
|
31
|
+
- 1️⃣ Write your prompt naturally
|
|
33
32
|
- 2️⃣ Tell the LLM to `use context7`
|
|
34
33
|
- 3️⃣ Get working code answers
|
|
35
34
|
|
|
@@ -54,7 +53,7 @@ npx -y @smithery/cli install @upstash/context7-mcp --client claude
|
|
|
54
53
|
|
|
55
54
|
Go to: `Settings` -> `Cursor Settings` -> `MCP` -> `Add new global MCP server`
|
|
56
55
|
|
|
57
|
-
Pasting the following configuration into your Cursor `~/.cursor/mcp.json` file is the recommended approach. See [Cursor MCP docs](https://docs.cursor.com/context/model-context-protocol) for more info.
|
|
56
|
+
Pasting the following configuration into your Cursor `~/.cursor/mcp.json` file is the recommended approach. You may also install in a specific project by creating `.cursor/mcp.json` in your project folder. See [Cursor MCP docs](https://docs.cursor.com/context/model-context-protocol) for more info.
|
|
58
57
|
|
|
59
58
|
```json
|
|
60
59
|
{
|
|
@@ -114,9 +113,12 @@ Add this to your Windsurf MCP config file. See [Windsurf MCP docs](https://docs.
|
|
|
114
113
|
}
|
|
115
114
|
```
|
|
116
115
|
|
|
117
|
-
### Install in
|
|
116
|
+
### Install in VS Code
|
|
118
117
|
|
|
119
|
-
|
|
118
|
+
[<img alt="Install in VS Code (npx)" src="https://img.shields.io/badge/VS_Code-VS_Code?style=flat-square&label=Install%20Context7%20MCP&color=0098FF">](https://insiders.vscode.dev/redirect?url=vscode%3Amcp%2Finstall%3F%7B%22name%22%3A%22context7%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40upstash%2Fcontext7-mcp%40latest%22%5D%7D)
|
|
119
|
+
[<img alt="Install in VS Code Insiders (npx)" src="https://img.shields.io/badge/VS_Code_Insiders-VS_Code_Insiders?style=flat-square&label=Install%20Context7%20MCP&color=24bfa5">](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Amcp%2Finstall%3F%7B%22name%22%3A%22context7%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40upstash%2Fcontext7-mcp%40latest%22%5D%7D)
|
|
120
|
+
|
|
121
|
+
Add this to your VS Code MCP config file. See [VS Code MCP docs](https://code.visualstudio.com/docs/copilot/chat/mcp-servers) for more info.
|
|
120
122
|
|
|
121
123
|
```json
|
|
122
124
|
{
|
|
@@ -130,6 +132,24 @@ Add this to your VSCode MCP config file. See [VSCode MCP docs](https://code.visu
|
|
|
130
132
|
}
|
|
131
133
|
```
|
|
132
134
|
|
|
135
|
+
### Install in Zed
|
|
136
|
+
|
|
137
|
+
It can be installed via [Zed Extensions](https://zed.dev/extensions?query=Context7) or you can add this to your Zed `settings.json`. See [Zed Context Server docs](https://zed.dev/docs/assistant/context-servers) for more info.
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"context_servers": {
|
|
142
|
+
"Context7": {
|
|
143
|
+
"command": {
|
|
144
|
+
"path": "npx",
|
|
145
|
+
"args": ["-y", "@upstash/context7-mcp@latest"]
|
|
146
|
+
},
|
|
147
|
+
"settings": {}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
133
153
|
### Install in Claude Code
|
|
134
154
|
|
|
135
155
|
Run this command. See [Claude Code MCP docs](https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/tutorials#set-up-model-context-protocol-mcp) for more info.
|
|
@@ -153,14 +173,91 @@ Add this to your Claude Desktop `claude_desktop_config.json` file. See [Claude D
|
|
|
153
173
|
}
|
|
154
174
|
```
|
|
155
175
|
|
|
176
|
+
### Using Docker
|
|
177
|
+
|
|
178
|
+
If you prefer to run the MCP server in a Docker container:
|
|
179
|
+
|
|
180
|
+
1. **Build the Docker Image:**
|
|
181
|
+
|
|
182
|
+
First, create a `Dockerfile` in the project root (or anywhere you prefer):
|
|
183
|
+
|
|
184
|
+
<details>
|
|
185
|
+
<summary>Click to see Dockerfile content</summary>
|
|
186
|
+
|
|
187
|
+
```Dockerfile
|
|
188
|
+
FROM node:18-alpine
|
|
189
|
+
|
|
190
|
+
WORKDIR /app
|
|
191
|
+
|
|
192
|
+
# Install the latest version globally
|
|
193
|
+
RUN npm install -g @upstash/context7-mcp@latest
|
|
194
|
+
|
|
195
|
+
# Expose default port if needed (optional, depends on MCP client interaction)
|
|
196
|
+
# EXPOSE 3000
|
|
197
|
+
|
|
198
|
+
# Default command to run the server
|
|
199
|
+
CMD ["context7-mcp"]
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
</details>
|
|
203
|
+
|
|
204
|
+
Then, build the image using a tag (e.g., `context7-mcp`). **Make sure Docker Desktop (or the Docker daemon) is running.** Run the following command in the same directory where you saved the `Dockerfile`:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
docker build -t context7-mcp .
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
2. **Configure Your MCP Client:**
|
|
211
|
+
|
|
212
|
+
Update your MCP client's configuration to use the Docker command.
|
|
213
|
+
|
|
214
|
+
*Example for a cline_mcp_settings.json:*
|
|
215
|
+
|
|
216
|
+
```json
|
|
217
|
+
{
|
|
218
|
+
"mcpServers": {
|
|
219
|
+
"Сontext7": {
|
|
220
|
+
"autoApprove": [],
|
|
221
|
+
"disabled": false,
|
|
222
|
+
"timeout": 60,
|
|
223
|
+
"command": "docker",
|
|
224
|
+
"args": ["run", "-i", "--rm", "context7-mcp"],
|
|
225
|
+
"transportType": "stdio"
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
*Note: This is an example configuration. Please refer to the specific examples for your MCP client (like Cursor, VS Code, etc.) earlier in this README to adapt the structure (e.g., `mcpServers` vs `servers`). Also, ensure the image name in `args` matches the tag used during the `docker build` command.*
|
|
232
|
+
|
|
233
|
+
### Environment Variables
|
|
234
|
+
|
|
235
|
+
- `DEFAULT_MINIMUM_TOKENS`: Set the minimum token count for documentation retrieval (default: 10000).
|
|
236
|
+
|
|
237
|
+
Examples:
|
|
238
|
+
|
|
239
|
+
```json
|
|
240
|
+
{
|
|
241
|
+
"mcpServers": {
|
|
242
|
+
"context7": {
|
|
243
|
+
"command": "npx",
|
|
244
|
+
"args": ["-y", "@upstash/context7-mcp@latest"],
|
|
245
|
+
"env": {
|
|
246
|
+
"DEFAULT_MINIMUM_TOKENS": "10000"
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
156
253
|
### Available Tools
|
|
157
254
|
|
|
158
255
|
- `resolve-library-id`: Resolves a general library name into a Context7-compatible library ID.
|
|
159
|
-
- `libraryName` (
|
|
256
|
+
- `libraryName` (required)
|
|
160
257
|
- `get-library-docs`: Fetches documentation for a library using a Context7-compatible library ID.
|
|
161
258
|
- `context7CompatibleLibraryID` (required)
|
|
162
259
|
- `topic` (optional): Focus the docs on a specific topic (e.g., "routing", "hooks")
|
|
163
|
-
- `tokens` (optional, default
|
|
260
|
+
- `tokens` (optional, default 10000): Max number of tokens to return. Values less than the configured `DEFAULT_MINIMUM_TOKENS` value or the default value of 10000 are automatically increased to that value.
|
|
164
261
|
|
|
165
262
|
## Development
|
|
166
263
|
|
|
@@ -214,6 +311,54 @@ If you see this error, try using `bunx` instead of `npx`.
|
|
|
214
311
|
|
|
215
312
|
This often resolves module resolution issues, especially in environments where `npx` does not properly install or resolve packages.
|
|
216
313
|
|
|
314
|
+
### ESM Resolution Issues
|
|
315
|
+
|
|
316
|
+
If you encounter an error like: `Error: Cannot find module 'uriTemplate.js'` try running with the `--experimental-vm-modules` flag:
|
|
317
|
+
|
|
318
|
+
```json
|
|
319
|
+
{
|
|
320
|
+
"mcpServers": {
|
|
321
|
+
"context7": {
|
|
322
|
+
"command": "npx",
|
|
323
|
+
"args": [
|
|
324
|
+
"-y",
|
|
325
|
+
"--node-options=--experimental-vm-modules",
|
|
326
|
+
"@upstash/context7-mcp@1.0.6"
|
|
327
|
+
]
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### MCP Client Errors
|
|
334
|
+
|
|
335
|
+
1. Try removing `@latest` from the package name.
|
|
336
|
+
|
|
337
|
+
2. Try using `bunx` as an alternative.
|
|
338
|
+
|
|
339
|
+
3. Try using `deno` as an alternative.
|
|
340
|
+
|
|
341
|
+
4. Make sure you are using Node v18 or higher to have native fetch support with `npx`.
|
|
342
|
+
|
|
343
|
+
## Disclaimer
|
|
344
|
+
|
|
345
|
+
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.
|
|
346
|
+
|
|
347
|
+
## Context7 In Media
|
|
348
|
+
|
|
349
|
+
- [Better Stack: "Free Tool Makes Cursor 10x Smarter"](https://youtu.be/52FC3qObp9E)
|
|
350
|
+
- [Cole Medin: "This is Hands Down the BEST MCP Server for AI Coding Assistants"](https://www.youtube.com/watch?v=G7gK8H6u7Rs)
|
|
351
|
+
- [Income stream surfers: "Context7 + SequentialThinking MCPs: Is This AGI?"](https://www.youtube.com/watch?v=-ggvzyLpK6o)
|
|
352
|
+
- [Julian Goldie SEO: "Context7: New MCP AI Agent Update"](https://www.youtube.com/watch?v=CTZm6fBYisc)
|
|
353
|
+
- [JeredBlu: "Context 7 MCP: Get Documentation Instantly + VS Code Setup"](https://www.youtube.com/watch?v=-ls0D-rtET4)
|
|
354
|
+
- [Income stream surfers: "Context7: The New MCP Server That Will CHANGE AI Coding"](https://www.youtube.com/watch?v=PS-2Azb-C3M)
|
|
355
|
+
- [AICodeKing: "Context7 + Cline & RooCode: This MCP Server Makes CLINE 100X MORE EFFECTIVE!"](https://www.youtube.com/watch?v=qZfENAPMnyo)
|
|
356
|
+
- [Sean Kochel: "5 MCP Servers For Vibe Coding Glory (Just Plug-In & Go)"](https://www.youtube.com/watch?v=LqTQi8qexJM)
|
|
357
|
+
|
|
358
|
+
## Star History
|
|
359
|
+
|
|
360
|
+
[](https://www.star-history.com/#upstash/context7&Date)
|
|
361
|
+
|
|
217
362
|
## License
|
|
218
363
|
|
|
219
364
|
MIT
|
package/dist/index.js
CHANGED
|
@@ -4,19 +4,42 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { searchLibraries, fetchLibraryDocumentation } from "./lib/api.js";
|
|
6
6
|
import { formatSearchResults } from "./lib/utils.js";
|
|
7
|
-
|
|
7
|
+
import dotenv from "dotenv";
|
|
8
|
+
// Load environment variables from .env file if present
|
|
9
|
+
dotenv.config();
|
|
10
|
+
// Get DEFAULT_MINIMUM_TOKENS from environment variable or use default
|
|
11
|
+
let DEFAULT_MINIMUM_TOKENS = 10000;
|
|
12
|
+
if (process.env.DEFAULT_MINIMUM_TOKENS) {
|
|
13
|
+
const parsedValue = parseInt(process.env.DEFAULT_MINIMUM_TOKENS, 10);
|
|
14
|
+
if (!isNaN(parsedValue) && parsedValue > 0) {
|
|
15
|
+
DEFAULT_MINIMUM_TOKENS = parsedValue;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
console.warn(`Warning: Invalid DEFAULT_MINIMUM_TOKENS value provided in environment variable. Using default value of 10000`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
8
21
|
// Create server instance
|
|
9
22
|
const server = new McpServer({
|
|
10
23
|
name: "Context7",
|
|
11
24
|
description: "Retrieves up-to-date documentation and code examples for any library.",
|
|
12
|
-
version: "
|
|
25
|
+
version: "v1.0.7",
|
|
13
26
|
capabilities: {
|
|
14
27
|
resources: {},
|
|
15
28
|
tools: {},
|
|
16
29
|
},
|
|
17
30
|
});
|
|
18
31
|
// Register Context7 tools
|
|
19
|
-
server.tool("resolve-library-id",
|
|
32
|
+
server.tool("resolve-library-id", `Resolves a package name to a Context7-compatible library ID and returns a list of matching libraries.
|
|
33
|
+
|
|
34
|
+
You MUST call this function before 'get-library-docs' to obtain a valid Context7-compatible library ID.
|
|
35
|
+
|
|
36
|
+
When selecting the best match, consider:
|
|
37
|
+
- Name similarity to the query
|
|
38
|
+
- Description relevance
|
|
39
|
+
- Code Snippet count (documentation coverage)
|
|
40
|
+
- GitHub Stars (popularity)
|
|
41
|
+
|
|
42
|
+
Return the selected library ID and explain your choice. If there are multiple good matches, mention this but proceed with the most relevant one.`, {
|
|
20
43
|
libraryName: z
|
|
21
44
|
.string()
|
|
22
45
|
.describe("Library name to search for and retrieve a Context7-compatible library ID."),
|
|
@@ -47,7 +70,20 @@ server.tool("resolve-library-id", "Required first step: Resolves a general packa
|
|
|
47
70
|
content: [
|
|
48
71
|
{
|
|
49
72
|
type: "text",
|
|
50
|
-
text:
|
|
73
|
+
text: `Available Libraries (top matches):
|
|
74
|
+
|
|
75
|
+
Each result includes:
|
|
76
|
+
- Library ID: Context7-compatible identifier (format: /org/repo)
|
|
77
|
+
- Name: Library or package name
|
|
78
|
+
- Description: Short summary
|
|
79
|
+
- Code Snippets: Number of available code examples
|
|
80
|
+
- GitHub Stars: Popularity indicator
|
|
81
|
+
|
|
82
|
+
For best results, select libraries based on name match, popularity (stars), snippet coverage, and relevance to your use case.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
${resultsText}`,
|
|
51
87
|
},
|
|
52
88
|
],
|
|
53
89
|
};
|
|
@@ -62,9 +98,7 @@ server.tool("get-library-docs", "Fetches up-to-date documentation for a library.
|
|
|
62
98
|
.describe("Topic to focus documentation on (e.g., 'hooks', 'routing')."),
|
|
63
99
|
tokens: z
|
|
64
100
|
.preprocess((val) => (typeof val === "string" ? Number(val) : val), z.number())
|
|
65
|
-
.
|
|
66
|
-
message: `Must be a number >= ${DEFAULT_MINIMUM_TOKENS}`,
|
|
67
|
-
})
|
|
101
|
+
.transform((val) => (val < DEFAULT_MINIMUM_TOKENS ? DEFAULT_MINIMUM_TOKENS : val))
|
|
68
102
|
.optional()
|
|
69
103
|
.describe(`Maximum number of tokens of documentation to retrieve (default: ${DEFAULT_MINIMUM_TOKENS}). Higher values provide more context but consume more tokens.`),
|
|
70
104
|
}, async ({ context7CompatibleLibraryID, tokens = DEFAULT_MINIMUM_TOKENS, topic = "" }) => {
|
package/dist/lib/utils.js
CHANGED
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
* @returns Formatted search result string
|
|
5
5
|
*/
|
|
6
6
|
export function formatSearchResult(result) {
|
|
7
|
-
return
|
|
7
|
+
return `- Title: ${result.title}
|
|
8
|
+
- Context7-compatible library ID: ${result.id}
|
|
9
|
+
- Description: ${result.description}
|
|
10
|
+
- Code Snippets: ${result.totalSnippets}
|
|
11
|
+
- GitHub Stars: ${result.stars}`;
|
|
8
12
|
}
|
|
9
13
|
/**
|
|
10
14
|
* Format search results into a string representation
|
|
@@ -16,5 +20,5 @@ export function formatSearchResults(searchResponse) {
|
|
|
16
20
|
return "No documentation libraries found matching your query.";
|
|
17
21
|
}
|
|
18
22
|
const formattedResults = searchResponse.results.map(formatSearchResult);
|
|
19
|
-
return formattedResults.join("\n
|
|
23
|
+
return formattedResults.join("\n---\n");
|
|
20
24
|
}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@upstash/context7-mcp","version":"v1.0.
|
|
1
|
+
{"name":"@upstash/context7-mcp","version":"v1.0.7","description":"MCP server for Context7","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"tsc && chmod 755 dist/index.js","format":"prettier --write .","lint":"eslint \"**/*.{js,ts,tsx}\" --fix"},"repository":{"type":"git","url":"git+https://github.com/upstash/context7.git"},"keywords":["modelcontextprotocol","mcp","context7"],"author":"abdush","license":"MIT","type":"module","bin":{"context7-mcp":"dist/index.js"},"files":["dist"],"bugs":{"url":"https://github.com/upstash/context7/issues"},"homepage":"https://github.com/upstash/context7#readme","dependencies":{"@modelcontextprotocol/sdk":"^1.8.0","dotenv":"^16.5.0","zod":"^3.24.2"},"devDependencies":{"@types/node":"^22.13.14","@typescript-eslint/eslint-plugin":"^8.28.0","@typescript-eslint/parser":"^8.28.0","eslint":"^9.23.0","eslint-config-prettier":"^10.1.1","eslint-plugin-prettier":"^5.2.5","prettier":"^3.5.3","typescript":"^5.8.2","typescript-eslint":"^8.28.0"}}
|