Skip to main content
Glama

count_tokens

Estimate token counts for text or files before running local agents or summaries, so you can check if input fits within the model context limit.

Instructions

Estimate token counts for text/files (chars/4 heuristic — ±20% vs a real tokenizer; for input sizing, not billing). Use before run_local_agent/summarize to check fit vs num_ctx.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
globNoGlob pattern, e.g. 'src/**/*.ts'
pathNoSingle file path (read server-side — never enters your context)
textNoInline text instead of files
pathsNoMultiple file paths

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.2/5.0
Behavior4/5

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

With no annotations the description carries the full burden, and it delivers: it discloses the chars/4 heuristic, quantifies the error margin (±20% vs a real tokenizer), and scopes it as input sizing not billing. It stops short of explaining the return shape or whether paths are read server-side (left to the schema).

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?

Two tight sentences, zero waste, with the core caveat (heuristic, ±20%) front-loaded and the usage guidance second. Every clause carries information.

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?

For a simple utility with no output schema and no annotations, the description covers purpose, accuracy limits, and usage context well. The one gap is that, absent an output schema, it does not describe what is returned (per-file vs aggregate counts), which an agent might want.

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%, so all four parameters (glob, path, text, paths) are already documented in the schema. The description's 'for text/files' only loosely gestures at the text-vs-file distinction without adding syntax or precedence rules, so baseline 3 applies.

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 (estimate/count) and resource (tokens for text/files), and the parenthetical makes clear it is a sizing heuristic rather than a billing-grade tokenizer. This cleanly distinguishes it from the model/agent-running siblings like run_local_agent and summarize.

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?

Names the trigger scenario ('Use before run_local_agent/summarize to check fit vs num_ctx') and the purpose, which is strong routing guidance. It lacks an explicit when-not-to-use or a note about the other sizing siblings, so it falls just short of a full 5.

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