Skip to main content
Glama

estimate_context

Estimate token size of a message list before sending to a model, so you can keep requests under the context window and avoid "Prompt is too long" errors.

Instructions

Estimate the current context size in tokens before sending it to the model.

Example call::

estimate_context({
    "messages": [{"role": "user", "content": "hello"}],
    "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": "estimate_context"
  }
}

Input Schema

NameRequiredDescriptionDefault
messagesYes
max_context_tokensNo

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

B3.4/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, and it does not state that the operation is side-effect free, whether it performs a network/model call, or whether it is cheap to call in a loop. It does convey the core semantics that the result is an estimate, and a declared output schema means return values need not be explained here.

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 purpose is front-loaded in a single clear sentence and the example is compact and illustrative. The reStructuredText '::' marker is noise rather than helpful structure, but the overall length is appropriate and every element carries information.

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 the description is not required to document return values, and the example covers the basic call shape. For a tool with zero annotation coverage and zero schema parameter descriptions, however, the definition should say more about side effects and about how it relates to the compact/trim siblings before an agent can call it with confidence.

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 schema alone leaves both parameters opaque. The worked example compensates partially by revealing the shape of a messages entry (role/content) and showing max_context_tokens being used with its default value. It does not explain what happens when the estimate exceeds max_context_tokens — whether it errors, warns, or just reports — which is the key semantic an agent needs.

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?

The description gives a specific verb and resource — estimate the current context size in tokens — plus the purpose of doing so before sending to the model. It is clear on its own, but it never distinguishes itself from the sibling tools compact_context and trim_context, so an agent cannot tell from this text alone whether to measure, compact, or trim.

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

Usage Guidelines3/5

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

The phrase 'before sending it to the model' implies a pre-flight check use case, which is useful implied guidance. However, there are no explicit when-not conditions, no mention of the sibling alternatives, and no statement about whether this should be called repeatedly or whether it only counts locally.

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