@upstash/context7-mcp 1.0.11 → 1.0.13

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 CHANGED
@@ -2,8 +2,7 @@
2
2
 
3
3
  [![Website](https://img.shields.io/badge/Website-context7.com-blue)](https://context7.com) [![smithery badge](https://smithery.ai/badge/@upstash/context7-mcp)](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
- [![中文文档](https://img.shields.io/badge/docs-中文版-yellow)](./docs/README.zh-CN.md) [![한국어 문서](https://img.shields.io/badge/docs-한국어-green)](./docs/README.ko.md) [![Documentación en Español](https://img.shields.io/badge/docs-Español-orange)](./docs/README.es.md) [![Documentation en Français](https://img.shields.io/badge/docs-Français-blue)](./docs/README.fr.md) [![Documentação em Português (Brasil)](https://img.shields.io/badge/docs-Português%20(Brasil)-purple)](./docs/README.pt-BR.md) [![Documentazione in italiano](https://img.shields.io/badge/docs-Italian-red)](./docs/README.it.md) [![Dokumentasi Bahasa Indonesia](https://img.shields.io/badge/docs-Bahasa%20Indonesia-pink)](./docs/README.id-ID.md) [![Dokumentation auf Deutsch](https://img.shields.io/badge/docs-Deutsch-darkgreen)](./docs/README.de.md) [![Документация на русском языке](https://img.shields.io/badge/docs-Русский-darkblue)](./docs/README.ru.md) [![Türkçe Doküman](https://img.shields.io/badge/docs-Türkçe-blue)](./docs/README.tr.md) [![Arabic Documentation](https://img.shields.io/badge/docs-Arabic-white)](./docs/README.ar.md)
6
-
5
+ [![繁體中文](https://img.shields.io/badge/docs-繁體中文-yellow)](./docs/README.zh-TW.md) [![簡體中文](https://img.shields.io/badge/docs-簡體中文-yellow)](./docs/README.zh-CN.md) [![한국어 문서](https://img.shields.io/badge/docs-한국어-green)](./docs/README.ko.md) [![Documentación en Español](https://img.shields.io/badge/docs-Español-orange)](./docs/README.es.md) [![Documentation en Français](https://img.shields.io/badge/docs-Français-blue)](./docs/README.fr.md) [![Documentação em Português (Brasil)](<https://img.shields.io/badge/docs-Português%20(Brasil)-purple>)](./docs/README.pt-BR.md) [![Documentazione in italiano](https://img.shields.io/badge/docs-Italian-red)](./docs/README.it.md) [![Dokumentasi Bahasa Indonesia](https://img.shields.io/badge/docs-Bahasa%20Indonesia-pink)](./docs/README.id-ID.md) [![Dokumentation auf Deutsch](https://img.shields.io/badge/docs-Deutsch-darkgreen)](./docs/README.de.md) [![Документация на русском языке](https://img.shields.io/badge/docs-Русский-darkblue)](./docs/README.ru.md) [![Türkçe Doküman](https://img.shields.io/badge/docs-Türkçe-blue)](./docs/README.tr.md) [![Arabic Documentation](https://img.shields.io/badge/docs-Arabic-white)](./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
- ## 🛠️ Getting Started
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
- ### Installing via Smithery
48
+ <details>
49
+ <summary><b>Installing via Smithery</b></summary>
46
50
 
47
- To install Context7 MCP Server for Claude Desktop automatically via [Smithery](https://smithery.ai/server/@upstash/context7-mcp):
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 claude
54
+ npx -y @smithery/cli@latest install @upstash/context7-mcp --client <CLIENT_NAME> --key <YOUR_SMITHERY_KEY>
51
55
  ```
52
56
 
53
- ### Install in Cursor
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
+ [![Install MCP Server](https://cursor.com/deeplink/mcp-install-dark.svg)](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
+ [![Install MCP Server](https://cursor.com/deeplink/mcp-install-dark.svg)](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
+ [![Install MCP Server](https://cursor.com/deeplink/mcp-install-dark.svg)](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
+ [![Install MCP Server](https://cursor.com/deeplink/mcp-install-dark.svg)](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
- ### Install in Windsurf
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
- ### Install in VS Code
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
- "Context7": {
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,10 @@ Add this to your VS Code MCP config file. See [VS Code MCP docs](https://code.vi
133
201
  }
134
202
  ```
135
203
 
136
- ### Install in Zed
204
+ </details>
205
+
206
+ <details>
207
+ <summary><b>Install in Zed</b></summary>
137
208
 
138
209
  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
210
 
@@ -151,15 +222,29 @@ It can be installed via [Zed Extensions](https://zed.dev/extensions?query=Contex
151
222
  }
152
223
  ```
153
224
 
154
- ### Install in Claude Code
225
+ </details>
226
+
227
+ <details>
228
+ <summary><b>Install in Claude Code</b></summary>
155
229
 
156
230
  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
231
 
232
+ #### Claude Code Remote Server Connection
233
+
234
+ ```sh
235
+ claude mcp add --transport sse context7 https://mcp.context7.com/sse
236
+ ```
237
+
238
+ #### Claude Code Local Server Connection
239
+
158
240
  ```sh
159
241
  claude mcp add context7 -- npx -y @upstash/context7-mcp
160
242
  ```
161
243
 
162
- ### Install in Claude Desktop
244
+ </details>
245
+
246
+ <details>
247
+ <summary><b>Install in Claude Desktop</b></summary>
163
248
 
164
249
  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
250
 
@@ -174,7 +259,10 @@ Add this to your Claude Desktop `claude_desktop_config.json` file. See [Claude D
174
259
  }
175
260
  ```
176
261
 
177
- ### Install in BoltAI
262
+ </details>
263
+
264
+ <details>
265
+ <summary><b>Install in BoltAI</b></summary>
178
266
 
179
267
  Open the "Settings" page of the app, navigate to "Plugins," and enter the following JSON:
180
268
 
@@ -191,76 +279,79 @@ Open the "Settings" page of the app, navigate to "Plugins," and enter the follow
191
279
 
192
280
  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
281
 
194
- ### Using Docker
282
+ </details>
283
+
284
+ <details>
285
+ <summary><b>Using Docker</b></summary>
195
286
 
196
287
  If you prefer to run the MCP server in a Docker container:
197
288
 
198
- 1. **Build the Docker Image:**
289
+ 1. **Build the Docker Image:**
199
290
 
200
- First, create a `Dockerfile` in the project root (or anywhere you prefer):
291
+ First, create a `Dockerfile` in the project root (or anywhere you prefer):
201
292
 
202
- <details>
203
- <summary>Click to see Dockerfile content</summary>
293
+ <details>
294
+ <summary>Click to see Dockerfile content</summary>
204
295
 
205
- ```Dockerfile
206
- FROM node:18-alpine
296
+ ```Dockerfile
297
+ FROM node:18-alpine
207
298
 
208
- WORKDIR /app
299
+ WORKDIR /app
209
300
 
210
- # Install the latest version globally
211
- RUN npm install -g @upstash/context7-mcp
301
+ # Install the latest version globally
302
+ RUN npm install -g @upstash/context7-mcp
212
303
 
213
- # Expose default port if needed (optional, depends on MCP client interaction)
214
- # EXPOSE 3000
304
+ # Expose default port if needed (optional, depends on MCP client interaction)
305
+ # EXPOSE 3000
215
306
 
216
- # Default command to run the server
217
- CMD ["context7-mcp"]
218
- ```
307
+ # Default command to run the server
308
+ CMD ["context7-mcp"]
309
+ ```
219
310
 
220
- </details>
311
+ </details>
221
312
 
222
- 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`:
313
+ 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
314
 
224
- ```bash
225
- docker build -t context7-mcp .
226
- ```
315
+ ```bash
316
+ docker build -t context7-mcp .
317
+ ```
227
318
 
228
319
  2. **Configure Your MCP Client:**
229
320
 
230
- Update your MCP client's configuration to use the Docker command.
321
+ Update your MCP client's configuration to use the Docker command.
231
322
 
232
- *Example for a cline_mcp_settings.json:*
323
+ _Example for a cline_mcp_settings.json:_
233
324
 
234
- ```json
235
- {
236
- "mcpServers": {
237
- "Сontext7": {
238
- "autoApprove": [],
239
- "disabled": false,
240
- "timeout": 60,
241
- "command": "docker",
242
- "args": ["run", "-i", "--rm", "context7-mcp"],
243
- "transportType": "stdio"
244
- }
245
- }
246
- }
247
- ```
325
+ ```json
326
+ {
327
+ "mcpServers": {
328
+ "Сontext7": {
329
+ "autoApprove": [],
330
+ "disabled": false,
331
+ "timeout": 60,
332
+ "command": "docker",
333
+ "args": ["run", "-i", "--rm", "context7-mcp"],
334
+ "transportType": "stdio"
335
+ }
336
+ }
337
+ }
338
+ ```
339
+
340
+ _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._
341
+
342
+ </details>
343
+
344
+ <details>
345
+ <summary><b>Install in Windows</b></summary>
248
346
 
249
- *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.*
347
+ 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
348
 
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
349
  ```json
254
350
  {
255
351
  "mcpServers": {
256
352
  "github.com/upstash/context7-mcp": {
257
353
  "command": "cmd",
258
- "args": [
259
- "/c",
260
- "npx",
261
- "-y",
262
- "@upstash/context7-mcp"
263
- ],
354
+ "args": ["/c", "npx", "-y", "@upstash/context7-mcp@latest"],
264
355
  "disabled": false,
265
356
  "autoApprove": []
266
357
  }
@@ -268,11 +359,74 @@ The configuration on Windows is slightly different compared to Linux or macOS (*
268
359
  }
269
360
  ```
270
361
 
271
- ### Environment Variables
362
+ </details>
363
+
364
+ <details>
365
+ <summary><b>Install in Augment Code</b></summary>
366
+
367
+ To configure Context7 MCP in Augment Code, follow these steps:
368
+
369
+ 1. Press Cmd/Ctrl Shift P or go to the hamburger menu in the Augment panel
370
+ 2. Select Edit Settings
371
+ 3. Under Advanced, click Edit in settings.json
372
+ 4. Add the server configuration to the `mcpServers` array in the `augment.advanced` object
373
+
374
+ ```json
375
+ "augment.advanced": {
376
+ "mcpServers": [
377
+ {
378
+ "name": "context7",
379
+ "command": "npx",
380
+ "args": ["-y", "@upstash/context7-mcp"]
381
+ }
382
+ ]
383
+ }
384
+ ```
385
+
386
+ 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.
387
+
388
+ </details>
389
+
390
+ <details>
391
+ <summary><b>Install in Roo Code</b></summary>
392
+
393
+ 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.
394
+
395
+ #### Roo Code Remote Server Connection
396
+
397
+ ```json
398
+ {
399
+ "mcpServers": {
400
+ "context7": {
401
+ "type": "streamable-http",
402
+ "url": "https://mcp.context7.com/mcp"
403
+ }
404
+ }
405
+ }
406
+ ```
407
+
408
+ #### Roo Code Local Server Connection
272
409
 
273
- - `DEFAULT_MINIMUM_TOKENS`: Set the minimum token count for documentation retrieval (default: 10000).
410
+ ```json
411
+ {
412
+ "mcpServers": {
413
+ "context7": {
414
+ "command": "npx",
415
+ "args": ["-y", "@upstash/context7-mcp"]
416
+ }
417
+ }
418
+ }
419
+ ```
420
+
421
+ </details>
422
+
423
+ ## 🔧 Environment Variables
424
+
425
+ The Context7 MCP server supports the following environment variables:
274
426
 
275
- Examples:
427
+ - `DEFAULT_MINIMUM_TOKENS`: Set the minimum token count for documentation retrieval (default: 10000)
428
+
429
+ Example configuration with environment variables:
276
430
 
277
431
  ```json
278
432
  {
@@ -281,23 +435,27 @@ Examples:
281
435
  "command": "npx",
282
436
  "args": ["-y", "@upstash/context7-mcp"],
283
437
  "env": {
284
- "DEFAULT_MINIMUM_TOKENS": "10000"
438
+ "DEFAULT_MINIMUM_TOKENS": "6000"
285
439
  }
286
440
  }
287
441
  }
288
442
  }
289
443
  ```
290
444
 
291
- ### Available Tools
445
+ ## 🔨 Available Tools
446
+
447
+ Context7 MCP provides the following tools that LLMs can use:
292
448
 
293
449
  - `resolve-library-id`: Resolves a general library name into a Context7-compatible library ID.
294
- - `libraryName` (required)
450
+
451
+ - `libraryName` (required): The name of the library to search for
452
+
295
453
  - `get-library-docs`: Fetches documentation for a library using a Context7-compatible library ID.
296
- - `context7CompatibleLibraryID` (required)
454
+ - `context7CompatibleLibraryID` (required): Exact Context7-compatible library ID (e.g., `/mongodb/docs`, `/vercel/next.js`)
297
455
  - `topic` (optional): Focus the docs on a specific topic (e.g., "routing", "hooks")
298
456
  - `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.
299
457
 
300
- ## Development
458
+ ## 💻 Development
301
459
 
302
460
  Clone the project and install dependencies:
303
461
 
@@ -311,7 +469,8 @@ Build:
311
469
  bun run build
312
470
  ```
313
471
 
314
- ### Local Configuration Example
472
+ <details>
473
+ <summary><b>Local Configuration Example</b></summary>
315
474
 
316
475
  ```json
317
476
  {
@@ -324,17 +483,23 @@ bun run build
324
483
  }
325
484
  ```
326
485
 
327
- ### Testing with MCP Inspector
486
+ </details>
487
+
488
+ <details>
489
+ <summary><b>Testing with MCP Inspector</b></summary>
328
490
 
329
491
  ```bash
330
492
  npx -y @modelcontextprotocol/inspector npx @upstash/context7-mcp
331
493
  ```
332
494
 
333
- ## Troubleshooting
495
+ </details>
334
496
 
335
- ### ERR_MODULE_NOT_FOUND
497
+ ## 🚨 Troubleshooting
336
498
 
337
- If you see this error, try using `bunx` instead of `npx`.
499
+ <details>
500
+ <summary><b>Module Not Found Errors</b></summary>
501
+
502
+ If you encounter `ERR_MODULE_NOT_FOUND`, try using `bunx` instead of `npx`:
338
503
 
339
504
  ```json
340
505
  {
@@ -347,82 +512,83 @@ If you see this error, try using `bunx` instead of `npx`.
347
512
  }
348
513
  ```
349
514
 
350
- This often resolves module resolution issues, especially in environments where `npx` does not properly install or resolve packages.
515
+ This often resolves module resolution issues in environments where `npx` doesn't properly install or resolve packages.
516
+
517
+ </details>
351
518
 
352
- ### ESM Resolution Issues
519
+ <details>
520
+ <summary><b>ESM Resolution Issues</b></summary>
353
521
 
354
- If you encounter an error like: `Error: Cannot find module 'uriTemplate.js'` try running with the `--experimental-vm-modules` flag:
522
+ For errors like `Error: Cannot find module 'uriTemplate.js'`, try the `--experimental-vm-modules` flag:
355
523
 
356
524
  ```json
357
525
  {
358
526
  "mcpServers": {
359
527
  "context7": {
360
528
  "command": "npx",
361
- "args": [
362
- "-y",
363
- "--node-options=--experimental-vm-modules",
364
- "@upstash/context7-mcp"
365
- ]
529
+ "args": ["-y", "--node-options=--experimental-vm-modules", "@upstash/context7-mcp@1.0.6"]
366
530
  }
367
531
  }
368
532
  }
369
533
  ```
370
534
 
371
- ### TLS/Certificate Issues
535
+ </details>
372
536
 
373
- Use the `--experimental-fetch` flag with `npx` to bypass TLS-related issues:
537
+ <details>
538
+ <summary><b>TLS/Certificate Issues</b></summary>
539
+
540
+ Use the `--experimental-fetch` flag to bypass TLS-related problems:
374
541
 
375
542
  ```json
376
543
  {
377
544
  "mcpServers": {
378
545
  "context7": {
379
546
  "command": "npx",
380
- "args": [
381
- "-y",
382
- "--node-options=--experimental-fetch",
383
- "@upstash/context7-mcp"
384
- ]
547
+ "args": ["-y", "--node-options=--experimental-fetch", "@upstash/context7-mcp"]
385
548
  }
386
549
  }
387
550
  }
388
551
  ```
389
552
 
390
- ### MCP Client Errors
391
-
392
- 1. Try adding `@latest` to the package name.
553
+ </details>
393
554
 
394
- 2. Try using `bunx` as an alternative.
555
+ <details>
556
+ <summary><b>General MCP Client Errors</b></summary>
395
557
 
396
- 3. Try using `deno` as an alternative.
558
+ 1. Try adding `@latest` to the package name
559
+ 2. Use `bunx` as an alternative to `npx`
560
+ 3. Consider using `deno` as another alternative
561
+ 4. Ensure you're using Node.js v18 or higher for native fetch support
397
562
 
398
- 4. Make sure you are using Node v18 or higher to have native fetch support with `npx`.
563
+ </details>
399
564
 
400
- ## Disclaimer
565
+ ## ⚠️ Disclaimer
401
566
 
402
567
  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
568
 
404
- ## Connect with Us
569
+ ## 🤝 Connect with Us
405
570
 
406
571
  Stay updated and join our community:
572
+
407
573
  - 📢 Follow us on [X](https://x.com/contextai) for the latest news and updates
408
574
  - 🌐 Visit our [Website](https://context7.com)
409
- - 💬 Join our [Discord Community](https://upstash.com/discord) (if applicable)
575
+ - 💬 Join our [Discord Community](https://upstash.com/discord)
410
576
 
411
- ## Context7 In Media
577
+ ## 📺 Context7 In Media
412
578
 
413
579
  - [Better Stack: "Free Tool Makes Cursor 10x Smarter"](https://youtu.be/52FC3qObp9E)
414
580
  - [Cole Medin: "This is Hands Down the BEST MCP Server for AI Coding Assistants"](https://www.youtube.com/watch?v=G7gK8H6u7Rs)
415
- - [Income stream surfers: "Context7 + SequentialThinking MCPs: Is This AGI?"](https://www.youtube.com/watch?v=-ggvzyLpK6o)
581
+ - [Income Stream Surfers: "Context7 + SequentialThinking MCPs: Is This AGI?"](https://www.youtube.com/watch?v=-ggvzyLpK6o)
416
582
  - [Julian Goldie SEO: "Context7: New MCP AI Agent Update"](https://www.youtube.com/watch?v=CTZm6fBYisc)
417
583
  - [JeredBlu: "Context 7 MCP: Get Documentation Instantly + VS Code Setup"](https://www.youtube.com/watch?v=-ls0D-rtET4)
418
- - [Income stream surfers: "Context7: The New MCP Server That Will CHANGE AI Coding"](https://www.youtube.com/watch?v=PS-2Azb-C3M)
584
+ - [Income Stream Surfers: "Context7: The New MCP Server That Will CHANGE AI Coding"](https://www.youtube.com/watch?v=PS-2Azb-C3M)
419
585
  - [AICodeKing: "Context7 + Cline & RooCode: This MCP Server Makes CLINE 100X MORE EFFECTIVE!"](https://www.youtube.com/watch?v=qZfENAPMnyo)
420
586
  - [Sean Kochel: "5 MCP Servers For Vibe Coding Glory (Just Plug-In & Go)"](https://www.youtube.com/watch?v=LqTQi8qexJM)
421
587
 
422
- ## Star History
588
+ ## Star History
423
589
 
424
590
  [![Star History Chart](https://api.star-history.com/svg?repos=upstash/context7&type=Date)](https://www.star-history.com/#upstash/context7&Date)
425
591
 
426
- ## License
592
+ ## 📄 License
427
593
 
428
594
  MIT
package/dist/index.js CHANGED
@@ -5,6 +5,10 @@ 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
+ import { createServer } from "http";
9
+ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
10
+ import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
11
+ import { parse } from "url";
8
12
  // Load environment variables from .env file if present
9
13
  dotenv.config();
10
14
  // Get DEFAULT_MINIMUM_TOKENS from environment variable or use default
@@ -18,18 +22,21 @@ if (process.env.DEFAULT_MINIMUM_TOKENS) {
18
22
  console.warn(`Warning: Invalid DEFAULT_MINIMUM_TOKENS value provided in environment variable. Using default value of 10000`);
19
23
  }
20
24
  }
21
- // Create server instance
22
- const server = new McpServer({
23
- name: "Context7",
24
- description: "Retrieves up-to-date documentation and code examples for any library.",
25
- version: "v1.0.11",
26
- capabilities: {
27
- resources: {},
28
- tools: {},
29
- },
30
- });
31
- // Register Context7 tools
32
- server.tool("resolve-library-id", `Resolves a package/product name to a Context7-compatible library ID and returns a list of matching libraries.
25
+ // Store SSE transports by session ID
26
+ const sseTransports = {};
27
+ // Function to create a new server instance with all tools registered
28
+ function createServerInstance() {
29
+ const server = new McpServer({
30
+ name: "Context7",
31
+ description: "Retrieves up-to-date documentation and code examples for any library.",
32
+ version: "v1.0.13",
33
+ capabilities: {
34
+ resources: {},
35
+ tools: {},
36
+ },
37
+ });
38
+ // Register Context7 tools
39
+ server.tool("resolve-library-id", `Resolves a package/product name to a Context7-compatible library ID and returns a list of matching libraries.
33
40
 
34
41
  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
42
 
@@ -48,37 +55,29 @@ Response Format:
48
55
  - If no good matches exist, clearly state this and suggest query refinements
49
56
 
50
57
  For ambiguous queries, request clarification before proceeding with a best-guess match.`, {
51
- libraryName: z
52
- .string()
53
- .describe("Library name to search for and retrieve a Context7-compatible library ID."),
54
- }, async ({ libraryName }) => {
55
- const searchResponse = await searchLibraries(libraryName);
56
- if (!searchResponse || !searchResponse.results) {
58
+ libraryName: z
59
+ .string()
60
+ .describe("Library name to search for and retrieve a Context7-compatible library ID."),
61
+ }, async ({ libraryName }) => {
62
+ const searchResponse = await searchLibraries(libraryName);
63
+ if (!searchResponse.results || searchResponse.results.length === 0) {
64
+ return {
65
+ content: [
66
+ {
67
+ type: "text",
68
+ text: searchResponse.error
69
+ ? searchResponse.error
70
+ : "Failed to retrieve library documentation data from Context7",
71
+ },
72
+ ],
73
+ };
74
+ }
75
+ const resultsText = formatSearchResults(searchResponse);
57
76
  return {
58
77
  content: [
59
78
  {
60
79
  type: "text",
61
- text: "Failed to retrieve library documentation data from Context7",
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):
80
+ text: `Available Libraries (top matches):
82
81
 
83
82
  Each result includes:
84
83
  - Library ID: Context7-compatible identifier (format: /org/project)
@@ -93,55 +92,152 @@ For best results, select libraries based on name match, trust score, snippet cov
93
92
  ----------
94
93
 
95
94
  ${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
- userQuery: z
114
- .string()
115
- .describe("Initial user query that triggered this tool call. Provide the user query as it is. Do not modify it or change it in any way. Do not add any additional information to the query."),
116
- }, async ({ context7CompatibleLibraryID, tokens = DEFAULT_MINIMUM_TOKENS, topic = "", userQuery, }) => {
117
- const documentationText = await fetchLibraryDocumentation(context7CompatibleLibraryID, {
118
- tokens,
119
- topic,
120
- userQuery,
95
+ },
96
+ ],
97
+ };
121
98
  });
122
- if (!documentationText) {
99
+ 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.", {
100
+ context7CompatibleLibraryID: z
101
+ .string()
102
+ .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'."),
103
+ topic: z
104
+ .string()
105
+ .optional()
106
+ .describe("Topic to focus documentation on (e.g., 'hooks', 'routing')."),
107
+ tokens: z
108
+ .preprocess((val) => (typeof val === "string" ? Number(val) : val), z.number())
109
+ .transform((val) => (val < DEFAULT_MINIMUM_TOKENS ? DEFAULT_MINIMUM_TOKENS : val))
110
+ .optional()
111
+ .describe(`Maximum number of tokens of documentation to retrieve (default: ${DEFAULT_MINIMUM_TOKENS}). Higher values provide more context but consume more tokens.`),
112
+ }, async ({ context7CompatibleLibraryID, tokens = DEFAULT_MINIMUM_TOKENS, topic = "" }) => {
113
+ const fetchDocsResponse = await fetchLibraryDocumentation(context7CompatibleLibraryID, {
114
+ tokens,
115
+ topic,
116
+ });
117
+ if (!fetchDocsResponse) {
118
+ return {
119
+ content: [
120
+ {
121
+ type: "text",
122
+ 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.",
123
+ },
124
+ ],
125
+ };
126
+ }
123
127
  return {
124
128
  content: [
125
129
  {
126
130
  type: "text",
127
- 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.",
131
+ text: fetchDocsResponse,
128
132
  },
129
133
  ],
130
134
  };
131
- }
132
- return {
133
- content: [
134
- {
135
- type: "text",
136
- text: documentationText,
137
- },
138
- ],
139
- };
140
- });
135
+ });
136
+ return server;
137
+ }
141
138
  async function main() {
142
- const transport = new StdioServerTransport();
143
- await server.connect(transport);
144
- console.error("Context7 Documentation MCP Server running on stdio");
139
+ const transportType = process.env.MCP_TRANSPORT || "stdio";
140
+ if (transportType === "http" || transportType === "sse") {
141
+ // Get initial port from environment or use default
142
+ const initialPort = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
143
+ // Keep track of which port we end up using
144
+ let actualPort = initialPort;
145
+ const httpServer = createServer(async (req, res) => {
146
+ const url = parse(req.url || "").pathname;
147
+ // Set CORS headers for all responses
148
+ res.setHeader("Access-Control-Allow-Origin", "*");
149
+ res.setHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS,DELETE");
150
+ res.setHeader("Access-Control-Allow-Headers", "Content-Type, MCP-Session-Id, mcp-session-id");
151
+ // Handle preflight OPTIONS requests
152
+ if (req.method === "OPTIONS") {
153
+ res.writeHead(200);
154
+ res.end();
155
+ return;
156
+ }
157
+ try {
158
+ // Create new server instance for each request
159
+ const requestServer = createServerInstance();
160
+ if (url === "/mcp") {
161
+ const transport = new StreamableHTTPServerTransport({
162
+ sessionIdGenerator: undefined,
163
+ });
164
+ await requestServer.connect(transport);
165
+ await transport.handleRequest(req, res);
166
+ }
167
+ else if (url === "/sse" && req.method === "GET") {
168
+ // Create new SSE transport for GET request
169
+ const sseTransport = new SSEServerTransport("/messages", res);
170
+ // Store the transport by session ID
171
+ sseTransports[sseTransport.sessionId] = sseTransport;
172
+ // Clean up transport when connection closes
173
+ res.on("close", () => {
174
+ delete sseTransports[sseTransport.sessionId];
175
+ });
176
+ await requestServer.connect(sseTransport);
177
+ }
178
+ else if (url === "/messages" && req.method === "POST") {
179
+ // Get session ID from query parameters
180
+ const parsedUrl = parse(req.url || "", true);
181
+ const sessionId = parsedUrl.query.sessionId;
182
+ if (!sessionId) {
183
+ res.writeHead(400);
184
+ res.end("Missing sessionId parameter");
185
+ return;
186
+ }
187
+ // Get existing transport for this session
188
+ const sseTransport = sseTransports[sessionId];
189
+ if (!sseTransport) {
190
+ res.writeHead(400);
191
+ res.end(`No transport found for sessionId: ${sessionId}`);
192
+ return;
193
+ }
194
+ // Handle the POST message with the existing transport
195
+ await sseTransport.handlePostMessage(req, res);
196
+ }
197
+ else if (url === "/ping") {
198
+ res.writeHead(200, { "Content-Type": "text/plain" });
199
+ res.end("pong");
200
+ }
201
+ else {
202
+ res.writeHead(404);
203
+ res.end("Not found");
204
+ }
205
+ }
206
+ catch (error) {
207
+ console.error("Error handling request:", error);
208
+ if (!res.headersSent) {
209
+ res.writeHead(500);
210
+ res.end("Internal Server Error");
211
+ }
212
+ }
213
+ });
214
+ // Function to attempt server listen with port fallback
215
+ const startServer = (port, maxAttempts = 10) => {
216
+ httpServer.once("error", (err) => {
217
+ if (err.code === "EADDRINUSE" && port < initialPort + maxAttempts) {
218
+ console.warn(`Port ${port} is in use, trying port ${port + 1}...`);
219
+ startServer(port + 1, maxAttempts);
220
+ }
221
+ else {
222
+ console.error(`Failed to start server: ${err.message}`);
223
+ process.exit(1);
224
+ }
225
+ });
226
+ httpServer.listen(port, () => {
227
+ actualPort = port;
228
+ console.error(`Context7 Documentation MCP Server running on ${transportType.toUpperCase()} at http://localhost:${actualPort}/mcp and legacy SSE at /sse`);
229
+ });
230
+ };
231
+ // Start the server with initial port
232
+ startServer(initialPort);
233
+ }
234
+ else {
235
+ // Stdio transport - this is already stateless by nature
236
+ const server = createServerInstance();
237
+ const transport = new StdioServerTransport();
238
+ await server.connect(transport);
239
+ console.error("Context7 Documentation MCP Server running on stdio");
240
+ }
145
241
  }
146
242
  main().catch((error) => {
147
243
  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
- console.error(`Failed to search libraries: ${response.status}`);
15
- return null;
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 null;
32
+ return { results: [], error: `Error searching libraries: ${error}` };
22
33
  }
23
34
  }
24
35
  /**
@@ -27,7 +38,7 @@ export async function searchLibraries(query) {
27
38
  * @param options Options for the request
28
39
  * @returns The documentation text or null if the request fails
29
40
  */
30
- export async function fetchLibraryDocumentation(libraryId, options = { userQuery: "" }) {
41
+ export async function fetchLibraryDocumentation(libraryId, options = {}) {
31
42
  try {
32
43
  if (libraryId.startsWith("/")) {
33
44
  libraryId = libraryId.slice(1);
@@ -41,12 +52,18 @@ export async function fetchLibraryDocumentation(libraryId, options = { userQuery
41
52
  const response = await fetch(url, {
42
53
  headers: {
43
54
  "X-Context7-Source": "mcp-server",
44
- "X-Context7-User-Query": options.userQuery?.trim().toLowerCase() || "",
45
55
  },
46
56
  });
47
57
  if (!response.ok) {
48
- console.error(`Failed to fetch documentation: ${response.status}`);
49
- return null;
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;
50
67
  }
51
68
  const text = await response.text();
52
69
  if (!text || text === "No content available" || text === "No context data available") {
@@ -55,7 +72,8 @@ export async function fetchLibraryDocumentation(libraryId, options = { userQuery
55
72
  return text;
56
73
  }
57
74
  catch (error) {
58
- console.error("Error fetching library documentation:", error);
59
- return null;
75
+ const errorMessage = `Error fetching library documentation. Please try again later. ${error}`;
76
+ console.error(errorMessage);
77
+ return errorMessage;
60
78
  }
61
79
  }
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@upstash/context7-mcp","version":"v1.0.11","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"}}
1
+ {"name":"@upstash/context7-mcp","version":"v1.0.13","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":"MCP_TRANSPORT=http node dist/index.js"},"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","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"}}