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();
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden for behavioral disclosure. 'Count tokens in text' implies a read-only operation that returns a number, but it doesn't specify whether this requires API authentication, has rate limits, what format the count is returned in, or potential errors (e.g., for empty text). For a tool with no annotation coverage, this leaves significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise at just three words, with zero wasted language. It's front-loaded with the core purpose and avoids unnecessary elaboration. For a simple tool, this brevity is appropriate and efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (2 parameters, no output schema, no annotations), the description is incomplete. It doesn't address what the tool returns, how errors are handled, or the role of the apiUrl parameter. While conciseness is good, the description lacks essential context for reliable agent use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate for undocumented parameters. It mentions 'text' implicitly but doesn't explain the 'apiUrl' parameter or provide any details about parameter formats, constraints, or examples. With 2 parameters (one required) and no schema descriptions, the description adds minimal value beyond what's inferred from the tool name.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Count tokens in text' clearly states the verb ('Count') and resource ('tokens in text'), making the purpose immediately understandable. It distinguishes from siblings like kobold_chat or kobold_generate by focusing on token counting rather than generation or conversation. However, it doesn't specify what 'tokens' refer to (e.g., AI model tokens vs. other types), which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention use cases like preprocessing text for model input, checking token limits, or comparing with siblings like kobold_detokenize. Without any context about when this tool is appropriate, the agent must infer usage from the name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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