kobold_token_count
Measure the token count of text for accurate processing and compatibility with KoboldAI MCP Server, ensuring efficient integration with text generation workflows.
Instructions
Count tokens in text
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apiUrl | No | http://localhost:5001 | |
| text | Yes |
Implementation Reference
- src/index.ts:346-358 (handler)Shared handler logic for POST-based tools like kobold_token_count: validates arguments against schema, forwards POST request to the configured KoboldAI endpoint, and returns the JSON response.if (postEndpoints[name]) { const { endpoint, schema } = postEndpoints[name]; const parsed = schema.safeParse(args); if (!parsed.success) { throw new Error(`Invalid arguments: ${parsed.error}`); } const result = await makeRequest(`${apiUrl}${endpoint}`, 'POST', requestData); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], isError: false, }; }
- src/index.ts:46-48 (schema)Zod schema defining input for kobold_token_count: optional apiUrl and required text string.const TokenCountSchema = BaseConfigSchema.extend({ text: z.string(), });
- src/index.ts:198-202 (registration)Tool registration in ListTools response, including name, description, and input schema.{ name: "kobold_token_count", description: "Count tokens in text", inputSchema: zodToJsonSchema(TokenCountSchema), },
- src/index.ts:333-333 (helper)Configuration mapping the kobold_token_count tool to its KoboldAI proxy endpoint.kobold_token_count: { endpoint: '/api/extra/tokencount', schema: TokenCountSchema },