From 02d87cf33f9c85aec6286113eff9e80b0f031648 Mon Sep 17 00:00:00 2001 From: enesgules Date: Fri, 5 Sep 2025 14:09:55 +0300 Subject: [PATCH] refactor: update token limits and improve constant organization for documentation retrieval --- README.md | 4 ++-- src/index.ts | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e7f4462..2904226 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.
Installing via Smithery @@ -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. ## 🛟 Tips diff --git a/src/index.ts b/src/index.ts index 33a36d4..5a81cc3 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 commander const program = new Command() .option("--transport ", "transport type", "stdio") - .option("--port ", "port for HTTP transport", "3000") + .option("--port ", "port for HTTP transport", DEFAULT_PORT.toString()) .option("--api-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 using let actualPort = initialPort; const httpServer = createServer(async (req, res) => {