feat: string-to-number conversion for tokens parameter

This commit is contained in:
Abdusshh 2025-04-19 16:14:24 +03:00
parent c1a4a1a21c
commit ae1a7c44fa

View File

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