Skip to content

Context7 Platform -- Up-to-date docs for AI agents

feat: string-to-number conversion for tokens parameter

Abdusshhae1a7c44fa00
diff --git a/src/index.ts b/src/index.ts
index 5f82665e..19d88dc5 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -80,8 +80,10 @@ server.tool(
.optional()
.describe("Topic to focus documentation on (e.g., 'hooks', 'routing')."),
tokens: z
- .number()
- .min(DEFAULT_MINIMUM_TOKENS)
+ .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}`,
+ })
.optional()
.describe(
`Maximum number of tokens of documentation to retrieve (default: ${DEFAULT_MINIMUM_TOKENS}). Higher values provide more context but consume more tokens.`