Skip to main content
Glama

Count the exact tokens in a text

tokendiet_count_tokens
Read-onlyIdempotent

Use when the user asks how many tokens a text, prompt, log, document or code paste is, whether it fits a context window (128K, 200K, 1M), or how big something is before they send it to an AI. Returns the exact o200k token count (GPT-4o family and later; Claude and Gemini usually within about 15%), plus words, characters and how much of each window it uses. Counts are exact for that tokenizer. Example: {"text": ""}. Not for shortening text.

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": "tokendiet_count_tokens"
  }
}

Input Schema

NameRequiredDescriptionDefault
textYesThe text to count (up to 200,000 characters).

Schema Changelog

Changes observed during successful MCP inspections.

  1. Added

TDQS

A4.8/5.0
Behavior5/5

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

Annotations already declare readOnly, idempotent, non-destructive and closed-world, so the safety profile is covered. Beyond that the description discloses the actual tokenizer (o200k, GPT-4o family and later), an accuracy caveat (Claude and Gemini usually within about 15%), and the return payload (exact token count plus words, characters and per-window utilization). That is substantial behavior context an agent could not get from 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.

Conciseness4/5

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

The critical trigger ('Use when the user asks how many tokens...') is front-loaded and the exclusion closes the block. It is a dense run-on of a single sentence stream, and the embedded JSON example interrupts the flow, but every clause carries information, so waste is minimal.

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

Completeness5/5

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

For a one-parameter read-only counting tool with no output schema, the description covers triggers, tokenizer identity, accuracy limits, returned metrics, the input size limit and an invocation example. An agent has everything needed to call it correctly and to interpret the result honestly.

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

Parameters4/5

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

There is a single parameter with 100% schema description coverage, so the schema already carries the semantics and the baseline is 4. The description reinforces it with a literal call example, {"text": "<the text to measure>"}, and repeats the 200,000-character cap already in the schema, adding a little formatting clarity but no new parameter meaning.

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

Purpose5/5

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

The description states a specific verb and resource ('Count the exact tokens in a text') and enumerates the objects it applies to (prompt, log, document, code paste). It also disambiguates from an adjacent capability with 'Not for shortening text.' No sibling tools exist, so differentiation is moot, but the scope is unambiguous.

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

Usage Guidelines5/5

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

It gives concrete triggering conditions: the user asks how many tokens something is, whether it fits a 128K/200K/1M window, or how large a payload is before sending to an AI. It also supplies a negative case ('Not for shortening text'), so both when and when-not are explicit with nothing left 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