feat: enforce minimum token limit of 5000 for library docs retrieval

This commit is contained in:
Abdusshh 2025-04-23 00:18:15 +03:00
parent 1afaa5982e
commit b199a1645e
2 changed files with 2 additions and 4 deletions

View File

@ -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

View File

@ -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.`