Skip to main content
Glama

trim_context

Drops the oldest messages when a prompt exceeds the model's context window, keeping recent turns so requests stay under the limit instead of failing with "Prompt is too long" errors.

Instructions

Trim the oldest messages when the estimated context exceeds the model limit.

Example call::

trim_context({
    "messages": [...],
    "keep_last": 8,
    "max_context_tokens": 32768,
})

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "messages": "<messages>"
    },
    "name": "trim_context"
  }
}

Input Schema

NameRequiredDescriptionDefault
messagesYes
keep_lastNo
max_context_tokensNo

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A3.6/5.0
Behavior3/5

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

No annotations are supplied, so the description carries the full behavioral burden. It usefully discloses the key behavior — the *oldest* messages are the ones removed — but says nothing about whether trimming is lossy/irreversible, what happens when the context is already under the limit (no-op?), or whether messages are mutated in place versus returned as a new list. For a destructive-feeling context operation with zero annotation coverage, this is a meaningful gap.

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 actionable rule is front-loaded in a single sentence with no wasted preamble. The code block largely restates what the input schema already declares, so it is mild redundancy rather than the most efficient use of space, but overall the definition is tight.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

An output schema exists, so return values need not be spelled out. What is missing is proportionate to the tool's mutation-like nature and absent annotations: whether trimming mutates the caller's message list or returns a trimmed copy, and whether dropped content is recoverable. The definition is minimally complete but leaves an agent guessing on those points.

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 0%, so the description must compensate for three bare parameters. The example call does at least show shape and the default-like values (keep_last: 8, max_context_tokens: 32768), and 'keep_last' is semantically inferable from its name. However, 'max_context_tokens' is never explained (which tokenizer, whether it is a hard cap or a threshold), and the example conveys syntax rather than meaning, so compensation is only partial.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource — 'trim the oldest messages' — plus the triggering condition (estimated context exceeding the model limit). An agent can tell this is a context-reduction operation, though it never contrasts itself with the siblings compact_context or estimate_context, so the boundary between trimming and compacting is left implicit.

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 condition 'when the estimated context exceeds the model limit' gives a clear when-to-use trigger, which is more than most definitions offer. It stops short of alternatives or exclusions: it never mentions estimate_context for checking size first or compact_context for a lossless/summarizing alternative, so the choice among the three siblings is not resolved.

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

Deploy Server

Other Tools