Skip to main content
Glama

kobold_token_count

Count tokens in text to manage AI model input limits and optimize text processing for KoboldAI integration.

Instructions

Count tokens in text

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
apiUrlNohttp://localhost:5001
textYes

Implementation Reference

  • Shared handler logic for all POST-endpoint tools like kobold_token_count: validates arguments using the tool's schema, proxies the request to the KoboldAI API 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, };
  • Zod input schema for the kobold_token_count tool: optional apiUrl and required text string for token counting.
    const TokenCountSchema = BaseConfigSchema.extend({ text: z.string(), });
  • src/index.ts:198-202 (registration)
    Registration of kobold_token_count in the ListTools response, providing name, description, and input schema.
    { name: "kobold_token_count", description: "Count tokens in text", inputSchema: zodToJsonSchema(TokenCountSchema), },
  • src/index.ts:333-333 (registration)
    Mapping of kobold_token_count to its KoboldAI API endpoint and schema in the tool dispatch handler.
    kobold_token_count: { endpoint: '/api/extra/tokencount', schema: TokenCountSchema },
  • Helper function used by all tool handlers to make HTTP requests to the KoboldAI backend API.
    async function makeRequest(url: string, method = 'GET', body: Record<string, unknown> | null = null) { const options: RequestInit = { method, headers: body ? { 'Content-Type': 'application/json' } : undefined, }; if (body && method !== 'GET') { options.body = JSON.stringify(body); } const response = await fetch(url, options); if (!response.ok) { throw new Error(`KoboldAI API error: ${response.statusText}`); } return response.json(); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/PhialsBasement/KoboldCPP-MCP-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server