Skip to main content
Glama

Count tokens

count_tokens
Read-onlyIdempotent

Count the tokens in a text (an estimate with OpenAI's cl100k tokenizer; other model families differ slightly).

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "text": "<text>"
    },
    "name": "count_tokens"
  }
}

Input Schema

NameRequiredDescriptionDefault
textYesThe text to count, such as a system prompt or a typical user message

Output Schema

NameRequiredDescriptionDefault
tokensYes
tokenizerYes
charactersYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changed
    • addedInput schema / properties / text / description
      Added value: +"The text to count, such as a system prompt or a typical user message"
  2. Changed1 schema field changed
    • changedOutput schema / (root)
      Previous value: -nullNew value: +{
      +  "$schema": "https://json-schema.org/draft/2020-12/schema",
      +  "additionalProperties": false,
      +  "properties": {
      +    "characters": {
      +      "type": "number"
      +    },
      +    "tokenizer": {
      +      "type": "string"
      +    },
      +    "tokens": {
      +      "type": "number"
      +    }
      +  },
      +  "required": [
      +    "tokens",
      +    "characters",
      +    "tokenizer"
      +  ],
      +  "type": "object"
      +}
  3. First observed

TDQS

A3.8/5.0
Behavior4/5

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

Annotations already cover safety (readOnly, idempotent, closedWorld, non-destructive), so the description's real contribution is disclosing that the result is an estimate tied to OpenAI's cl100k tokenizer and that other model families will differ. That caveat directly bears on how much an agent should trust the number, which is not encoded anywhere in the structured fields.

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?

A single front-loaded sentence with the core action first and the tokenizer caveat in parentheses. Nothing is redundant and nothing is missing that belongs at this length.

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

Completeness4/5

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

An output schema exists, so return values need not be explained, and the main behavioral caveat (estimate, tokenizer-specific) is present. The only remaining gap is the absence of any pointer to estimate_cost for turning token counts into cost, which would complete the sibling story.

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

Parameters3/5

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

With 100% schema coverage and a single required parameter, the schema already documents the input fully, including the 1–100,000 length bound and example usage. The description adds no further detail about the parameter, so baseline 3 applies.

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?

States a specific verb and resource ("Count the tokens in a text") and adds the tokenizer used. It is clear from the siblings that this is the token-measurement utility, but it does not explicitly distinguish itself from estimate_cost, which likely also needs token counts.

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

Usage Guidelines3/5

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

Usage is only implied by the verb; there is no statement of when to use this rather than estimate_cost or price_ai_feature. No prerequisites or exclusions are given, leaving routing to inference.

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

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources