Skip to main content
Glama

Estimar tokens de LLM

token-estimate
Read-onlyIdempotent

Estima heurísticamente cuántos tokens de LLM usa un texto, con un rango de ±25 %. El conteo real depende del tokenizador de cada modelo. Cuándo: un flujo de agente necesita un resultado exacto y repetible para un paso auxiliar (tokens, costos, reintentos, fragmentos, ranking, limpieza de JSON). No para: estimar el costo de llamadas a un LLM a partir de tokens (llm-cost-estimate). Efectos secundarios: ninguno (solo lectura, sin red, sin estado guardado). Determinista: la misma entrada da la misma salida. Límites: entrada JSON de hasta 64 KB, 1 s por llamada, resultado de hasta 1 MB.

EN: Heuristically estimates how many LLM tokens a text uses (Latin text ~4 chars/token, CJK ~1 char/token, code and punctuation denser) with a ±25% range. Real counts depend on each model's tokenizer. When: an agent loop needs an exact, repeatable result for a bookkeeping step (tokens, costs, retries, chunking, ranking, JSON clean-up). [EN completo / full EN: inputSchema.description]

Input Schema

NameRequiredDescriptionDefault
textYesText (string; required).
context_windowNoOptional context window to compare against (integer; optional; min 1; max 100000000).

Output Schema

NameRequiredDescriptionDefault
lowNo
fitsNo
highNo
wordsNo
charactersNo
estimated_tokensNo
percent_of_windowNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changed
    • addedInput schema / properties / text / examples
      Added value: +[
      +  "The quick brown fox jumps over the lazy dog."
      +]
  2. Changed1 schema field changed
    • addedInput schema / description
      Added value: +"EN: Heuristically estimates how many LLM tokens a text uses (Latin text ~4 chars/token, CJK ~1 char/token, code and punctuation denser) with a ±25% range. Real counts depend on each model's tokenizer. When: an agent loop needs an exact, repeatable result for a bookkeeping step (tokens, costs, retries, chunking, ranking, JSON clean-up). Not for: estimating LLM request cost from input/output token counts (llm-cost-estimate). Side effects: none (read-only, no network access, no stored state). Deterministic: the same input gives the same output. Limits: JSON input up to 64 KB, 1 s per call, result up to 1 MB."
  3. First observed

TDQS

A4.4/5.0
Behavior4/5

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

Annotations already declare readOnlyHint, idempotentHint and openWorldHint=false, but the description still adds real information beyond them: the ±25% accuracy band, the tokenization heuristics, and hard limits (64 KB input, 1 s per call, 1 MB result). One flaw: the stated 64 KB input limit conflicts with the schema's maxLength of 1,048,576 characters, which could mislead an agent about accepted input size.

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

Conciseness3/5

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

The labeled structure (When / Not for / Side effects / Deterministic / Limits) is front-loaded and scannable, but the entry wastes space on duplicated Spanish and English text and ends with a leftover placeholder artifact '[EN completo / full EN: inputSchema.description]'. That noise costs it a level.

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?

With an output schema present and annotations covering the safety profile, the description supplies everything else an agent needs: purpose, routing to the sibling, determinism, and resource limits. The only residual gap is the input-size figure that does not match the schema constraint.

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?

Schema coverage is 100%, so the baseline is 3, and the description earns an extra point by explaining that Latin text runs ~4 chars/token while CJK is ~1 char/token and code/punctuation is denser – semantics about the input that the schema does not carry. The optional context_window parameter is not discussed in the prose, but the schema documents it adequately.

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?

Names a specific verb and resource (heuristically estimate LLM token count for a text) and adds the accuracy envelope (±25%) plus the char-per-token heuristics. It explicitly distinguishes itself from llm-cost-estimate, so an agent can pick between the two without opening either schema.

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?

The 'When:' clause enumerates concrete agent-loop scenarios (tokens, costs, retries, chunking, ranking, JSON clean-up) and the 'Not for:' clause names the alternative tool llm-cost-estimate along with the condition that selects it. This is exactly the when/when-not/alternative structure the rubric rewards.

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