Context7 Platform -- Up-to-date docs for AI agents
refactor: update token limits and improve constant organization for documentation retrieval
enesgules02d87cf33f9c
diff --git a/README.md b/README.mdindex e7f44628..2904226d 100644--- a/README.md+++ b/README.md@@ -53,7 +53,7 @@ Check out our [project addition guide](./docs/adding-projects.md) to learn how t> [!WARNING]> **SSE Protocol Deprecation Notice**>-> The Server-Sent Events (SSE) transport protocol is deprecated and it's endpoint will be removed in upcoming releases. Please use HTTP or stdio transport methods instead.+> 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>@@ -975,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.## 🛟 Tipsdiff --git a/src/index.ts b/src/index.tsindex 33a36d4b..5a81cc30 100644--- a/src/index.ts+++ b/src/index.ts@@ -12,12 +12,17 @@ import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";import { Command } from "commander";import { IncomingMessage } from "http";-const DEFAULT_MINIMUM_TOKENS = 1000;+/** 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 commanderconst 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);@@ -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,{@@ -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 usinglet actualPort = initialPort;const httpServer = createServer(async (req, res) => {