@upstash/context7-mcp 1.0.0 → 1.0.1-rc
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 +61 -37
- package/{build → dist}/index.js +12 -12
- package/{build → dist}/lib/utils.js +1 -1
- package/package.json +4 -4
- /package/{build → dist}/lib/api.js +0 -0
- /package/{build → dist}/lib/types.js +0 -0
package/README.md
CHANGED
|
@@ -1,34 +1,66 @@
|
|
|
1
|
-
# Context7 MCP
|
|
1
|
+
# Context7 MCP - Up-to-date Docs For Any Cursor Prompt
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## ❌ Without Context7
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
LLMs rely on outdated or generic information about the libraries you use. You get:
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
- "Get examples of using React Query"
|
|
7
|
+
- ❌ Code examples are outdated and based on year-old training data
|
|
8
|
+
- ❌ Hallucinated APIs don't even exist
|
|
9
|
+
- ❌ Generic answers for old package versions
|
|
11
10
|
|
|
12
|
-
##
|
|
11
|
+
## ✅ With Context7
|
|
12
|
+
|
|
13
|
+
Context7 MCP pulls up-to-date, version-specific documentation and code examples straight from the source — and places them directly into your prompt.
|
|
14
|
+
|
|
15
|
+
Add `use context7` to your question in Cursor:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
"How do I use the new Next.js `after` function? use context7"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
"How do I invalidate a query in React Query? use context7"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
"How do I protect a route with NextAuth? use context7"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Context7 fetches up-to-date documentation and working code examples right into your LLM’s context.
|
|
30
|
+
|
|
31
|
+
- 1️⃣ Ask your question naturally
|
|
32
|
+
- 2️⃣ Tell the LLM to `use context7`
|
|
33
|
+
- 3️⃣ Get working code answers
|
|
34
|
+
|
|
35
|
+
No tab-switching, no hallucinated APIs that don't exist, no outdated code generations.
|
|
36
|
+
|
|
37
|
+
## 🛠️ Getting Started
|
|
13
38
|
|
|
14
39
|
### Requirements
|
|
15
40
|
|
|
16
41
|
- Node.js >= v18.0.0
|
|
17
42
|
- Cursor, Windsurf, Claude Desktop or another MCP Client
|
|
18
43
|
|
|
19
|
-
###
|
|
44
|
+
### Install in Cursor
|
|
20
45
|
|
|
21
|
-
|
|
46
|
+
Go to: `Settings` -> `Cursor Settings` -> `MCP` -> `Add new global MCP server`
|
|
22
47
|
|
|
23
|
-
|
|
48
|
+
Paste this into your Cursor `~/.cursor/mcp.json` file. See [Cursor MCP docs](https://docs.cursor.com/context/model-context-protocol) for more info.
|
|
24
49
|
|
|
25
|
-
```
|
|
26
|
-
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"mcpServers": {
|
|
53
|
+
"context7": {
|
|
54
|
+
"command": "npx",
|
|
55
|
+
"args": ["-y", "@upstash/context7-mcp"]
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
27
59
|
```
|
|
28
60
|
|
|
29
|
-
|
|
61
|
+
### Install in Windsurf
|
|
30
62
|
|
|
31
|
-
Add this to your Windsurf MCP config file.
|
|
63
|
+
Add this to your Windsurf MCP config file. See [Windsurf MCP docs](https://docs.windsurf.com/windsurf/mcp) for more info.
|
|
32
64
|
|
|
33
65
|
```json
|
|
34
66
|
{
|
|
@@ -41,43 +73,37 @@ Add this to your Windsurf MCP config file. For more info, check the [Windsurf MC
|
|
|
41
73
|
}
|
|
42
74
|
```
|
|
43
75
|
|
|
44
|
-
### Tools
|
|
76
|
+
### Available Tools
|
|
45
77
|
|
|
46
|
-
- `
|
|
47
|
-
- `
|
|
48
|
-
|
|
49
|
-
- `
|
|
50
|
-
- `
|
|
78
|
+
- `resolve-library-id`: Resolves a general npm package name into a Context7-compatible library ID.
|
|
79
|
+
- `libraryName` (optional): Search and rerank results
|
|
80
|
+
- `get-library-docs`: Fetches documentation for a library using a Context7-compatible library ID.
|
|
81
|
+
- `context7CompatibleLibraryID` (required)
|
|
82
|
+
- `topic` (optional): Focus the docs on a specific topic (e.g., "routing", "hooks")
|
|
83
|
+
- `tokens` (optional, default 5000): Max number of tokens to return
|
|
51
84
|
|
|
52
85
|
## Development
|
|
53
86
|
|
|
54
|
-
Clone the project and
|
|
87
|
+
Clone the project and install dependencies:
|
|
55
88
|
|
|
56
89
|
```bash
|
|
57
|
-
|
|
90
|
+
bun i
|
|
58
91
|
```
|
|
59
92
|
|
|
60
|
-
|
|
93
|
+
Build:
|
|
61
94
|
|
|
62
95
|
```bash
|
|
63
|
-
|
|
64
|
-
npm run lint
|
|
96
|
+
bun run build
|
|
65
97
|
```
|
|
66
98
|
|
|
67
|
-
###
|
|
68
|
-
|
|
69
|
-
```bash
|
|
70
|
-
npm run build
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
### Local Configuration
|
|
99
|
+
### Local Configuration Example
|
|
74
100
|
|
|
75
101
|
```json
|
|
76
102
|
{
|
|
77
103
|
"mcpServers": {
|
|
78
104
|
"context7": {
|
|
79
|
-
"command": "
|
|
80
|
-
"args": ["/
|
|
105
|
+
"command": "npx",
|
|
106
|
+
"args": ["tsx", "/path/to/folder/context7-mcp/src/index.ts"]
|
|
81
107
|
}
|
|
82
108
|
}
|
|
83
109
|
}
|
|
@@ -85,8 +111,6 @@ npm run build
|
|
|
85
111
|
|
|
86
112
|
### Testing with MCP Inspector
|
|
87
113
|
|
|
88
|
-
You can also use the MCP Inspector to test the tools by following the MCP documentation for setting up the inspector.
|
|
89
|
-
|
|
90
114
|
```bash
|
|
91
115
|
npx -y @modelcontextprotocol/inspector npx @upstash/context7-mcp
|
|
92
116
|
```
|
package/{build → dist}/index.js
RENAMED
|
@@ -7,7 +7,7 @@ import { formatProjectsList, rerankProjects } from "./lib/utils.js";
|
|
|
7
7
|
// Create server instance
|
|
8
8
|
const server = new McpServer({
|
|
9
9
|
name: "Context7",
|
|
10
|
-
description: "Retrieves documentation and code examples for
|
|
10
|
+
description: "Retrieves up-to-date documentation and code examples for npm packages.",
|
|
11
11
|
version: "1.0.0",
|
|
12
12
|
capabilities: {
|
|
13
13
|
resources: {},
|
|
@@ -15,11 +15,11 @@ const server = new McpServer({
|
|
|
15
15
|
},
|
|
16
16
|
});
|
|
17
17
|
// Register Context7 tools
|
|
18
|
-
server.tool("
|
|
18
|
+
server.tool("resolve-library-id", "Required first step: Resolves a general package name into a Context7-compatible library ID. Must be called before using 'get-library-docs' to retrieve a valid Context7-compatible library ID.", {
|
|
19
19
|
libraryName: z
|
|
20
20
|
.string()
|
|
21
21
|
.optional()
|
|
22
|
-
.describe("Optional library name to search for and rerank results based on"),
|
|
22
|
+
.describe("Optional library name to search for and rerank results based on."),
|
|
23
23
|
}, async ({ libraryName }) => {
|
|
24
24
|
const projects = await fetchProjects();
|
|
25
25
|
if (!projects) {
|
|
@@ -53,32 +53,32 @@ server.tool("list-available-docs", "Lists all available library documentation fr
|
|
|
53
53
|
content: [
|
|
54
54
|
{
|
|
55
55
|
type: "text",
|
|
56
|
-
text: projectsText,
|
|
56
|
+
text: "Available libraries and their Context7-compatible library ID:\n\n" + projectsText,
|
|
57
57
|
},
|
|
58
58
|
],
|
|
59
59
|
};
|
|
60
60
|
});
|
|
61
|
-
server.tool("get-library-
|
|
62
|
-
|
|
61
|
+
server.tool("get-library-docs", "Fetches up-to-date documentation for a library. You must call 'resolve-library-id' first to obtain the exact Context7-compatible library ID required to use this tool.", {
|
|
62
|
+
context7CompatibleLibraryID: z
|
|
63
63
|
.string()
|
|
64
|
-
.describe("
|
|
64
|
+
.describe("Exact Context7-compatible library ID (e.g., 'mongodb/docs', 'vercel/nextjs') retrieved from 'resolve-library-id'."),
|
|
65
65
|
topic: z
|
|
66
66
|
.string()
|
|
67
67
|
.optional()
|
|
68
|
-
.describe("
|
|
68
|
+
.describe("Topic to focus documentation on (e.g., 'hooks', 'routing')."),
|
|
69
69
|
tokens: z
|
|
70
70
|
.number()
|
|
71
71
|
.min(5000)
|
|
72
72
|
.optional()
|
|
73
|
-
.describe("Maximum number of tokens of documentation to retrieve (default: 5000). Higher values provide more
|
|
74
|
-
}, async ({
|
|
75
|
-
const documentationText = await fetchLibraryDocumentation(
|
|
73
|
+
.describe("Maximum number of tokens of documentation to retrieve (default: 5000). Higher values provide more context but consume more tokens."),
|
|
74
|
+
}, async ({ context7CompatibleLibraryID, tokens = 5000, topic = "" }) => {
|
|
75
|
+
const documentationText = await fetchLibraryDocumentation(context7CompatibleLibraryID, tokens, topic);
|
|
76
76
|
if (!documentationText) {
|
|
77
77
|
return {
|
|
78
78
|
content: [
|
|
79
79
|
{
|
|
80
80
|
type: "text",
|
|
81
|
-
text: "Documentation not found or not finalized for this library.
|
|
81
|
+
text: "Documentation not found or not finalized for this library. This might have happened because you used an invalid Context7-compatible library ID. To get a valid Context7-compatible library ID, use the 'resolve-library-id' with the package name you wish to retrieve documentation for.",
|
|
82
82
|
},
|
|
83
83
|
],
|
|
84
84
|
};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @returns Formatted project string
|
|
5
5
|
*/
|
|
6
6
|
export function formatProject(project) {
|
|
7
|
-
return `Title: ${project.settings.title}\
|
|
7
|
+
return `Title: ${project.settings.title}\nContext7-compatible library ID: ${project.settings.project}\n`;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Format a list of projects into a string representation
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upstash/context7-mcp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-rc",
|
|
4
4
|
"description": "MCP server for Context7",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
|
-
"build": "tsc && chmod 755
|
|
7
|
+
"build": "tsc && chmod 755 dist/index.js",
|
|
8
8
|
"format": "prettier --write .",
|
|
9
9
|
"lint": "eslint \"**/*.{js,ts,tsx}\" --fix"
|
|
10
10
|
},
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"type": "module",
|
|
19
19
|
"bin": {
|
|
20
|
-
"context7-mcp": "
|
|
20
|
+
"context7-mcp": "dist/index.js"
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
23
|
-
"
|
|
23
|
+
"dist"
|
|
24
24
|
],
|
|
25
25
|
"bugs": {
|
|
26
26
|
"url": "https://github.com/upstash/context7-mcp/issues"
|
|
File without changes
|
|
File without changes
|