Skip to content
mentoor

Topic 3 of 4 · 5 min read

Caching, rate limits and quotas for agent traffic

Goal: Set cache and rate-limit settings for a server from its usage data and explain how they protect it from a looping agent.

Cache what rarely changes, limit what an agent could repeat without end, and give every call a deadline. Agent traffic is unlike human traffic: an agent can call the same tool hundreds of times in a minute, with no sense that it is stuck.

Check yourself · 1 of 3

What does cacheScope: "private" on a tools/list result tell clients and proxies?

Choose one answer

Why it matters

A person clicks a few times a minute. An agent in a loop retries a failing search, re-lists tools on every step, or fires the same write again after a timeout. Without limits, one confused run can exhaust your database connections or your downstream API budget and take every other agent down with it.

Caching hints

In the 2026-07-28 spec, results of tools/list, prompts/list, resources/list, resources/templates/list, resources/read and server/discover carry two fields:

  • ttlMs: how many milliseconds the client may treat the result as fresh. It is a hint, like HTTP max-age, not a promise. Zero means stale at once.
  • cacheScope: public if the result is the same for everyone, private if it depends on the caller. Caches must not be shared across authorization contexts.

A tool list that changes twice a year can use a long ttlMs and public. A list filtered by the caller's permissions must be private. Servers that also send notifications/tools/list_changed let clients refresh early when the list does change.

Return tools in a deterministic order. The spec says the same order across requests, when the set has not changed, lets clients cache the list and improves LLM prompt cache hit rates. A list sorted by a random hash or by last-used time breaks the model's prompt cache on every call.

Limits

  1. Per-caller rate limit: calls per minute for each user or agent, with a lower limit for expensive tools.
  2. Per-run or daily quota: a hard cap, such as a maximum number of write calls per run.
  3. Timeouts: every tool call has a deadline, and you honour cancellation so abandoned work stops.
  4. Idempotency for writes: accept a client request key so a retry does not create a second order.
  5. A clear error: return a tool error that says what limit was hit and when to retry, so a model can stop instead of looping.

Before and after

Before: no limits. An agent retries search_catalog 400 times in a minute against a database that serves 50 queries per second.

After:

Setting Value
tools/list ttlMs 3600000, public, stable order
search_catalog 30 calls/min per user, 10 s timeout
create_order 5 calls/run, idempotency key required
limit error "Rate limit reached for search_catalog, retry in 40 s"

What goes wrong

  • Caching a private list as public, so one user sees another's tools or data.
  • A limit with a vague error. The model retries immediately because nothing says to wait.
  • Retries without idempotency, which duplicates writes.
  • One shared limit for all users, so a single loop locks everyone out.

Examples

Sizing a limit from usage data

Logs show real users call search_catalog at most 12 times a minute, while the database handles 50 queries a second in total. A per-user limit of 30 a minute leaves room for bursts and still stops a loop within seconds. A limit of 1,000 would protect nothing.

Shuffled tool order

A server builds its tool list from a hash map, so the order changes between processes. Each reconnect gives the model a different tool list, so its prompt cache misses every time. Sorting by tool name gives a stable list with no other change.

Key points

  • ttlMs and cacheScope on list and read results tell clients how long a result stays fresh and whether it may be shared.
  • A list that varies by caller must be private; caches must not cross authorization contexts.
  • Return tools in the same order on every request so clients and model prompt caches stay valid.
  • Rate limits and quotas should be per caller, with tighter limits and hard caps on expensive or write tools.
  • A limit error should say what was hit and when to retry, so the model stops instead of looping.

Common mistakes

  • Marking a caller-specific list as public.
  • Applying one shared rate limit to all users instead of one per caller.
  • Returning a limit error with no retry hint, so the agent retries at once.
  • Retrying write tools without an idempotency key.

Check yourself · 2 of 3

An agent that hits a rate limit keeps retrying the same call every second. Which change to the limit response helps most?

Choose one answer

Check yourself · 3 of 3

Why should a server return its tools in the same order on every tools/list call?

Choose one answer

Practice items, not counted towards your mastery.

Start here