From b199a1645ee0a69a57234fe1a9b70279c15f79b6 Mon Sep 17 00:00:00 2001 From: Abdusshh Date: Wed, 23 Apr 2025 00:18:15 +0300 Subject: [PATCH] feat: enforce minimum token limit of 5000 for library docs retrieval --- README.md | 2 +- src/index.ts | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 837a06f..4890a08 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ Add this to your Claude Desktop `claude_desktop_config.json` file. See [Claude D - `get-library-docs`: Fetches documentation for a library using a Context7-compatible library ID. - `context7CompatibleLibraryID` (required) - `topic` (optional): Focus the docs on a specific topic (e.g., "routing", "hooks") - - `tokens` (optional, default 5000): Max number of tokens to return + - `tokens` (optional, default 5000): Max number of tokens to return. Values less than 5000 are automatically increased to 5000. ## Development diff --git a/src/index.ts b/src/index.ts index 19d88dc..0111f5e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -81,9 +81,7 @@ server.tool( .describe("Topic to focus documentation on (e.g., 'hooks', 'routing')."), tokens: z .preprocess((val) => (typeof val === "string" ? Number(val) : val), z.number()) - .refine((val) => typeof val === "number" && val >= DEFAULT_MINIMUM_TOKENS, { - message: `Must be a number >= ${DEFAULT_MINIMUM_TOKENS}`, - }) + .transform((val) => (val < DEFAULT_MINIMUM_TOKENS ? DEFAULT_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.`