Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 9 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ Check out our [project addition guide](./docs/adding-projects.md) to learn how t
- Cursor, Claude Code, VSCode, Windsurf or another MCP Client
- Context7 API Key (Optional for higher rate limits) (Get yours by creating an account at [context7.com/dashboard](https://context7.com/dashboard))

> [!WARNING]
> **SSE Protocol Deprecation Notice**
>
> 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.

<details>
<summary><b>Installing via Smithery</b></summary>

Expand Down Expand Up @@ -117,12 +122,6 @@ Run this command. See [Claude Code MCP docs](https://docs.anthropic.com/en/docs/
claude mcp add --transport http context7 https://mcp.context7.com/mcp --header "CONTEXT7_API_KEY: YOUR_API_KEY"
```

Or using SSE transport:

```sh
claude mcp add --transport sse context7 https://mcp.context7.com/sse --header "CONTEXT7_API_KEY: YOUR_API_KEY"
```

#### Claude Code Local Server Connection

```sh
Expand Down Expand Up @@ -335,7 +334,8 @@ See [Gemini CLI Configuration](https://google-gemini.github.io/gemini-cli/docs/t
"context7": {
"httpUrl": "https://mcp.context7.com/mcp",
"headers": {
"CONTEXT7_API_KEY": "YOUR_API_KEY"
"CONTEXT7_API_KEY": "YOUR_API_KEY",
"Accept": "application/json, text/event-stream"
}
}
}
Expand Down Expand Up @@ -757,7 +757,7 @@ Add this to your Visual Studio MCP config file (see the [Visual Studio docs](htt
"inputs": [],
"servers": {
"context7": {
"type": "sse",
"type": "http",
"url": "https://mcp.context7.com/mcp",
"headers": {
"CONTEXT7_API_KEY": "YOUR_API_KEY"
Expand Down Expand Up @@ -809,23 +809,6 @@ Add this to your Crush configuration file. See [Crush MCP docs](https://github.c
}
```

#### Crush Remote Server Connection (SSE)

```json
{
"$schema": "https://charm.land/crush.json",
"mcp": {
"context7": {
"type": "sse",
"url": "https://mcp.context7.com/sse",
"headers": {
"CONTEXT7_API_KEY": "YOUR_API_KEY"
}
}
}
}
```

#### Crush Local Server Connection

```json
Expand Down Expand Up @@ -992,7 +975,7 @@ Context7 MCP provides the following tools that LLMs can use:
- `get-library-docs`: Fetches documentation for a library using a Context7-compatible library ID.
- `context7CompatibleLibraryID` (required): Exact Context7-compatible library ID (e.g., `/mongodb/docs`, `/vercel/next.js`)
- `topic` (optional): Focus the docs on a specific topic (e.g., "routing", "hooks")
- `tokens` (optional, default 10000): Max number of tokens to return. Values less than the default value of 10000 are automatically increased to 10000.
- `tokens` (optional, default 5000): Max number of tokens to return. Values less than 1000 are automatically increased to 1000.

## 🛟 Tips

Expand Down
17 changes: 11 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
import { Command } from "commander";
import { IncomingMessage } from "http";

const DEFAULT_MINIMUM_TOKENS = 10000;
/** Minimum allowed tokens for documentation retrieval */
const MINIMUM_TOKENS = 1000;
/** Default tokens when none specified */
const DEFAULT_TOKENS = 5000;
/** Default HTTP server port */
const DEFAULT_PORT = 3000;

// Parse CLI arguments using commander
const program = new Command()
.option("--transport <stdio|http>", "transport type", "stdio")
.option("--port <number>", "port for HTTP transport", "3000")
.option("--port <number>", "port for HTTP transport", DEFAULT_PORT.toString())
.option("--api-key <key>", "API key for authentication")
.allowUnknownOption() // let MCP Inspector / other wrappers pass through extra flags
.parse(process.argv);
Expand Down Expand Up @@ -200,14 +205,14 @@ ${resultsText}`,
.describe("Topic to focus documentation on (e.g., 'hooks', 'routing')."),
tokens: z
.preprocess((val) => (typeof val === "string" ? Number(val) : val), z.number())
.transform((val) => (val < DEFAULT_MINIMUM_TOKENS ? DEFAULT_MINIMUM_TOKENS : val))
.transform((val) => (val < MINIMUM_TOKENS ? MINIMUM_TOKENS : val))
.optional()
.describe(
`Maximum number of tokens of documentation to retrieve (default: ${DEFAULT_MINIMUM_TOKENS}). Higher values provide more context but consume more tokens.`
`Maximum number of tokens of documentation to retrieve (default: ${DEFAULT_TOKENS}). Higher values provide more context but consume more tokens.`
),
},
},
async ({ context7CompatibleLibraryID, tokens = DEFAULT_MINIMUM_TOKENS, topic = "" }) => {
async ({ context7CompatibleLibraryID, tokens = DEFAULT_TOKENS, topic = "" }) => {
const fetchDocsResponse = await fetchLibraryDocumentation(
context7CompatibleLibraryID,
{
Expand Down Expand Up @@ -248,7 +253,7 @@ async function main() {

if (transportType === "http") {
// Get initial port from environment or use default
const initialPort = CLI_PORT ?? 3000;
const initialPort = CLI_PORT ?? DEFAULT_PORT;
// Keep track of which port we end up using
let actualPort = initialPort;
const httpServer = createServer(async (req, res) => {
Expand Down