Skip to main content
Glama

Token Diet

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. Language models cannot count their own tokens, so call this instead of estimating. Example: {"text": ""}. Not for shortening text.

Input Schema

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

Schema Changelog

Changes observed during successful MCP inspections.

  1. Added

TDQS

A4.7/5.0
Behavior5/5

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

Goes well beyond the readOnly/idempotent annotations: it discloses the tokenizer (o200k, GPT-4o family and later), the expected accuracy for Claude and Gemini (~15% variance), the full set of returned metrics (tokens, words, characters, window utilization), and the 200K character ceiling. This is exactly the accuracy-caveat context an agent needs to relay results honestly.

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?

Front-loaded with the trigger condition, then the return shape, then the justification for not estimating, then the exclusion. Dense but every sentence carries decision-relevant information; nothing is padding.

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 single-parameter read-only counting tool with no output schema, the description covers trigger, tokenizer, accuracy caveats, returned fields, and input limits. An agent could invoke and correctly report results with no further information.

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 coverage is 100% and the single `text` parameter is already documented with its 200,000-character limit, so the schema does the heavy lifting. The description's JSON example merely restates the schema shape rather than adding syntax or formatting rules, so the baseline 3 is appropriate.

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?

States a specific verb and resource (count tokens in a text) and enumerates the exact input classes it covers: text, prompt, log, document, code paste. It also carves out what it is not ("Not for shortening text") and names the specific tokenizer used, so the tool is unambiguous even without siblings.

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?

Gives an explicit trigger ("Use when the user asks how many tokens..."), a proactive condition (checking fit against 128K/200K/1M context windows before sending), and a clear exclusion ("Not for shortening text"). It also says to call this *instead of estimating*, which preempts the most likely competing behavior.

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