mirror of
https://github.com/upstash/context7.git
synced 2025-11-24 14:08:35 +00:00
Merge pull request #668 from upstash/feat/tokens-param
This commit is contained in:
commit
29628d68e6
35
README.md
35
README.md
@ -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
|
- 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))
|
- 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>
|
<details>
|
||||||
<summary><b>Installing via Smithery</b></summary>
|
<summary><b>Installing via Smithery</b></summary>
|
||||||
|
|
||||||
@ -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"
|
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
|
#### Claude Code Local Server Connection
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@ -335,7 +334,8 @@ See [Gemini CLI Configuration](https://google-gemini.github.io/gemini-cli/docs/t
|
|||||||
"context7": {
|
"context7": {
|
||||||
"httpUrl": "https://mcp.context7.com/mcp",
|
"httpUrl": "https://mcp.context7.com/mcp",
|
||||||
"headers": {
|
"headers": {
|
||||||
"CONTEXT7_API_KEY": "YOUR_API_KEY"
|
"CONTEXT7_API_KEY": "YOUR_API_KEY",
|
||||||
|
"Accept": "application/json, text/event-stream"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -757,7 +757,7 @@ Add this to your Visual Studio MCP config file (see the [Visual Studio docs](htt
|
|||||||
"inputs": [],
|
"inputs": [],
|
||||||
"servers": {
|
"servers": {
|
||||||
"context7": {
|
"context7": {
|
||||||
"type": "sse",
|
"type": "http",
|
||||||
"url": "https://mcp.context7.com/mcp",
|
"url": "https://mcp.context7.com/mcp",
|
||||||
"headers": {
|
"headers": {
|
||||||
"CONTEXT7_API_KEY": "YOUR_API_KEY"
|
"CONTEXT7_API_KEY": "YOUR_API_KEY"
|
||||||
@ -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
|
#### Crush Local Server Connection
|
||||||
|
|
||||||
```json
|
```json
|
||||||
@ -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.
|
- `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`)
|
- `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")
|
- `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
|
## 🛟 Tips
|
||||||
|
|
||||||
|
|||||||
17
src/index.ts
17
src/index.ts
@ -12,12 +12,17 @@ import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
|
|||||||
import { Command } from "commander";
|
import { Command } from "commander";
|
||||||
import { IncomingMessage } from "http";
|
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
|
// Parse CLI arguments using commander
|
||||||
const program = new Command()
|
const program = new Command()
|
||||||
.option("--transport <stdio|http>", "transport type", "stdio")
|
.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")
|
.option("--api-key <key>", "API key for authentication")
|
||||||
.allowUnknownOption() // let MCP Inspector / other wrappers pass through extra flags
|
.allowUnknownOption() // let MCP Inspector / other wrappers pass through extra flags
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
@ -200,14 +205,14 @@ ${resultsText}`,
|
|||||||
.describe("Topic to focus documentation on (e.g., 'hooks', 'routing')."),
|
.describe("Topic to focus documentation on (e.g., 'hooks', 'routing')."),
|
||||||
tokens: z
|
tokens: z
|
||||||
.preprocess((val) => (typeof val === "string" ? Number(val) : val), z.number())
|
.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()
|
.optional()
|
||||||
.describe(
|
.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(
|
const fetchDocsResponse = await fetchLibraryDocumentation(
|
||||||
context7CompatibleLibraryID,
|
context7CompatibleLibraryID,
|
||||||
{
|
{
|
||||||
@ -248,7 +253,7 @@ async function main() {
|
|||||||
|
|
||||||
if (transportType === "http") {
|
if (transportType === "http") {
|
||||||
// Get initial port from environment or use default
|
// 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
|
// Keep track of which port we end up using
|
||||||
let actualPort = initialPort;
|
let actualPort = initialPort;
|
||||||
const httpServer = createServer(async (req, res) => {
|
const httpServer = createServer(async (req, res) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user