Skip to main content
Glama

token-bucket

Shared token bucket: many agents, one upstream rate limit — One rate limiter shared by every agent in your fleet. take(cost) atomically spends tokens if available and returns allowed plus remaining, or refuses with retryAfterMs until enough tokens refill. capacity and refillPerSecond are fixed when the bucket is first used; a call with different settings is refused so two fleets cannot silently disagree. Use a requestId so a retried take is not charged twi

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": {
      "op": "<op>",
      "bucket": "<bucket>",
      "capacity": "<capacity>",
      "refillPerSecond": "<refillPerSecond>"
    },
    "name": "token-bucket"
  }
}

Input Schema

NameRequiredDescriptionDefault
opYes
costNoTokens to spend; default 1.
bucketYesBucket name, e.g. openai:org-123:rpm.
capacityYesBucket size in tokens. Required on every call, peek included, and must equal the value the bucket was created with.
tenantIdNoRequired for API-key callers (namespaced as key:<tenantId>; keep it unguessable). Ignored when a wallet paid: the payer address is the tenant.
requestIdNoCaller-chosen id for this mutation. A retry with the same id and same input returns the stored response (24 h) instead of applying twice; the same id with different input is rejected. Send one on every mutation you may retry: without it a retry is applied again (fleet-memory record appends a duplicate; a repeated spend-ledger commit or release answers NO_HOLD because the first call already took effect).
refillPerSecondYesTokens added per second (0.5 = one every 2 s). Required on every call; must equal the value the bucket was created with.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changed
    • addedInput schema / properties / capacity / description
      Added value: +"Bucket size in tokens. Required on every call, peek included, and must equal the value the bucket was created with."
    • addedInput schema / properties / refillPerSecond / description
      Added value: +"Tokens added per second (0.5 = one every 2 s). Required on every call; must equal the value the bucket was created with."
  2. First observed

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 burden. It discloses important behavior – atomicity of take, refusal with retryAfterMs, immutable capacity/refillPerSecond, and idempotent retries via requestId – which is genuinely useful. However, it omits auth/tenant implications (tenantId requirement, key:<tenantId> namespacing) and says nothing about peek's behavior, and the final sentence is cut off mid-word ('not charged twi'), leaving the retry-charging rule incomplete.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The content is front-loaded and dense with no filler sentences, which is good. But the description is visibly truncated mid-word at the end, so the final and most operationally important retry-charging rule is left unfinished – a structural defect, not merely brevity.

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 stateful, mutating limiter with no output schema and no annotations, the description covers the essentials: atomic spend, refusal path, idempotency guidance, and immutable configuration. Gaps remain around the peek operation's return value and the truncated retry rule, but an agent could call take correctly from what is written.

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 86%, so the schema already explains cost, capacity, refillPerSecond, tenantId and requestId in detail. The description mostly restates the immutability rule for capacity/refillPerSecond, adding only the rationale that two fleets cannot silently disagree, and it never mentions op, tenantId, or requestId's stored-response window beyond the truncated retry hint. Baseline 3 is appropriate.

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 opens with a concrete resource and purpose ('Shared token bucket: many agents, one upstream rate limit') and specifies the primary operation's semantics: take(cost) atomically spends tokens and returns allowed plus remaining or refuses with retryAfterMs. It does not describe the second enum operation, peek, so the stated purpose covers only part of what the tool exposes. No sibling in the catalog performs comparable rate limiting, so a sibling-differentiation clause is not essential here.

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 tells the caller when this applies (one limiter shared across a whole agent fleet) and gives concrete usage rules: capacity and refillPerSecond must match the values the bucket was created with, mismatched settings are refused, and requestId should be used on any take that may be retried. It does not name an alternative tool or say what to do when a take is refused beyond the returned retryAfterMs.

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