Skip to main content
Glama

Count tokens

count_tokens
Read-onlyIdempotent

Count tokens with the o200k or cl100k encoder and price the count against the published model table. Claude and Gemini rows are estimates, not those vendors' tokenizers.

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 prompt or document to count.
encodingNoo200k
modelIdsNoPrice rows to return. Unknown ids are rejected.
cachedRatioNo
outputTokensNo
requestsPerDayNo

Output Schema

NameRequiredDescriptionDefault
charsYes
countYes
wordsYes
pricesYes
encodingYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changed
    • addedInput schema / additionalProperties
      Added value: +false
  2. First observed

TDQS

B3/5.0
Behavior3/5

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

Annotations already declare readOnly, idempotent and closed-world, so the safety profile is covered. The description contributes real context beyond them: counts are priced against a published model table and non-OpenAI rows are approximations. It stops short of saying how the price is computed or how cached/output/request parameters affect it.

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

Conciseness4/5

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

Two sentences, zero filler, with the encoder/pricing scope front-loaded and the estimate caveat immediately after. Efficient, though the caveat could be merged more tightly with the encoder clause.

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

Completeness3/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 needn't be explained, and the estimate caveat covers the biggest correctness risk. However, for a six-parameter tool with a third of its params undescribed, the description leaves the pricing inputs unexplained.

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 coverage is only 33% across six parameters. The description implies the encoder and modelIds semantics, but cachedRatio, outputTokens and requestsPerDay are undocumented in both schema and description, so an agent cannot tell what they change about the result.

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 tokens') plus the exact encoders supported and the added pricing behavior, so the agent knows this is more than a plain tokenizer. It does not differentiate itself from the sibling count_text, which likely overlaps in purpose.

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 only guidance is a caveat that Claude and Gemini rows are estimates rather than native tokenizations. There is no statement of when to pick this tool over count_text or when pricing is useful, leaving the routing decision 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.