@upstash/context7-mcp 1.0.12 → 1.0.14
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 +349 -106
- package/dist/index.js +192 -88
- package/dist/lib/api.js +26 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
|
|
3
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
4
|
|
|
5
|
-
[](./docs/README.zh-TW.md) [](./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) [](./docs/README.tr.md) [](./docs/README.ar.md)
|
|
7
6
|
|
|
8
7
|
## ❌ Without Context7
|
|
9
8
|
|
|
@@ -35,27 +34,57 @@ Context7 fetches up-to-date code examples and documentation right into your LLM'
|
|
|
35
34
|
|
|
36
35
|
No tab-switching, no hallucinated APIs that don't exist, no outdated code generations.
|
|
37
36
|
|
|
38
|
-
##
|
|
37
|
+
## 📚 Adding Projects
|
|
38
|
+
|
|
39
|
+
Check out our [project addition guide](./docs/adding-projects.md) to learn how to add (or update) your favorite libraries to Context7.
|
|
40
|
+
|
|
41
|
+
## 🛠️ Installation
|
|
39
42
|
|
|
40
43
|
### Requirements
|
|
41
44
|
|
|
42
45
|
- Node.js >= v18.0.0
|
|
43
46
|
- Cursor, Windsurf, Claude Desktop or another MCP Client
|
|
44
47
|
|
|
45
|
-
|
|
48
|
+
<details>
|
|
49
|
+
<summary><b>Installing via Smithery</b></summary>
|
|
46
50
|
|
|
47
|
-
To install Context7 MCP Server for
|
|
51
|
+
To install Context7 MCP Server for any client automatically via [Smithery](https://smithery.ai/server/@upstash/context7-mcp):
|
|
48
52
|
|
|
49
53
|
```bash
|
|
50
|
-
npx -y @smithery/cli install @upstash/context7-mcp --client
|
|
54
|
+
npx -y @smithery/cli@latest install @upstash/context7-mcp --client <CLIENT_NAME> --key <YOUR_SMITHERY_KEY>
|
|
51
55
|
```
|
|
52
56
|
|
|
53
|
-
|
|
57
|
+
You can find your Smithery key in the [Smithery.ai webpage](https://smithery.ai/server/@upstash/context7-mcp).
|
|
58
|
+
|
|
59
|
+
</details>
|
|
60
|
+
|
|
61
|
+
<details>
|
|
62
|
+
<summary><b>Install in Cursor</b></summary>
|
|
54
63
|
|
|
55
64
|
Go to: `Settings` -> `Cursor Settings` -> `MCP` -> `Add new global MCP server`
|
|
56
65
|
|
|
57
66
|
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
67
|
|
|
68
|
+
> Since Cursor 1.0, you can click the install button below for instant one-click installation.
|
|
69
|
+
|
|
70
|
+
#### Cursor Remote Server Connection
|
|
71
|
+
|
|
72
|
+
[](https://cursor.com/install-mcp?name=context7&config=eyJ1cmwiOiJodHRwczovL21jcC5jb250ZXh0Ny5jb20vbWNwIn0%3D)
|
|
73
|
+
|
|
74
|
+
```json
|
|
75
|
+
{
|
|
76
|
+
"mcpServers": {
|
|
77
|
+
"context7": {
|
|
78
|
+
"url": "https://mcp.context7.com/mcp"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### Cursor Local Server Connection
|
|
85
|
+
|
|
86
|
+
[](https://cursor.com/install-mcp?name=context7&config=eyJjb21tYW5kIjoibnB4IC15IEB1cHN0YXNoL2NvbnRleHQ3LW1jcCJ9)
|
|
87
|
+
|
|
59
88
|
```json
|
|
60
89
|
{
|
|
61
90
|
"mcpServers": {
|
|
@@ -70,6 +99,8 @@ Pasting the following configuration into your Cursor `~/.cursor/mcp.json` file i
|
|
|
70
99
|
<details>
|
|
71
100
|
<summary>Alternative: Use Bun</summary>
|
|
72
101
|
|
|
102
|
+
[](https://cursor.com/install-mcp?name=context7&config=eyJjb21tYW5kIjoiYnVueCAteSBAdXBzdGFzaC9jb250ZXh0Ny1tY3AifQ%3D%3D)
|
|
103
|
+
|
|
73
104
|
```json
|
|
74
105
|
{
|
|
75
106
|
"mcpServers": {
|
|
@@ -86,6 +117,8 @@ Pasting the following configuration into your Cursor `~/.cursor/mcp.json` file i
|
|
|
86
117
|
<details>
|
|
87
118
|
<summary>Alternative: Use Deno</summary>
|
|
88
119
|
|
|
120
|
+
[](https://cursor.com/install-mcp?name=context7&config=eyJjb21tYW5kIjoiZGVubyBydW4gLS1hbGxvdy1lbnYgLS1hbGxvdy1uZXQgbnBtOkB1cHN0YXNoL2NvbnRleHQ3LW1jcCJ9)
|
|
121
|
+
|
|
89
122
|
```json
|
|
90
123
|
{
|
|
91
124
|
"mcpServers": {
|
|
@@ -99,10 +132,27 @@ Pasting the following configuration into your Cursor `~/.cursor/mcp.json` file i
|
|
|
99
132
|
|
|
100
133
|
</details>
|
|
101
134
|
|
|
102
|
-
|
|
135
|
+
</details>
|
|
136
|
+
|
|
137
|
+
<details>
|
|
138
|
+
<summary><b>Install in Windsurf</b></summary>
|
|
103
139
|
|
|
104
140
|
Add this to your Windsurf MCP config file. See [Windsurf MCP docs](https://docs.windsurf.com/windsurf/mcp) for more info.
|
|
105
141
|
|
|
142
|
+
#### Windsurf Remote Server Connection
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"mcpServers": {
|
|
147
|
+
"context7": {
|
|
148
|
+
"serverUrl": "https://mcp.context7.com/sse"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
#### Windsurf Local Server Connection
|
|
155
|
+
|
|
106
156
|
```json
|
|
107
157
|
{
|
|
108
158
|
"mcpServers": {
|
|
@@ -114,17 +164,35 @@ Add this to your Windsurf MCP config file. See [Windsurf MCP docs](https://docs.
|
|
|
114
164
|
}
|
|
115
165
|
```
|
|
116
166
|
|
|
117
|
-
|
|
167
|
+
</details>
|
|
168
|
+
|
|
169
|
+
<details>
|
|
170
|
+
<summary><b>Install in VS Code</b></summary>
|
|
118
171
|
|
|
119
172
|
[<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)
|
|
120
173
|
[<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)
|
|
121
174
|
|
|
122
175
|
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.
|
|
123
176
|
|
|
177
|
+
#### VS Code Remote Server Connection
|
|
178
|
+
|
|
124
179
|
```json
|
|
125
|
-
{
|
|
180
|
+
"mcp": {
|
|
126
181
|
"servers": {
|
|
127
|
-
"
|
|
182
|
+
"context7": {
|
|
183
|
+
"type": "http",
|
|
184
|
+
"url": "https://mcp.context7.com/mcp"
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
#### VS Code Local Server Connection
|
|
191
|
+
|
|
192
|
+
```json
|
|
193
|
+
"mcp": {
|
|
194
|
+
"servers": {
|
|
195
|
+
"context7": {
|
|
128
196
|
"type": "stdio",
|
|
129
197
|
"command": "npx",
|
|
130
198
|
"args": ["-y", "@upstash/context7-mcp"]
|
|
@@ -133,7 +201,49 @@ Add this to your VS Code MCP config file. See [VS Code MCP docs](https://code.vi
|
|
|
133
201
|
}
|
|
134
202
|
```
|
|
135
203
|
|
|
136
|
-
|
|
204
|
+
</details>
|
|
205
|
+
|
|
206
|
+
<details>
|
|
207
|
+
<summary><b>Install in Visual Studio 2022</b></summary>
|
|
208
|
+
|
|
209
|
+
You can configure Context7 MCP in Visual Studio 2022 by following the [Visual Studio MCP Servers documentation](https://learn.microsoft.com/visualstudio/ide/mcp-servers?view=vs-2022).
|
|
210
|
+
|
|
211
|
+
Add this to your Visual Studio MCP config file (see the [Visual Studio docs](https://learn.microsoft.com/visualstudio/ide/mcp-servers?view=vs-2022) for details):
|
|
212
|
+
|
|
213
|
+
```json
|
|
214
|
+
{
|
|
215
|
+
"mcp": {
|
|
216
|
+
"servers": {
|
|
217
|
+
"context7": {
|
|
218
|
+
"type": "http",
|
|
219
|
+
"url": "https://mcp.context7.com/mcp"
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Or, for a local server:
|
|
227
|
+
|
|
228
|
+
```json
|
|
229
|
+
{
|
|
230
|
+
"mcp": {
|
|
231
|
+
"servers": {
|
|
232
|
+
"context7": {
|
|
233
|
+
"type": "stdio",
|
|
234
|
+
"command": "npx",
|
|
235
|
+
"args": ["-y", "@upstash/context7-mcp"]
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
For more information and troubleshooting, refer to the [Visual Studio MCP Servers documentation](https://learn.microsoft.com/visualstudio/ide/mcp-servers?view=vs-2022).
|
|
243
|
+
</details>
|
|
244
|
+
|
|
245
|
+
<details>
|
|
246
|
+
<summary><b>Install in Zed</b></summary>
|
|
137
247
|
|
|
138
248
|
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.
|
|
139
249
|
|
|
@@ -151,15 +261,29 @@ It can be installed via [Zed Extensions](https://zed.dev/extensions?query=Contex
|
|
|
151
261
|
}
|
|
152
262
|
```
|
|
153
263
|
|
|
154
|
-
|
|
264
|
+
</details>
|
|
265
|
+
|
|
266
|
+
<details>
|
|
267
|
+
<summary><b>Install in Claude Code</b></summary>
|
|
155
268
|
|
|
156
269
|
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.
|
|
157
270
|
|
|
271
|
+
#### Claude Code Remote Server Connection
|
|
272
|
+
|
|
273
|
+
```sh
|
|
274
|
+
claude mcp add --transport sse context7 https://mcp.context7.com/sse
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
#### Claude Code Local Server Connection
|
|
278
|
+
|
|
158
279
|
```sh
|
|
159
280
|
claude mcp add context7 -- npx -y @upstash/context7-mcp
|
|
160
281
|
```
|
|
161
282
|
|
|
162
|
-
|
|
283
|
+
</details>
|
|
284
|
+
|
|
285
|
+
<details>
|
|
286
|
+
<summary><b>Install in Claude Desktop</b></summary>
|
|
163
287
|
|
|
164
288
|
Add this to your Claude Desktop `claude_desktop_config.json` file. See [Claude Desktop MCP docs](https://modelcontextprotocol.io/quickstart/user) for more info.
|
|
165
289
|
|
|
@@ -174,7 +298,10 @@ Add this to your Claude Desktop `claude_desktop_config.json` file. See [Claude D
|
|
|
174
298
|
}
|
|
175
299
|
```
|
|
176
300
|
|
|
177
|
-
|
|
301
|
+
</details>
|
|
302
|
+
|
|
303
|
+
<details>
|
|
304
|
+
<summary><b>Install in BoltAI</b></summary>
|
|
178
305
|
|
|
179
306
|
Open the "Settings" page of the app, navigate to "Plugins," and enter the following JSON:
|
|
180
307
|
|
|
@@ -191,76 +318,79 @@ Open the "Settings" page of the app, navigate to "Plugins," and enter the follow
|
|
|
191
318
|
|
|
192
319
|
Once saved, enter in the chat `get-library-docs` followed by your Context7 documentation ID (e.g., `get-library-docs /nuxt/ui`). More information is available on [BoltAI's Documentation site](https://docs.boltai.com/docs/plugins/mcp-servers). For BoltAI on iOS, [see this guide](https://docs.boltai.com/docs/boltai-mobile/mcp-servers).
|
|
193
320
|
|
|
194
|
-
|
|
321
|
+
</details>
|
|
322
|
+
|
|
323
|
+
<details>
|
|
324
|
+
<summary><b>Using Docker</b></summary>
|
|
195
325
|
|
|
196
326
|
If you prefer to run the MCP server in a Docker container:
|
|
197
327
|
|
|
198
|
-
1.
|
|
328
|
+
1. **Build the Docker Image:**
|
|
199
329
|
|
|
200
|
-
|
|
330
|
+
First, create a `Dockerfile` in the project root (or anywhere you prefer):
|
|
201
331
|
|
|
202
|
-
|
|
203
|
-
|
|
332
|
+
<details>
|
|
333
|
+
<summary>Click to see Dockerfile content</summary>
|
|
204
334
|
|
|
205
|
-
|
|
206
|
-
|
|
335
|
+
```Dockerfile
|
|
336
|
+
FROM node:18-alpine
|
|
207
337
|
|
|
208
|
-
|
|
338
|
+
WORKDIR /app
|
|
209
339
|
|
|
210
|
-
|
|
211
|
-
|
|
340
|
+
# Install the latest version globally
|
|
341
|
+
RUN npm install -g @upstash/context7-mcp
|
|
212
342
|
|
|
213
|
-
|
|
214
|
-
|
|
343
|
+
# Expose default port if needed (optional, depends on MCP client interaction)
|
|
344
|
+
# EXPOSE 3000
|
|
215
345
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
346
|
+
# Default command to run the server
|
|
347
|
+
CMD ["context7-mcp"]
|
|
348
|
+
```
|
|
219
349
|
|
|
220
|
-
|
|
350
|
+
</details>
|
|
221
351
|
|
|
222
|
-
|
|
352
|
+
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`:
|
|
223
353
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
354
|
+
```bash
|
|
355
|
+
docker build -t context7-mcp .
|
|
356
|
+
```
|
|
227
357
|
|
|
228
358
|
2. **Configure Your MCP Client:**
|
|
229
359
|
|
|
230
|
-
|
|
360
|
+
Update your MCP client's configuration to use the Docker command.
|
|
231
361
|
|
|
232
|
-
|
|
362
|
+
_Example for a cline_mcp_settings.json:_
|
|
233
363
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
364
|
+
```json
|
|
365
|
+
{
|
|
366
|
+
"mcpServers": {
|
|
367
|
+
"Сontext7": {
|
|
368
|
+
"autoApprove": [],
|
|
369
|
+
"disabled": false,
|
|
370
|
+
"timeout": 60,
|
|
371
|
+
"command": "docker",
|
|
372
|
+
"args": ["run", "-i", "--rm", "context7-mcp"],
|
|
373
|
+
"transportType": "stdio"
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
_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._
|
|
380
|
+
|
|
381
|
+
</details>
|
|
382
|
+
|
|
383
|
+
<details>
|
|
384
|
+
<summary><b>Install in Windows</b></summary>
|
|
248
385
|
|
|
249
|
-
|
|
386
|
+
The configuration on Windows is slightly different compared to Linux or macOS (_`Cline` is used in the example_). The same principle applies to other editors; refer to the configuration of `command` and `args`.
|
|
250
387
|
|
|
251
|
-
### Install in Windows
|
|
252
|
-
The configuration on Windows is slightly different compared to Linux or macOS (*`Cline` is used in the example*). The same principle applies to other editors; refer to the configuration of `command` and `args`.
|
|
253
388
|
```json
|
|
254
389
|
{
|
|
255
390
|
"mcpServers": {
|
|
256
391
|
"github.com/upstash/context7-mcp": {
|
|
257
392
|
"command": "cmd",
|
|
258
|
-
"args": [
|
|
259
|
-
"/c",
|
|
260
|
-
"npx",
|
|
261
|
-
"-y",
|
|
262
|
-
"@upstash/context7-mcp"
|
|
263
|
-
],
|
|
393
|
+
"args": ["/c", "npx", "-y", "@upstash/context7-mcp@latest"],
|
|
264
394
|
"disabled": false,
|
|
265
395
|
"autoApprove": []
|
|
266
396
|
}
|
|
@@ -268,36 +398,122 @@ The configuration on Windows is slightly different compared to Linux or macOS (*
|
|
|
268
398
|
}
|
|
269
399
|
```
|
|
270
400
|
|
|
271
|
-
|
|
401
|
+
</details>
|
|
402
|
+
|
|
403
|
+
<details>
|
|
404
|
+
<summary><b>Install in Augment Code</b></summary>
|
|
272
405
|
|
|
273
|
-
|
|
406
|
+
To configure Context7 MCP in Augment Code, follow these steps:
|
|
274
407
|
|
|
275
|
-
|
|
408
|
+
1. Press Cmd/Ctrl Shift P or go to the hamburger menu in the Augment panel
|
|
409
|
+
2. Select Edit Settings
|
|
410
|
+
3. Under Advanced, click Edit in settings.json
|
|
411
|
+
4. Add the server configuration to the `mcpServers` array in the `augment.advanced` object
|
|
412
|
+
|
|
413
|
+
```json
|
|
414
|
+
"augment.advanced": {
|
|
415
|
+
"mcpServers": [
|
|
416
|
+
{
|
|
417
|
+
"name": "context7",
|
|
418
|
+
"command": "npx",
|
|
419
|
+
"args": ["-y", "@upstash/context7-mcp"]
|
|
420
|
+
}
|
|
421
|
+
]
|
|
422
|
+
}
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
Once the MCP server is added, restart your editor. If you receive any errors, check the syntax to make sure closing brackets or commas are not missing.
|
|
426
|
+
|
|
427
|
+
</details>
|
|
428
|
+
|
|
429
|
+
<details>
|
|
430
|
+
<summary><b>Install in Roo Code</b></summary>
|
|
431
|
+
|
|
432
|
+
Add this to your Roo Code MCP configuration file. See [Roo Code MCP docs](https://docs.roocode.com/features/mcp/using-mcp-in-roo) for more info.
|
|
433
|
+
|
|
434
|
+
#### Roo Code Remote Server Connection
|
|
435
|
+
|
|
436
|
+
```json
|
|
437
|
+
{
|
|
438
|
+
"mcpServers": {
|
|
439
|
+
"context7": {
|
|
440
|
+
"type": "streamable-http",
|
|
441
|
+
"url": "https://mcp.context7.com/mcp"
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
#### Roo Code Local Server Connection
|
|
276
448
|
|
|
277
449
|
```json
|
|
278
450
|
{
|
|
279
451
|
"mcpServers": {
|
|
280
452
|
"context7": {
|
|
281
453
|
"command": "npx",
|
|
282
|
-
"args": ["-y", "@upstash/context7-mcp"]
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
454
|
+
"args": ["-y", "@upstash/context7-mcp"]
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
</details>
|
|
461
|
+
|
|
462
|
+
<details>
|
|
463
|
+
<summary><b>Install in Zencoder</b></summary>
|
|
464
|
+
|
|
465
|
+
To configure Context7 MCP in Zencoder, follow these steps:
|
|
466
|
+
|
|
467
|
+
1. Go to the Zencoder menu (...)
|
|
468
|
+
2. From the dropdown menu, select Agent tools
|
|
469
|
+
3. Click on the Add custom MCP
|
|
470
|
+
4. Add the name and server configuration from below, and make sure to hit the Install button
|
|
471
|
+
|
|
472
|
+
```json
|
|
473
|
+
{
|
|
474
|
+
"command": "npx",
|
|
475
|
+
"args": [
|
|
476
|
+
"-y",
|
|
477
|
+
"@upstash/context7-mcp@latest"
|
|
478
|
+
]
|
|
479
|
+
}
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
Once the MCP server is added, you can easily continue using it.
|
|
483
|
+
|
|
484
|
+
</details>
|
|
485
|
+
|
|
486
|
+
<details>
|
|
487
|
+
<summary><b>Install in Amazon Q Developer CLI</b></summary>
|
|
488
|
+
|
|
489
|
+
Add this to your Amazon Q Developer CLI configuration file. See [Amazon Q Developer CLI docs](https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/command-line-mcp-configuration.html) for more details.
|
|
490
|
+
|
|
491
|
+
```json
|
|
492
|
+
{
|
|
493
|
+
"mcpServers": {
|
|
494
|
+
"context7": {
|
|
495
|
+
"command": "npx",
|
|
496
|
+
"args": ["-y", "@upstash/context7-mcp@latest"]
|
|
286
497
|
}
|
|
287
498
|
}
|
|
288
499
|
}
|
|
289
500
|
```
|
|
501
|
+
</details>
|
|
502
|
+
|
|
503
|
+
## 🔨 Available Tools
|
|
290
504
|
|
|
291
|
-
|
|
505
|
+
Context7 MCP provides the following tools that LLMs can use:
|
|
292
506
|
|
|
293
507
|
- `resolve-library-id`: Resolves a general library name into a Context7-compatible library ID.
|
|
294
|
-
|
|
508
|
+
|
|
509
|
+
- `libraryName` (required): The name of the library to search for
|
|
510
|
+
|
|
295
511
|
- `get-library-docs`: Fetches documentation for a library using a Context7-compatible library ID.
|
|
296
|
-
- `context7CompatibleLibraryID` (required)
|
|
512
|
+
- `context7CompatibleLibraryID` (required): Exact Context7-compatible library ID (e.g., `/mongodb/docs`, `/vercel/next.js`)
|
|
297
513
|
- `topic` (optional): Focus the docs on a specific topic (e.g., "routing", "hooks")
|
|
298
|
-
- `tokens` (optional, default 10000): Max number of tokens to return. Values less than the
|
|
514
|
+
- `tokens` (optional, default 10000): Max number of tokens to return. Values less than the default value of 10000 are automatically increased to 10000.
|
|
299
515
|
|
|
300
|
-
## Development
|
|
516
|
+
## 💻 Development
|
|
301
517
|
|
|
302
518
|
Clone the project and install dependencies:
|
|
303
519
|
|
|
@@ -311,7 +527,27 @@ Build:
|
|
|
311
527
|
bun run build
|
|
312
528
|
```
|
|
313
529
|
|
|
314
|
-
|
|
530
|
+
Run the server:
|
|
531
|
+
|
|
532
|
+
```bash
|
|
533
|
+
bun run dist/index.js
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
### CLI Arguments
|
|
537
|
+
|
|
538
|
+
`context7-mcp` accepts the following CLI flags:
|
|
539
|
+
|
|
540
|
+
- `--transport <stdio|http|sse>` – Transport to use (`stdio` by default).
|
|
541
|
+
- `--port <number>` – Port to listen on when using `http` or `sse` transport (default `3000`).
|
|
542
|
+
|
|
543
|
+
Example with http transport and port 8080:
|
|
544
|
+
|
|
545
|
+
```bash
|
|
546
|
+
bun run dist/index.js --transport http --port 8080
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
<details>
|
|
550
|
+
<summary><b>Local Configuration Example</b></summary>
|
|
315
551
|
|
|
316
552
|
```json
|
|
317
553
|
{
|
|
@@ -324,17 +560,23 @@ bun run build
|
|
|
324
560
|
}
|
|
325
561
|
```
|
|
326
562
|
|
|
327
|
-
|
|
563
|
+
</details>
|
|
564
|
+
|
|
565
|
+
<details>
|
|
566
|
+
<summary><b>Testing with MCP Inspector</b></summary>
|
|
328
567
|
|
|
329
568
|
```bash
|
|
330
569
|
npx -y @modelcontextprotocol/inspector npx @upstash/context7-mcp
|
|
331
570
|
```
|
|
332
571
|
|
|
333
|
-
|
|
572
|
+
</details>
|
|
573
|
+
|
|
574
|
+
## 🚨 Troubleshooting
|
|
334
575
|
|
|
335
|
-
|
|
576
|
+
<details>
|
|
577
|
+
<summary><b>Module Not Found Errors</b></summary>
|
|
336
578
|
|
|
337
|
-
If you
|
|
579
|
+
If you encounter `ERR_MODULE_NOT_FOUND`, try using `bunx` instead of `npx`:
|
|
338
580
|
|
|
339
581
|
```json
|
|
340
582
|
{
|
|
@@ -347,82 +589,83 @@ If you see this error, try using `bunx` instead of `npx`.
|
|
|
347
589
|
}
|
|
348
590
|
```
|
|
349
591
|
|
|
350
|
-
This often resolves module resolution issues
|
|
592
|
+
This often resolves module resolution issues in environments where `npx` doesn't properly install or resolve packages.
|
|
593
|
+
|
|
594
|
+
</details>
|
|
351
595
|
|
|
352
|
-
|
|
596
|
+
<details>
|
|
597
|
+
<summary><b>ESM Resolution Issues</b></summary>
|
|
353
598
|
|
|
354
|
-
|
|
599
|
+
For errors like `Error: Cannot find module 'uriTemplate.js'`, try the `--experimental-vm-modules` flag:
|
|
355
600
|
|
|
356
601
|
```json
|
|
357
602
|
{
|
|
358
603
|
"mcpServers": {
|
|
359
604
|
"context7": {
|
|
360
605
|
"command": "npx",
|
|
361
|
-
"args": [
|
|
362
|
-
"-y",
|
|
363
|
-
"--node-options=--experimental-vm-modules",
|
|
364
|
-
"@upstash/context7-mcp"
|
|
365
|
-
]
|
|
606
|
+
"args": ["-y", "--node-options=--experimental-vm-modules", "@upstash/context7-mcp@1.0.6"]
|
|
366
607
|
}
|
|
367
608
|
}
|
|
368
609
|
}
|
|
369
610
|
```
|
|
370
611
|
|
|
371
|
-
|
|
612
|
+
</details>
|
|
613
|
+
|
|
614
|
+
<details>
|
|
615
|
+
<summary><b>TLS/Certificate Issues</b></summary>
|
|
372
616
|
|
|
373
|
-
Use the `--experimental-fetch` flag
|
|
617
|
+
Use the `--experimental-fetch` flag to bypass TLS-related problems:
|
|
374
618
|
|
|
375
619
|
```json
|
|
376
620
|
{
|
|
377
621
|
"mcpServers": {
|
|
378
622
|
"context7": {
|
|
379
623
|
"command": "npx",
|
|
380
|
-
"args": [
|
|
381
|
-
"-y",
|
|
382
|
-
"--node-options=--experimental-fetch",
|
|
383
|
-
"@upstash/context7-mcp"
|
|
384
|
-
]
|
|
624
|
+
"args": ["-y", "--node-options=--experimental-fetch", "@upstash/context7-mcp"]
|
|
385
625
|
}
|
|
386
626
|
}
|
|
387
627
|
}
|
|
388
628
|
```
|
|
389
629
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
1. Try adding `@latest` to the package name.
|
|
630
|
+
</details>
|
|
393
631
|
|
|
394
|
-
|
|
632
|
+
<details>
|
|
633
|
+
<summary><b>General MCP Client Errors</b></summary>
|
|
395
634
|
|
|
396
|
-
|
|
635
|
+
1. Try adding `@latest` to the package name
|
|
636
|
+
2. Use `bunx` as an alternative to `npx`
|
|
637
|
+
3. Consider using `deno` as another alternative
|
|
638
|
+
4. Ensure you're using Node.js v18 or higher for native fetch support
|
|
397
639
|
|
|
398
|
-
|
|
640
|
+
</details>
|
|
399
641
|
|
|
400
|
-
## Disclaimer
|
|
642
|
+
## ⚠️ Disclaimer
|
|
401
643
|
|
|
402
644
|
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.
|
|
403
645
|
|
|
404
|
-
## Connect with Us
|
|
646
|
+
## 🤝 Connect with Us
|
|
405
647
|
|
|
406
648
|
Stay updated and join our community:
|
|
649
|
+
|
|
407
650
|
- 📢 Follow us on [X](https://x.com/contextai) for the latest news and updates
|
|
408
651
|
- 🌐 Visit our [Website](https://context7.com)
|
|
409
|
-
- 💬 Join our [Discord Community](https://upstash.com/discord)
|
|
652
|
+
- 💬 Join our [Discord Community](https://upstash.com/discord)
|
|
410
653
|
|
|
411
|
-
## Context7 In Media
|
|
654
|
+
## 📺 Context7 In Media
|
|
412
655
|
|
|
413
656
|
- [Better Stack: "Free Tool Makes Cursor 10x Smarter"](https://youtu.be/52FC3qObp9E)
|
|
414
657
|
- [Cole Medin: "This is Hands Down the BEST MCP Server for AI Coding Assistants"](https://www.youtube.com/watch?v=G7gK8H6u7Rs)
|
|
415
|
-
- [Income
|
|
658
|
+
- [Income Stream Surfers: "Context7 + SequentialThinking MCPs: Is This AGI?"](https://www.youtube.com/watch?v=-ggvzyLpK6o)
|
|
416
659
|
- [Julian Goldie SEO: "Context7: New MCP AI Agent Update"](https://www.youtube.com/watch?v=CTZm6fBYisc)
|
|
417
660
|
- [JeredBlu: "Context 7 MCP: Get Documentation Instantly + VS Code Setup"](https://www.youtube.com/watch?v=-ls0D-rtET4)
|
|
418
|
-
- [Income
|
|
661
|
+
- [Income Stream Surfers: "Context7: The New MCP Server That Will CHANGE AI Coding"](https://www.youtube.com/watch?v=PS-2Azb-C3M)
|
|
419
662
|
- [AICodeKing: "Context7 + Cline & RooCode: This MCP Server Makes CLINE 100X MORE EFFECTIVE!"](https://www.youtube.com/watch?v=qZfENAPMnyo)
|
|
420
663
|
- [Sean Kochel: "5 MCP Servers For Vibe Coding Glory (Just Plug-In & Go)"](https://www.youtube.com/watch?v=LqTQi8qexJM)
|
|
421
664
|
|
|
422
|
-
## Star History
|
|
665
|
+
## ⭐ Star History
|
|
423
666
|
|
|
424
667
|
[](https://www.star-history.com/#upstash/context7&Date)
|
|
425
668
|
|
|
426
|
-
## License
|
|
669
|
+
## 📄 License
|
|
427
670
|
|
|
428
671
|
MIT
|
package/dist/index.js
CHANGED
|
@@ -4,32 +4,43 @@ 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
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
import { createServer } from "http";
|
|
8
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
9
|
+
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
|
|
10
|
+
import { Command } from "commander";
|
|
11
|
+
const DEFAULT_MINIMUM_TOKENS = 10000;
|
|
12
|
+
// Parse CLI arguments using commander
|
|
13
|
+
const program = new Command()
|
|
14
|
+
.option("--transport <stdio|http|sse>", "transport type", "stdio")
|
|
15
|
+
.option("--port <number>", "port for HTTP/SSE transport", "3000")
|
|
16
|
+
.allowUnknownOption() // let MCP Inspector / other wrappers pass through extra flags
|
|
17
|
+
.parse(process.argv);
|
|
18
|
+
const cliOptions = program.opts();
|
|
19
|
+
// Validate transport option
|
|
20
|
+
const allowedTransports = ["stdio", "http", "sse"];
|
|
21
|
+
if (!allowedTransports.includes(cliOptions.transport)) {
|
|
22
|
+
console.error(`Invalid --transport value: '${cliOptions.transport}'. Must be one of: stdio, http, sse.`);
|
|
23
|
+
process.exit(1);
|
|
20
24
|
}
|
|
21
|
-
//
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
server
|
|
25
|
+
// Transport configuration
|
|
26
|
+
const TRANSPORT_TYPE = (cliOptions.transport || "stdio");
|
|
27
|
+
// HTTP/SSE port configuration
|
|
28
|
+
const CLI_PORT = (() => {
|
|
29
|
+
const parsed = parseInt(cliOptions.port, 10);
|
|
30
|
+
return isNaN(parsed) ? undefined : parsed;
|
|
31
|
+
})();
|
|
32
|
+
// Store SSE transports by session ID
|
|
33
|
+
const sseTransports = {};
|
|
34
|
+
// Function to create a new server instance with all tools registered
|
|
35
|
+
function createServerInstance() {
|
|
36
|
+
const server = new McpServer({
|
|
37
|
+
name: "Context7",
|
|
38
|
+
version: "v1.0.14",
|
|
39
|
+
}, {
|
|
40
|
+
instructions: "Use this server to retrieve up-to-date documentation and code examples for any library.",
|
|
41
|
+
});
|
|
42
|
+
// Register Context7 tools
|
|
43
|
+
server.tool("resolve-library-id", `Resolves a package/product name to a Context7-compatible library ID and returns a list of matching libraries.
|
|
33
44
|
|
|
34
45
|
You MUST call this function before 'get-library-docs' to obtain a valid Context7-compatible library ID UNLESS the user explicitly provides a library ID in the format '/org/project' or '/org/project/version' in their query.
|
|
35
46
|
|
|
@@ -48,37 +59,29 @@ Response Format:
|
|
|
48
59
|
- If no good matches exist, clearly state this and suggest query refinements
|
|
49
60
|
|
|
50
61
|
For ambiguous queries, request clarification before proceeding with a best-guess match.`, {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}, async ({ libraryName }) => {
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
libraryName: z
|
|
63
|
+
.string()
|
|
64
|
+
.describe("Library name to search for and retrieve a Context7-compatible library ID."),
|
|
65
|
+
}, async ({ libraryName }) => {
|
|
66
|
+
const searchResponse = await searchLibraries(libraryName);
|
|
67
|
+
if (!searchResponse.results || searchResponse.results.length === 0) {
|
|
68
|
+
return {
|
|
69
|
+
content: [
|
|
70
|
+
{
|
|
71
|
+
type: "text",
|
|
72
|
+
text: searchResponse.error
|
|
73
|
+
? searchResponse.error
|
|
74
|
+
: "Failed to retrieve library documentation data from Context7",
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const resultsText = formatSearchResults(searchResponse);
|
|
57
80
|
return {
|
|
58
81
|
content: [
|
|
59
82
|
{
|
|
60
83
|
type: "text",
|
|
61
|
-
text:
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
if (searchResponse.results.length === 0) {
|
|
67
|
-
return {
|
|
68
|
-
content: [
|
|
69
|
-
{
|
|
70
|
-
type: "text",
|
|
71
|
-
text: "No documentation libraries available",
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
const resultsText = formatSearchResults(searchResponse);
|
|
77
|
-
return {
|
|
78
|
-
content: [
|
|
79
|
-
{
|
|
80
|
-
type: "text",
|
|
81
|
-
text: `Available Libraries (top matches):
|
|
84
|
+
text: `Available Libraries (top matches):
|
|
82
85
|
|
|
83
86
|
Each result includes:
|
|
84
87
|
- Library ID: Context7-compatible identifier (format: /org/project)
|
|
@@ -93,51 +96,152 @@ For best results, select libraries based on name match, trust score, snippet cov
|
|
|
93
96
|
----------
|
|
94
97
|
|
|
95
98
|
${resultsText}`,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
});
|
|
100
|
-
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, UNLESS the user explicitly provides a library ID in the format '/org/project' or '/org/project/version' in their query.", {
|
|
101
|
-
context7CompatibleLibraryID: z
|
|
102
|
-
.string()
|
|
103
|
-
.describe("Exact Context7-compatible library ID (e.g., '/mongodb/docs', '/vercel/next.js', '/supabase/supabase', '/vercel/next.js/v14.3.0-canary.87') retrieved from 'resolve-library-id' or directly from user query in the format '/org/project' or '/org/project/version'."),
|
|
104
|
-
topic: z
|
|
105
|
-
.string()
|
|
106
|
-
.optional()
|
|
107
|
-
.describe("Topic to focus documentation on (e.g., 'hooks', 'routing')."),
|
|
108
|
-
tokens: z
|
|
109
|
-
.preprocess((val) => (typeof val === "string" ? Number(val) : val), z.number())
|
|
110
|
-
.transform((val) => (val < DEFAULT_MINIMUM_TOKENS ? DEFAULT_MINIMUM_TOKENS : val))
|
|
111
|
-
.optional()
|
|
112
|
-
.describe(`Maximum number of tokens of documentation to retrieve (default: ${DEFAULT_MINIMUM_TOKENS}). Higher values provide more context but consume more tokens.`),
|
|
113
|
-
}, async ({ context7CompatibleLibraryID, tokens = DEFAULT_MINIMUM_TOKENS, topic = "" }) => {
|
|
114
|
-
const documentationText = await fetchLibraryDocumentation(context7CompatibleLibraryID, {
|
|
115
|
-
tokens,
|
|
116
|
-
topic,
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
};
|
|
117
102
|
});
|
|
118
|
-
|
|
103
|
+
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, UNLESS the user explicitly provides a library ID in the format '/org/project' or '/org/project/version' in their query.", {
|
|
104
|
+
context7CompatibleLibraryID: z
|
|
105
|
+
.string()
|
|
106
|
+
.describe("Exact Context7-compatible library ID (e.g., '/mongodb/docs', '/vercel/next.js', '/supabase/supabase', '/vercel/next.js/v14.3.0-canary.87') retrieved from 'resolve-library-id' or directly from user query in the format '/org/project' or '/org/project/version'."),
|
|
107
|
+
topic: z
|
|
108
|
+
.string()
|
|
109
|
+
.optional()
|
|
110
|
+
.describe("Topic to focus documentation on (e.g., 'hooks', 'routing')."),
|
|
111
|
+
tokens: z
|
|
112
|
+
.preprocess((val) => (typeof val === "string" ? Number(val) : val), z.number())
|
|
113
|
+
.transform((val) => (val < DEFAULT_MINIMUM_TOKENS ? DEFAULT_MINIMUM_TOKENS : val))
|
|
114
|
+
.optional()
|
|
115
|
+
.describe(`Maximum number of tokens of documentation to retrieve (default: ${DEFAULT_MINIMUM_TOKENS}). Higher values provide more context but consume more tokens.`),
|
|
116
|
+
}, async ({ context7CompatibleLibraryID, tokens = DEFAULT_MINIMUM_TOKENS, topic = "" }) => {
|
|
117
|
+
const fetchDocsResponse = await fetchLibraryDocumentation(context7CompatibleLibraryID, {
|
|
118
|
+
tokens,
|
|
119
|
+
topic,
|
|
120
|
+
});
|
|
121
|
+
if (!fetchDocsResponse) {
|
|
122
|
+
return {
|
|
123
|
+
content: [
|
|
124
|
+
{
|
|
125
|
+
type: "text",
|
|
126
|
+
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.",
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
};
|
|
130
|
+
}
|
|
119
131
|
return {
|
|
120
132
|
content: [
|
|
121
133
|
{
|
|
122
134
|
type: "text",
|
|
123
|
-
text:
|
|
135
|
+
text: fetchDocsResponse,
|
|
124
136
|
},
|
|
125
137
|
],
|
|
126
138
|
};
|
|
127
|
-
}
|
|
128
|
-
return
|
|
129
|
-
|
|
130
|
-
{
|
|
131
|
-
type: "text",
|
|
132
|
-
text: documentationText,
|
|
133
|
-
},
|
|
134
|
-
],
|
|
135
|
-
};
|
|
136
|
-
});
|
|
139
|
+
});
|
|
140
|
+
return server;
|
|
141
|
+
}
|
|
137
142
|
async function main() {
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
143
|
+
const transportType = TRANSPORT_TYPE;
|
|
144
|
+
if (transportType === "http" || transportType === "sse") {
|
|
145
|
+
// Get initial port from environment or use default
|
|
146
|
+
const initialPort = CLI_PORT ?? 3000;
|
|
147
|
+
// Keep track of which port we end up using
|
|
148
|
+
let actualPort = initialPort;
|
|
149
|
+
const httpServer = createServer(async (req, res) => {
|
|
150
|
+
const url = new URL(req.url || "", `http://${req.headers.host}`).pathname;
|
|
151
|
+
// Set CORS headers for all responses
|
|
152
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
153
|
+
res.setHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS,DELETE");
|
|
154
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type, MCP-Session-Id, mcp-session-id");
|
|
155
|
+
// Handle preflight OPTIONS requests
|
|
156
|
+
if (req.method === "OPTIONS") {
|
|
157
|
+
res.writeHead(200);
|
|
158
|
+
res.end();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
// Create new server instance for each request
|
|
163
|
+
const requestServer = createServerInstance();
|
|
164
|
+
if (url === "/mcp") {
|
|
165
|
+
const transport = new StreamableHTTPServerTransport({
|
|
166
|
+
sessionIdGenerator: undefined,
|
|
167
|
+
});
|
|
168
|
+
await requestServer.connect(transport);
|
|
169
|
+
await transport.handleRequest(req, res);
|
|
170
|
+
}
|
|
171
|
+
else if (url === "/sse" && req.method === "GET") {
|
|
172
|
+
// Create new SSE transport for GET request
|
|
173
|
+
const sseTransport = new SSEServerTransport("/messages", res);
|
|
174
|
+
// Store the transport by session ID
|
|
175
|
+
sseTransports[sseTransport.sessionId] = sseTransport;
|
|
176
|
+
// Clean up transport when connection closes
|
|
177
|
+
res.on("close", () => {
|
|
178
|
+
delete sseTransports[sseTransport.sessionId];
|
|
179
|
+
});
|
|
180
|
+
await requestServer.connect(sseTransport);
|
|
181
|
+
}
|
|
182
|
+
else if (url === "/messages" && req.method === "POST") {
|
|
183
|
+
// Get session ID from query parameters
|
|
184
|
+
const sessionId = new URL(req.url || "", `http://${req.headers.host}`).searchParams.get("sessionId") ??
|
|
185
|
+
"";
|
|
186
|
+
if (!sessionId) {
|
|
187
|
+
res.writeHead(400);
|
|
188
|
+
res.end("Missing sessionId parameter");
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
// Get existing transport for this session
|
|
192
|
+
const sseTransport = sseTransports[sessionId];
|
|
193
|
+
if (!sseTransport) {
|
|
194
|
+
res.writeHead(400);
|
|
195
|
+
res.end(`No transport found for sessionId: ${sessionId}`);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
// Handle the POST message with the existing transport
|
|
199
|
+
await sseTransport.handlePostMessage(req, res);
|
|
200
|
+
}
|
|
201
|
+
else if (url === "/ping") {
|
|
202
|
+
res.writeHead(200, { "Content-Type": "text/plain" });
|
|
203
|
+
res.end("pong");
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
res.writeHead(404);
|
|
207
|
+
res.end("Not found");
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
console.error("Error handling request:", error);
|
|
212
|
+
if (!res.headersSent) {
|
|
213
|
+
res.writeHead(500);
|
|
214
|
+
res.end("Internal Server Error");
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
// Function to attempt server listen with port fallback
|
|
219
|
+
const startServer = (port, maxAttempts = 10) => {
|
|
220
|
+
httpServer.once("error", (err) => {
|
|
221
|
+
if (err.code === "EADDRINUSE" && port < initialPort + maxAttempts) {
|
|
222
|
+
console.warn(`Port ${port} is in use, trying port ${port + 1}...`);
|
|
223
|
+
startServer(port + 1, maxAttempts);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
console.error(`Failed to start server: ${err.message}`);
|
|
227
|
+
process.exit(1);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
httpServer.listen(port, () => {
|
|
231
|
+
actualPort = port;
|
|
232
|
+
console.error(`Context7 Documentation MCP Server running on ${transportType.toUpperCase()} at http://localhost:${actualPort}/mcp and legacy SSE at /sse`);
|
|
233
|
+
});
|
|
234
|
+
};
|
|
235
|
+
// Start the server with initial port
|
|
236
|
+
startServer(initialPort);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
// Stdio transport - this is already stateless by nature
|
|
240
|
+
const server = createServerInstance();
|
|
241
|
+
const transport = new StdioServerTransport();
|
|
242
|
+
await server.connect(transport);
|
|
243
|
+
console.error("Context7 Documentation MCP Server running on stdio");
|
|
244
|
+
}
|
|
141
245
|
}
|
|
142
246
|
main().catch((error) => {
|
|
143
247
|
console.error("Fatal error in main():", error);
|
package/dist/lib/api.js
CHANGED
|
@@ -11,14 +11,25 @@ export async function searchLibraries(query) {
|
|
|
11
11
|
url.searchParams.set("query", query);
|
|
12
12
|
const response = await fetch(url);
|
|
13
13
|
if (!response.ok) {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const errorCode = response.status;
|
|
15
|
+
if (errorCode === 429) {
|
|
16
|
+
console.error(`Rate limited due to too many requests. Please try again later.`);
|
|
17
|
+
return {
|
|
18
|
+
results: [],
|
|
19
|
+
error: `Rate limited due to too many requests. Please try again later.`,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
console.error(`Failed to search libraries. Please try again later. Error code: ${errorCode}`);
|
|
23
|
+
return {
|
|
24
|
+
results: [],
|
|
25
|
+
error: `Failed to search libraries. Please try again later. Error code: ${errorCode}`,
|
|
26
|
+
};
|
|
16
27
|
}
|
|
17
28
|
return await response.json();
|
|
18
29
|
}
|
|
19
30
|
catch (error) {
|
|
20
31
|
console.error("Error searching libraries:", error);
|
|
21
|
-
return
|
|
32
|
+
return { results: [], error: `Error searching libraries: ${error}` };
|
|
22
33
|
}
|
|
23
34
|
}
|
|
24
35
|
/**
|
|
@@ -44,8 +55,15 @@ export async function fetchLibraryDocumentation(libraryId, options = {}) {
|
|
|
44
55
|
},
|
|
45
56
|
});
|
|
46
57
|
if (!response.ok) {
|
|
47
|
-
|
|
48
|
-
|
|
58
|
+
const errorCode = response.status;
|
|
59
|
+
if (errorCode === 429) {
|
|
60
|
+
const errorMessage = `Rate limited due to too many requests. Please try again later.`;
|
|
61
|
+
console.error(errorMessage);
|
|
62
|
+
return errorMessage;
|
|
63
|
+
}
|
|
64
|
+
const errorMessage = `Failed to fetch documentation. Please try again later. Error code: ${errorCode}`;
|
|
65
|
+
console.error(errorMessage);
|
|
66
|
+
return errorMessage;
|
|
49
67
|
}
|
|
50
68
|
const text = await response.text();
|
|
51
69
|
if (!text || text === "No content available" || text === "No context data available") {
|
|
@@ -54,7 +72,8 @@ export async function fetchLibraryDocumentation(libraryId, options = {}) {
|
|
|
54
72
|
return text;
|
|
55
73
|
}
|
|
56
74
|
catch (error) {
|
|
57
|
-
|
|
58
|
-
|
|
75
|
+
const errorMessage = `Error fetching library documentation. Please try again later. ${error}`;
|
|
76
|
+
console.error(errorMessage);
|
|
77
|
+
return errorMessage;
|
|
59
78
|
}
|
|
60
79
|
}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@upstash/context7-mcp","version":"v1.0.
|
|
1
|
+
{"name":"@upstash/context7-mcp","version":"v1.0.14","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","lint:check":"eslint \"**/*.{js,ts,tsx}\"","start":"node dist/index.js --transport http"},"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.12.0","commander":"^14.0.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"}}
|