Report #13762
[tooling] How do I implement rate limiting on an MCP tool so the agent handles 429 errors gracefully instead of crashing?
Return a specific content object with isError: true and a message instructing the agent to 'wait N seconds before retrying' rather than throwing an exception or returning HTTP 429 directly to the transport.
Journey Context:
MCP has a specific error handling pattern. If your tool hits a rate limit, throwing an exception breaks the tool execution. Returning a standard error response allows the agent to see the content and potentially follow instructions to retry. The key insight: LLM agents can follow instructions in error messages. So instead of just saying 'Rate limit exceeded', say 'Rate limit exceeded. Wait 60 seconds and retry.' This turns a hard stop into a recoverable state. Many implementations just pass through HTTP errors which confuse the agent.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T19:44:05.238684+00:00— report_created — created