@upstash/context7-mcp 1.0.16 → 1.0.18
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 +106 -54
- package/dist/index.js +46 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
1
3
|
# Context7 MCP - Up-to-date Code Docs For Any Prompt
|
|
2
4
|
|
|
3
|
-
[](https://context7.com) [](https://smithery.ai/server/@upstash/context7-mcp)
|
|
5
|
+
[](https://context7.com) [](https://smithery.ai/server/@upstash/context7-mcp) [](https://www.npmjs.com/package/@upstash/context7-mcp) [](./LICENSE)
|
|
4
6
|
|
|
5
7
|
[](https://cursor.com/en/install-mcp?name=context7&config=eyJ1cmwiOiJodHRwczovL21jcC5jb250ZXh0Ny5jb20vbWNwIn0%3D) [<img alt="Install in VS Code (npx)" src="https://img.shields.io/badge/Install%20in%20VS%20Code-0098FF?style=for-the-badge&logo=visualstudiocode&logoColor=white">](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)
|
|
6
8
|
|
|
@@ -11,7 +13,7 @@
|
|
|
11
13
|
LLMs rely on outdated or generic information about the libraries you use. You get:
|
|
12
14
|
|
|
13
15
|
- ❌ Code examples are outdated and based on year-old training data
|
|
14
|
-
- ❌ Hallucinated APIs don't even exist
|
|
16
|
+
- ❌ Hallucinated APIs that don't even exist
|
|
15
17
|
- ❌ Generic answers for old package versions
|
|
16
18
|
|
|
17
19
|
## ✅ With Context7
|
|
@@ -34,7 +36,7 @@ Context7 fetches up-to-date code examples and documentation right into your LLM'
|
|
|
34
36
|
- 2️⃣ Tell the LLM to `use context7`
|
|
35
37
|
- 3️⃣ Get working code answers
|
|
36
38
|
|
|
37
|
-
No tab-switching, no hallucinated APIs that don't exist, no outdated code
|
|
39
|
+
No tab-switching, no hallucinated APIs that don't exist, no outdated code generation.
|
|
38
40
|
|
|
39
41
|
## 📚 Adding Projects
|
|
40
42
|
|
|
@@ -48,6 +50,11 @@ Check out our [project addition guide](./docs/adding-projects.md) to learn how t
|
|
|
48
50
|
- Cursor, Claude Code, VSCode, Windsurf or another MCP Client
|
|
49
51
|
- Context7 API Key (Optional for higher rate limits) (Get yours by creating an account at [context7.com/dashboard](https://context7.com/dashboard))
|
|
50
52
|
|
|
53
|
+
> [!WARNING]
|
|
54
|
+
> **SSE Protocol Deprecation Notice**
|
|
55
|
+
>
|
|
56
|
+
> The Server-Sent Events (SSE) transport protocol is deprecated and its endpoint will be removed in upcoming releases. Please use HTTP or stdio transport methods instead.
|
|
57
|
+
|
|
51
58
|
<details>
|
|
52
59
|
<summary><b>Installing via Smithery</b></summary>
|
|
53
60
|
|
|
@@ -107,7 +114,7 @@ Pasting the following configuration into your Cursor `~/.cursor/mcp.json` file i
|
|
|
107
114
|
<details>
|
|
108
115
|
<summary><b>Install in Claude Code</b></summary>
|
|
109
116
|
|
|
110
|
-
Run this command. See [Claude Code MCP docs](https://docs.anthropic.com/en/docs/
|
|
117
|
+
Run this command. See [Claude Code MCP docs](https://docs.anthropic.com/en/docs/claude-code/mcp) for more info.
|
|
111
118
|
|
|
112
119
|
#### Claude Code Remote Server Connection
|
|
113
120
|
|
|
@@ -115,12 +122,6 @@ Run this command. See [Claude Code MCP docs](https://docs.anthropic.com/en/docs/
|
|
|
115
122
|
claude mcp add --transport http context7 https://mcp.context7.com/mcp --header "CONTEXT7_API_KEY: YOUR_API_KEY"
|
|
116
123
|
```
|
|
117
124
|
|
|
118
|
-
Or using SSE transport:
|
|
119
|
-
|
|
120
|
-
```sh
|
|
121
|
-
claude mcp add --transport sse context7 https://mcp.context7.com/sse --header "CONTEXT7_API_KEY: YOUR_API_KEY"
|
|
122
|
-
```
|
|
123
|
-
|
|
124
125
|
#### Claude Code Local Server Connection
|
|
125
126
|
|
|
126
127
|
```sh
|
|
@@ -216,6 +217,28 @@ You can easily install Context7 through the [Cline MCP Server Marketplace](https
|
|
|
216
217
|
3. Use the search bar within the **Marketplace** tab to find _Context7_.
|
|
217
218
|
4. Click the **Install** button.
|
|
218
219
|
|
|
220
|
+
Or you can directly edit MCP servers configuration:
|
|
221
|
+
|
|
222
|
+
1. Open **Cline**.
|
|
223
|
+
2. Click the hamburger menu icon (☰) to enter the **MCP Servers** section.
|
|
224
|
+
3. Choose **Remote Servers** tab.
|
|
225
|
+
4. Click the **Edit Configuration** button.
|
|
226
|
+
5. Add context7 to `mcpServers`:
|
|
227
|
+
|
|
228
|
+
```json
|
|
229
|
+
{
|
|
230
|
+
"mcpServers": {
|
|
231
|
+
"context7": {
|
|
232
|
+
"url": "https://mcp.context7.com/mcp",
|
|
233
|
+
"type": "streamableHttp",
|
|
234
|
+
"headers": {
|
|
235
|
+
"Authorization": "Bearer YOUR_API_KEY"
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
219
242
|
</details>
|
|
220
243
|
|
|
221
244
|
<details>
|
|
@@ -298,7 +321,10 @@ Add this to your Roo Code MCP configuration file. See [Roo Code MCP docs](https:
|
|
|
298
321
|
"mcpServers": {
|
|
299
322
|
"context7": {
|
|
300
323
|
"type": "streamable-http",
|
|
301
|
-
"url": "https://mcp.context7.com/mcp"
|
|
324
|
+
"url": "https://mcp.context7.com/mcp",
|
|
325
|
+
"headers": {
|
|
326
|
+
"CONTEXT7_API_KEY": "YOUR_API_KEY",
|
|
327
|
+
}
|
|
302
328
|
}
|
|
303
329
|
}
|
|
304
330
|
}
|
|
@@ -333,7 +359,8 @@ See [Gemini CLI Configuration](https://google-gemini.github.io/gemini-cli/docs/t
|
|
|
333
359
|
"context7": {
|
|
334
360
|
"httpUrl": "https://mcp.context7.com/mcp",
|
|
335
361
|
"headers": {
|
|
336
|
-
"CONTEXT7_API_KEY": "YOUR_API_KEY"
|
|
362
|
+
"CONTEXT7_API_KEY": "YOUR_API_KEY",
|
|
363
|
+
"Accept": "application/json, text/event-stream"
|
|
337
364
|
}
|
|
338
365
|
}
|
|
339
366
|
}
|
|
@@ -384,7 +411,7 @@ Open Claude Desktop developer settings and edit your `claude_desktop_config.json
|
|
|
384
411
|
<details>
|
|
385
412
|
<summary><b>Install in Opencode</b></summary>
|
|
386
413
|
|
|
387
|
-
Add this to your Opencode configuration file. See [Opencode MCP docs](https://opencode.ai/docs/mcp-servers)
|
|
414
|
+
Add this to your Opencode configuration file. See [Opencode MCP docs](https://opencode.ai/docs/mcp-servers) for more info.
|
|
388
415
|
|
|
389
416
|
#### Opencode Remote Server Connection
|
|
390
417
|
|
|
@@ -416,6 +443,7 @@ Add this to your Opencode configuration file. See [Opencode MCP docs](https://op
|
|
|
416
443
|
```
|
|
417
444
|
|
|
418
445
|
</details>
|
|
446
|
+
|
|
419
447
|
<details>
|
|
420
448
|
<summary><b>Install in OpenAI Codex</b></summary>
|
|
421
449
|
|
|
@@ -429,6 +457,40 @@ args = ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
|
|
|
429
457
|
command = "npx"
|
|
430
458
|
```
|
|
431
459
|
|
|
460
|
+
⚠️ Windows Notes
|
|
461
|
+
|
|
462
|
+
On Windows, some users may encounter request timed out errors with the default configuration.
|
|
463
|
+
In that case, explicitly configure the MCP server with the full path to Node.js and the installed package:
|
|
464
|
+
|
|
465
|
+
```toml
|
|
466
|
+
[mcp_servers.context7]
|
|
467
|
+
command = "C:\\Program Files\\nodejs\\node.exe"
|
|
468
|
+
args = [
|
|
469
|
+
"C:\\Users\\yourname\\AppData\\Roaming\\npm\\node_modules\\@upstash\\context7-mcp\\dist\\index.js",
|
|
470
|
+
"--transport",
|
|
471
|
+
"stdio",
|
|
472
|
+
"--api-key",
|
|
473
|
+
"YOUR_API_KEY"
|
|
474
|
+
]
|
|
475
|
+
```
|
|
476
|
+
Alternatively, you can use the following configuration:
|
|
477
|
+
|
|
478
|
+
```toml
|
|
479
|
+
[mcp_servers.context7]
|
|
480
|
+
command = "cmd"
|
|
481
|
+
args = [
|
|
482
|
+
"/c",
|
|
483
|
+
"npx",
|
|
484
|
+
"-y",
|
|
485
|
+
"@upstash/context7-mcp",
|
|
486
|
+
"--api-key",
|
|
487
|
+
"YOUR_API_KEY"
|
|
488
|
+
]
|
|
489
|
+
env = { SystemRoot="C:\\Windows" }
|
|
490
|
+
startup_timeout_ms = 20_000
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
This ensures Codex CLI works reliably on Windows.
|
|
432
494
|
</details>
|
|
433
495
|
|
|
434
496
|
<details>
|
|
@@ -436,7 +498,7 @@ command = "npx"
|
|
|
436
498
|
|
|
437
499
|
See [JetBrains AI Assistant Documentation](https://www.jetbrains.com/help/ai-assistant/configure-an-mcp-server.html) for more details.
|
|
438
500
|
|
|
439
|
-
1. In JetBrains IDEs go to `Settings` -> `Tools` -> `AI Assistant` -> `Model Context Protocol (MCP)`
|
|
501
|
+
1. In JetBrains IDEs, go to `Settings` -> `Tools` -> `AI Assistant` -> `Model Context Protocol (MCP)`
|
|
440
502
|
2. Click `+ Add`.
|
|
441
503
|
3. Click on `Command` in the top-left corner of the dialog and select the As JSON option from the list
|
|
442
504
|
4. Add this configuration and click `OK`
|
|
@@ -619,7 +681,7 @@ If you prefer to run the MCP server in a Docker container:
|
|
|
619
681
|
<details>
|
|
620
682
|
<summary><b>Install Using the Desktop Extension</b></summary>
|
|
621
683
|
|
|
622
|
-
Install the [context7.
|
|
684
|
+
Install the [context7.mcpb](mcpb/context7.mcpb) file under the mcpb folder and add it to your client. For more information, please check out [MCP bundles docs](https://github.com/anthropics/mcpb#mcp-bundles-mcpb).
|
|
623
685
|
|
|
624
686
|
</details>
|
|
625
687
|
|
|
@@ -755,7 +817,7 @@ Add this to your Visual Studio MCP config file (see the [Visual Studio docs](htt
|
|
|
755
817
|
"inputs": [],
|
|
756
818
|
"servers": {
|
|
757
819
|
"context7": {
|
|
758
|
-
"type": "
|
|
820
|
+
"type": "http",
|
|
759
821
|
"url": "https://mcp.context7.com/mcp",
|
|
760
822
|
"headers": {
|
|
761
823
|
"CONTEXT7_API_KEY": "YOUR_API_KEY"
|
|
@@ -807,23 +869,6 @@ Add this to your Crush configuration file. See [Crush MCP docs](https://github.c
|
|
|
807
869
|
}
|
|
808
870
|
```
|
|
809
871
|
|
|
810
|
-
#### Crush Remote Server Connection (SSE)
|
|
811
|
-
|
|
812
|
-
```json
|
|
813
|
-
{
|
|
814
|
-
"$schema": "https://charm.land/crush.json",
|
|
815
|
-
"mcp": {
|
|
816
|
-
"context7": {
|
|
817
|
-
"type": "sse",
|
|
818
|
-
"url": "https://mcp.context7.com/sse",
|
|
819
|
-
"headers": {
|
|
820
|
-
"CONTEXT7_API_KEY": "YOUR_API_KEY"
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
```
|
|
826
|
-
|
|
827
872
|
#### Crush Local Server Connection
|
|
828
873
|
|
|
829
874
|
```json
|
|
@@ -985,41 +1030,48 @@ See [Local and Remote MCPs for Perplexity](https://www.perplexity.ai/help-center
|
|
|
985
1030
|
Context7 MCP provides the following tools that LLMs can use:
|
|
986
1031
|
|
|
987
1032
|
- `resolve-library-id`: Resolves a general library name into a Context7-compatible library ID.
|
|
988
|
-
|
|
989
1033
|
- `libraryName` (required): The name of the library to search for
|
|
990
1034
|
|
|
991
1035
|
- `get-library-docs`: Fetches documentation for a library using a Context7-compatible library ID.
|
|
992
1036
|
- `context7CompatibleLibraryID` (required): Exact Context7-compatible library ID (e.g., `/mongodb/docs`, `/vercel/next.js`)
|
|
993
1037
|
- `topic` (optional): Focus the docs on a specific topic (e.g., "routing", "hooks")
|
|
994
|
-
- `tokens` (optional, default
|
|
1038
|
+
- `tokens` (optional, default 5000): Max number of tokens to return. Values less than 1000 are automatically increased to 1000.
|
|
995
1039
|
|
|
996
1040
|
## 🛟 Tips
|
|
997
1041
|
|
|
998
1042
|
### Add a Rule
|
|
999
1043
|
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
>
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1044
|
+
If you don’t want to add `use context7` to every prompt, you can define a simple rule in your MCP client's rule section:
|
|
1045
|
+
|
|
1046
|
+
- For Windsurf, in `.windsurfrules` file
|
|
1047
|
+
- For Cursor, from `Cursor Settings > Rules` section
|
|
1048
|
+
- For Claude Code, in `CLAUDE.md` file
|
|
1049
|
+
|
|
1050
|
+
Or the equivalent in your MCP client to auto-invoke Context7 on any code question.
|
|
1051
|
+
|
|
1052
|
+
#### Example Rule
|
|
1053
|
+
|
|
1054
|
+
```txt
|
|
1055
|
+
Always use context7 when I need code generation, setup or configuration steps, or
|
|
1056
|
+
library/API documentation. This means you should automatically use the Context7 MCP
|
|
1057
|
+
tools to resolve library id and get library docs without me having to explicitly ask.
|
|
1058
|
+
```
|
|
1059
|
+
|
|
1060
|
+
From then on, you’ll get Context7’s docs in any related conversation without typing anything extra. You can alter the rule to match your use cases.
|
|
1009
1061
|
|
|
1010
1062
|
### Use Library Id
|
|
1011
1063
|
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1064
|
+
If you already know exactly which library you want to use, add its Context7 ID to your prompt. That way, Context7 MCP server can skip the library-matching step and directly continue with retrieving docs.
|
|
1065
|
+
|
|
1066
|
+
```txt
|
|
1067
|
+
Implement basic authentication with Supabase. use library /supabase/supabase for API and docs.
|
|
1068
|
+
```
|
|
1069
|
+
|
|
1070
|
+
The slash syntax tells the MCP tool exactly which library to load docs for.
|
|
1019
1071
|
|
|
1020
1072
|
### HTTPS Proxy
|
|
1021
1073
|
|
|
1022
|
-
|
|
1074
|
+
If you are behind an HTTP proxy, Context7 uses the standard `https_proxy` / `HTTPS_PROXY` environment variables.
|
|
1023
1075
|
|
|
1024
1076
|
## 💻 Development
|
|
1025
1077
|
|
|
@@ -1049,7 +1101,7 @@ bun run dist/index.js
|
|
|
1049
1101
|
- `--port <number>` – Port to listen on when using `http` transport (default `3000`).
|
|
1050
1102
|
- `--api-key <key>` – API key for authentication. You can get your API key by creating an account at [context7.com/dashboard](https://context7.com/dashboard).
|
|
1051
1103
|
|
|
1052
|
-
Example with
|
|
1104
|
+
Example with HTTP transport and port 8080:
|
|
1053
1105
|
|
|
1054
1106
|
```bash
|
|
1055
1107
|
bun run dist/index.js --transport http --port 8080
|
|
@@ -1069,7 +1121,7 @@ bun run dist/index.js --transport stdio --api-key YOUR_API_KEY
|
|
|
1069
1121
|
"mcpServers": {
|
|
1070
1122
|
"context7": {
|
|
1071
1123
|
"command": "npx",
|
|
1072
|
-
"args": ["tsx", "/path/to/folder/context7
|
|
1124
|
+
"args": ["tsx", "/path/to/folder/context7/src/index.ts", "--api-key", "YOUR_API_KEY"]
|
|
1073
1125
|
}
|
|
1074
1126
|
}
|
|
1075
1127
|
}
|
package/dist/index.js
CHANGED
|
@@ -8,11 +8,16 @@ import { createServer } from "http";
|
|
|
8
8
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
9
9
|
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
|
|
10
10
|
import { Command } from "commander";
|
|
11
|
-
|
|
11
|
+
/** Minimum allowed tokens for documentation retrieval */
|
|
12
|
+
const MINIMUM_TOKENS = 1000;
|
|
13
|
+
/** Default tokens when none specified */
|
|
14
|
+
const DEFAULT_TOKENS = 5000;
|
|
15
|
+
/** Default HTTP server port */
|
|
16
|
+
const DEFAULT_PORT = 3000;
|
|
12
17
|
// Parse CLI arguments using commander
|
|
13
18
|
const program = new Command()
|
|
14
19
|
.option("--transport <stdio|http>", "transport type", "stdio")
|
|
15
|
-
.option("--port <number>", "port for HTTP transport",
|
|
20
|
+
.option("--port <number>", "port for HTTP transport", DEFAULT_PORT.toString())
|
|
16
21
|
.option("--api-key <key>", "API key for authentication")
|
|
17
22
|
.allowUnknownOption() // let MCP Inspector / other wrappers pass through extra flags
|
|
18
23
|
.parse(process.argv);
|
|
@@ -72,7 +77,7 @@ function getClientIp(req) {
|
|
|
72
77
|
function createServerInstance(clientIp, apiKey) {
|
|
73
78
|
const server = new McpServer({
|
|
74
79
|
name: "Context7",
|
|
75
|
-
version: "1.0.
|
|
80
|
+
version: "1.0.18",
|
|
76
81
|
}, {
|
|
77
82
|
instructions: "Use this server to retrieve up-to-date documentation and code examples for any library.",
|
|
78
83
|
});
|
|
@@ -130,7 +135,7 @@ Each result includes:
|
|
|
130
135
|
- Description: Short summary
|
|
131
136
|
- Code Snippets: Number of available code examples
|
|
132
137
|
- Trust Score: Authority indicator
|
|
133
|
-
- Versions: List of versions if available. Use one of those versions if
|
|
138
|
+
- Versions: List of versions if available. Use one of those versions if the user provides a version in their query. The format of the version is /org/project/version.
|
|
134
139
|
|
|
135
140
|
For best results, select libraries based on name match, trust score, snippet coverage, and relevance to your use case.
|
|
136
141
|
|
|
@@ -154,11 +159,11 @@ ${resultsText}`,
|
|
|
154
159
|
.describe("Topic to focus documentation on (e.g., 'hooks', 'routing')."),
|
|
155
160
|
tokens: z
|
|
156
161
|
.preprocess((val) => (typeof val === "string" ? Number(val) : val), z.number())
|
|
157
|
-
.transform((val) => (val <
|
|
162
|
+
.transform((val) => (val < MINIMUM_TOKENS ? MINIMUM_TOKENS : val))
|
|
158
163
|
.optional()
|
|
159
|
-
.describe(`Maximum number of tokens of documentation to retrieve (default: ${
|
|
164
|
+
.describe(`Maximum number of tokens of documentation to retrieve (default: ${DEFAULT_TOKENS}). Higher values provide more context but consume more tokens.`),
|
|
160
165
|
},
|
|
161
|
-
}, async ({ context7CompatibleLibraryID, tokens =
|
|
166
|
+
}, async ({ context7CompatibleLibraryID, tokens = DEFAULT_TOKENS, topic = "" }) => {
|
|
162
167
|
const fetchDocsResponse = await fetchLibraryDocumentation(context7CompatibleLibraryID, {
|
|
163
168
|
tokens,
|
|
164
169
|
topic,
|
|
@@ -188,11 +193,11 @@ async function main() {
|
|
|
188
193
|
const transportType = TRANSPORT_TYPE;
|
|
189
194
|
if (transportType === "http") {
|
|
190
195
|
// Get initial port from environment or use default
|
|
191
|
-
const initialPort = CLI_PORT ??
|
|
196
|
+
const initialPort = CLI_PORT ?? DEFAULT_PORT;
|
|
192
197
|
// Keep track of which port we end up using
|
|
193
198
|
let actualPort = initialPort;
|
|
194
199
|
const httpServer = createServer(async (req, res) => {
|
|
195
|
-
const
|
|
200
|
+
const pathname = new URL(req.url || "/", "http://localhost").pathname;
|
|
196
201
|
// Set CORS headers for all responses
|
|
197
202
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
198
203
|
res.setHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS,DELETE");
|
|
@@ -237,14 +242,18 @@ async function main() {
|
|
|
237
242
|
const clientIp = getClientIp(req);
|
|
238
243
|
// Create new server instance for each request
|
|
239
244
|
const requestServer = createServerInstance(clientIp, apiKey);
|
|
240
|
-
if (
|
|
245
|
+
if (pathname === "/mcp") {
|
|
241
246
|
const transport = new StreamableHTTPServerTransport({
|
|
242
247
|
sessionIdGenerator: undefined,
|
|
243
248
|
});
|
|
249
|
+
res.on("close", () => {
|
|
250
|
+
transport.close();
|
|
251
|
+
requestServer.close();
|
|
252
|
+
});
|
|
244
253
|
await requestServer.connect(transport);
|
|
245
254
|
await transport.handleRequest(req, res);
|
|
246
255
|
}
|
|
247
|
-
else if (
|
|
256
|
+
else if (pathname === "/sse" && req.method === "GET") {
|
|
248
257
|
// Create new SSE transport for GET request
|
|
249
258
|
const sseTransport = new SSEServerTransport("/messages", res);
|
|
250
259
|
// Store the transport by session ID
|
|
@@ -252,42 +261,54 @@ async function main() {
|
|
|
252
261
|
// Clean up transport when connection closes
|
|
253
262
|
res.on("close", () => {
|
|
254
263
|
delete sseTransports[sseTransport.sessionId];
|
|
264
|
+
sseTransport.close();
|
|
265
|
+
requestServer.close();
|
|
255
266
|
});
|
|
256
267
|
await requestServer.connect(sseTransport);
|
|
268
|
+
// Send initial message to establish communication
|
|
269
|
+
res.write("data: " +
|
|
270
|
+
JSON.stringify({
|
|
271
|
+
type: "connection_established",
|
|
272
|
+
sessionId: sseTransport.sessionId,
|
|
273
|
+
timestamp: new Date().toISOString(),
|
|
274
|
+
}) +
|
|
275
|
+
"\n\n");
|
|
257
276
|
}
|
|
258
|
-
else if (
|
|
277
|
+
else if (pathname === "/messages" && req.method === "POST") {
|
|
259
278
|
// Get session ID from query parameters
|
|
260
|
-
const sessionId = new URL(req.url || "",
|
|
261
|
-
"";
|
|
279
|
+
const sessionId = new URL(req.url || "/", "http://localhost").searchParams.get("sessionId") ?? "";
|
|
262
280
|
if (!sessionId) {
|
|
263
|
-
res.writeHead(400);
|
|
264
|
-
res.end("Missing sessionId parameter");
|
|
281
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
282
|
+
res.end(JSON.stringify({ error: "Missing sessionId parameter", status: 400 }));
|
|
265
283
|
return;
|
|
266
284
|
}
|
|
267
285
|
// Get existing transport for this session
|
|
268
286
|
const sseTransport = sseTransports[sessionId];
|
|
269
287
|
if (!sseTransport) {
|
|
270
|
-
res.writeHead(400);
|
|
271
|
-
res.end(
|
|
288
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
289
|
+
res.end(JSON.stringify({
|
|
290
|
+
error: `No transport found for sessionId: ${sessionId}`,
|
|
291
|
+
status: 400,
|
|
292
|
+
}));
|
|
272
293
|
return;
|
|
273
294
|
}
|
|
274
295
|
// Handle the POST message with the existing transport
|
|
275
296
|
await sseTransport.handlePostMessage(req, res);
|
|
276
297
|
}
|
|
277
|
-
else if (
|
|
278
|
-
res.writeHead(200, { "Content-Type": "
|
|
279
|
-
res.end("pong");
|
|
298
|
+
else if (pathname === "/ping") {
|
|
299
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
300
|
+
res.end(JSON.stringify({ status: "ok", message: "pong" }));
|
|
280
301
|
}
|
|
281
302
|
else {
|
|
282
|
-
res.writeHead(404);
|
|
283
|
-
res.end("Not found");
|
|
303
|
+
res.writeHead(404, { "Content-Type": "application/json" });
|
|
304
|
+
res.end(JSON.stringify({ error: "Not found", status: 404 }));
|
|
284
305
|
}
|
|
285
306
|
}
|
|
286
307
|
catch (error) {
|
|
287
308
|
console.error("Error handling request:", error);
|
|
288
309
|
if (!res.headersSent) {
|
|
289
|
-
res.writeHead(500);
|
|
290
|
-
res.end("Internal Server Error");
|
|
310
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
311
|
+
res.end(JSON.stringify({ error: "Internal Server Error", status: 500 }));
|
|
291
312
|
}
|
|
292
313
|
}
|
|
293
314
|
});
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@upstash/context7-mcp","version":"1.0.
|
|
1
|
+
{"name":"@upstash/context7-mcp","version":"1.0.18","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","pack-mcpb":"bun install && bun run build && rm -rf node_modules && bun install --production && mv mcpb/.mcpbignore .mcpbignore && mv mcpb/manifest.json manifest.json && mv public/icon.png icon.png && mcpb validate manifest.json && mcpb pack . mcpb/context7.mcpb && mv manifest.json mcpb/manifest.json && mv .mcpbignore mcpb/.mcpbignore && mv icon.png public/icon.png && bun install"},"repository":{"type":"git","url":"git+https://github.com/upstash/context7.git"},"keywords":["modelcontextprotocol","mcp","context7","vibe-coding","developer tools","documentation","context"],"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.17.5","commander":"^14.0.0","undici":"^6.6.3","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.34.0","eslint-config-prettier":"^10.1.1","eslint-plugin-prettier":"^5.2.5","prettier":"^3.6.2","typescript":"^5.8.2","typescript-eslint":"^8.28.0"}}
|