Skip to main content
Glama

messages_count_tokens

Read-only

Count tokens (Anthropic-compatible) — Anthropic Messages API compatible token counter: POST the same body you would send to /v1/messages (model, messages, optional system and tools) and get {input_tokens} back before you send it. Handles text, image, document, tool_use and tool_result blocks plus tool-definition overhead, with a per-part breakdown. Heuristic estimate (typically within about 15% for English), no model call, instant. Use it to budget context windows and cost before calling /v1/messages. Price: $0.001 USDC (Base, via x402).

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": {
      "model": "<model>",
      "messages": "<messages>"
    },
    "name": "messages_count_tokens"
  }
}

Input Schema

NameRequiredDescriptionDefault
modelYesclaude-sonnet-4-5
messagesYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Added

TDQS

A4.6/5.0
Behavior5/5

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

Beyond the annotations (readOnly, openWorld, non-destructive), it discloses accuracy ('heuristic estimate, typically within about 15% for English'), cost/latency ('no model call, instant'), the exact response shape ({input_tokens} plus a per-part breakdown), and a payment requirement ($0.001 USDC on Base via x402). These are all facts an agent cannot get from the structured fields.

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?

It is front-loaded with the core action and resource, then layers compatibility, behavior, accuracy, and price in a logical order. It is dense and slightly run-on, but nearly every clause carries decision-relevant information, so little could be cut without loss.

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 two-parameter read-only counter with no output schema, the description supplies everything needed: input body shape, supported content block types, return shape, accuracy caveat, latency, and payment cost.

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?

With 50% schema coverage, the description does real work: it enumerates the body fields (model, messages, optional system and tools) and the block types handled (text, image, document, tool_use, tool_result) plus tool-definition overhead. The only weakness is that 'system' and 'tools' are described but not present in the input schema, which may confuse an agent about what it can actually pass.

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 tokens') and immediately scopes it as 'Anthropic Messages API compatible', explaining that it accepts 'the same body you would send to /v1/messages'. That compatibility framing is what separates it from a generic token counter among the ai_* siblings.

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?

It gives an explicit use case: 'budget context windows and cost before calling /v1/messages'. It is clear about the situation the tool is for, but it does not name an alternative counter (e.g. ai_token_count) or state when a different tool would be preferable.

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.

Resources