Skip to main content
Glama

IA-QA — 152 QA & Dev Tools for AI Agents

truncate_to_tokens

Read-onlyIdempotent

Truncate text to at most N tokens (cl100k_base: ~4 chars/token) to avoid exceeding an LLM context window. Optionally keeps the end of the text instead of the start (useful for keeping recent conversation history). Reports whether truncation occurred and the estimated token count.

Input Schema

NameRequiredDescriptionDefault
inputYesText to truncate
from_endNoKeep the end of the text instead of the start (default: false)
max_tokensYesMaximum number of tokens to keep

Output Schema

NameRequiredDescriptionDefault
textNo
truncatedNo
tokens_estimateNo
original_tokens_estimateNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changed
    • addedInput schema / examples
      Added value: +[
      +  {
      +    "input": "short",
      +    "max_tokens": 50
      +  }
      +]
  2. Changed1 schema field changed
    • addedOutput schema / properties
      Added value: +{
      +  "original_tokens_estimate": {},
      +  "text": {},
      +  "tokens_estimate": {},
      +  "truncated": {
      +    "type": "boolean"
      +  }
      +}
  3. Changed1 schema field changed
    • changedOutput schema / (root)
      Previous value: -nullNew value: +{
      +  "additionalProperties": true,
      +  "type": "object"
      +}
  4. 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 readOnly/idempotent/non-destructive, so the safety profile is covered. The description adds useful behavior the annotations cannot convey: the tokenizer and its ~4 chars/token approximation, the head-vs-tail retention option, and that the result reports whether truncation occurred.

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?

Three sentences, front-loaded with the core action, followed by the optional behavior and the return signal. No filler or redundant restatement of the tool name.

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, return values needn't be spelled out, and the description still flags that truncation status and token count are reported. The approximation caveat on token counting is a valuable completeness touch; only a note on very short or empty input edge cases is missing.

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 baseline is 3. The description goes beyond the schema by naming the cl100k_base tokenizer and its rough chars-per-token ratio, which tells the agent how max_tokens is actually interpreted rather than just restating 'Maximum number of tokens to keep'.

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 ('Truncate text to at most N tokens') plus the mechanism and intent (avoid exceeding an LLM context window). This clearly separates it from siblings like count_tokens or context_window_check, which measure rather than modify text.

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?

Gives a concrete use case ('to avoid exceeding an LLM context window') and one scenario for the from_end flag ('keeping recent conversation history'). It doesn't explicitly name alternatives such as count_tokens or split_chunks or say when not to use it, which keeps it just under a 5.

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.