Skip to main content
Glama
crisjonblvx

enrichrapi-mcp

by crisjonblvx

count_llm_tokens

Count tokens in text for any major LLM model to manage context windows, avoid overflows, and estimate input costs. Returns consumption, remaining tokens, and cost.

Instructions

Count the tokens in text for any major LLM model.

Returns the exact token count (or a close approximation for non-OpenAI models), how much of the model's context window is consumed, tokens remaining, and the estimated input cost. Essential for prompt engineering, RAG chunk sizing, and context window management.

Supported models: OpenAI: gpt-5.6, gpt-5, gpt-4o, gpt-4.1, o3, o4-mini Anthropic: claude-opus-5, claude-sonnet-5, claude-haiku-4-5 (plus aliases: claude-opus-4, claude-sonnet-4) Google: gemini-3.5-flash, gemini-3.1-pro, gemini-2.0-flash Meta: llama-4-maverick, llama-4-scout, llama-3.3-70b Mistral: mistral-large-3, mistral-small-4 DeepSeek: deepseek-v4-flash, deepseek-v4-pro, deepseek-v3, deepseek-r1

OpenAI models use tiktoken counts. All other models are approximated with cl100k_base (accurate to ±10%). Input prices are estimates; see as_of.

Args: text: The text to count tokens for (prompt, document, message, etc.) model: LLM model name (default "gpt-4o")

Returns: dict with keys: model, model_family, token_count, context_window, context_used_pct, tokens_remaining, fits_in_context, estimated_input_cost_usd, approximate, as_of, note, cost_usd

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes
modelNogpt-4o

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.2.0

TDQS

A4.7/5.0
Behavior5/5

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

With no annotations provided, the description carries full burden and handles it well. It discloses key behavioral traits: exact counts for OpenAI, ±10% approximation for other models using cl100k_base, estimated input prices with an as_of date, and the exact return key structure. The user can predict what the tool does and its accuracy limits.

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 description is longer than average due to the supported-model enumeration, but every section earns its place: purpose, return value summary, model list, algorithm notes, and parameters. The core behavior is front-loaded, and the organization makes it skimmable.

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 tool with no annotations and no output schema, the description provides everything an agent needs: purpose, supported models, approximation behavior, pricing caveat, and a full return-key list. The model list is future-proofed with aliases, and the mention of 'as_of' prevents misuse of stale prices.

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

Parameters5/5

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

Schema description coverage is 0%, but the description includes an Args section that explains both parameters: text ('The text to count tokens for') and model ('LLM model name (default "gpt-4o")'). It even lists acceptable model values, fully compensating for the sparse schema.

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 opens with a specific verb and resource: 'Count the tokens in text for any major LLM model.' It clearly distinguishes the tool from its utility siblings (e.g., convert_units, generate_hash) by stating its domain—LLM token counting for prompt engineering. The supported model list further reinforces the exact scope.

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

Usage Guidelines4/5

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

The description explicitly names core use cases: 'Essential for prompt engineering, RAG chunk sizing, and context window management.' It doesn't enumerate when not to use the tool or name direct alternatives, but given the sibling list contains no competing token-counting tool, this is sufficient context for selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.