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).

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.6/5.0
Behavior4/5

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

Annotations already declare readOnly/idempotent/non-destructive, so the safety profile is covered. The description adds genuinely useful behavioral context beyond the structured fields: the result is an estimate using OpenAI's cl100k tokenizer and will differ slightly for other model families, which affects how much an agent should trust the number.

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?

One sentence with the core action front-loaded and the accuracy caveat efficiently packed into a parenthetical. No filler or redundancy.

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 no explanation, and the tokenizer caveat closes the main accuracy question. It falls short only on usage context (when this is preferable to estimate_cost) and says nothing about the length limit that the schema imposes.

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?

Schema description coverage is 100% and the single parameter is fully documented in the schema, including examples and length bounds. The description adds no syntax or formatting detail beyond that baseline.

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 (count) and resource (tokens in a text), which is immediately actionable. It does not differentiate itself from the related sibling estimate_cost, so an agent must infer the boundary between the two.

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?

No when-to-use or when-not-to-use guidance is provided. The nearby sibling estimate_cost overlaps in intent, and the description offers nothing to route an agent between them.

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