Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:0sec labs 0 Agent Interaction

From Leeroopedia
Knowledge Sources
Domains MCP, Rate_Limiting, Traffic_Management
Last Updated 2026-10-30 00:00 GMT

Overview

Technique for enforcing per-host token-bucket rate limits on outgoing HTTP requests from an MCP server, with 429 backoff and a conservative cool-off floor, to prevent aggressive agents from overwhelming target infrastructure.

Description

Agent interaction rate limiting is the principle that an AI agent making HTTP requests through an MCP server must be rate-limited to prevent abuse and respect target infrastructure. The RateLimiter uses a token-bucket algorithm per host: hostnames are normalized (lowercased, port stripped) so api.example.com:443 and API.example.com share a bucket. When a 429 response lands without a useful Retry-After, a conservative 60-second cool-off floor applies. The parseRateLimitFlag function parses CLI specs like "host=rps,host2=rps:burst,default" or plain "5" for a default rps. An optional onThrottle observer fires when a request is actually throttled.

Usage

Use this principle when an MCP server exposes HTTP tools (http_request, crawl, submit_form) to an AI agent. Rate limiting prevents the agent from sending too many requests too fast.

Theoretical Basis

The token-bucket algorithm:

# Abstract model (NOT real implementation)
class TokenBucket:
    capacity: float       # burst size
    tokens: float          # current tokens
    refill_rate: float     # tokens per second

    def acquire():
        if tokens >= 1:
            tokens -= 1
            return  # allowed
        else:
            sleep(until_next_token())  # block
            acquire()

class RateLimiter:
    default_config: HostRateConfig
    per_host: dict[str, HostRateConfig]
    buckets: dict[str, TokenBucket]  # per-host

    async def acquire(host):
        bucket = get_or_create_bucket(host)
        await bucket.acquire()

The 429 backoff: when a target returns 429, the host is "parked" for max(Retry-After, 60s). The 60-second floor ensures a target that just said "slow down" gets a meaningful pause, not a one-second retry.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment