Rate Limit

The per-IP rate limit of the MCPServer’s public endpoint.

The MCP server requires no authentication, so each client IP address may send at most smarter_settings.mcpserver_rate_limit requests a minute, 1200 by default. The requests are counted in fixed one-minute windows, in Redis, so that every pod of the platform shares the count. A request beyond the limit is answered 429 Too Many Requests, with a Retry-After header, until the window ends.

The client’s address is found as SmarterMiddlewareMixin finds it, from X-Forwarded-For, X-Real-IP, CF-Connecting-IP or the connection itself, ignoring private addresses, which are the platform’s own proxies. A request whose public address cannot be determined, e.g. in local development, is not limited.

Note

Experimental. The MCPServer was designed and coded by Claude Code (Anthropic’s Claude Opus 5.5), with Lawrence McDaniel as co-author. It is experimental, and will be documented.

smarter.apps.mcpserver.protocol.ratelimit.RATE_LIMITED = -32010

The JSON-RPC error code of a rate-limited request, in the implementation-defined range of MCP’s error codes.

smarter.apps.mcpserver.protocol.ratelimit.client_ip(request)[source]

Return the public IP address of a request’s client.

The ClientAddress helper is created on the first call, and reused.

Parameters:

request (HttpRequest) – The request.

Return type:

str | None

Returns:

The address, or None if it cannot be determined.

smarter.apps.mcpserver.protocol.ratelimit.is_rate_limited(ip)[source]

Count a request of a client, and return whether the client is over the limit.

The count is kept in the cache (Redis), so every pod of the platform shares it. The first request of a window creates its key with add(), and each later one increments it with incr(), which is atomic, so that concurrent requests are all counted.

Side effects: one or two cache writes, unless the limit is off or the address is unknown.

Parameters:

ip (str | None) – The client’s IP address, from client_ip().

Return type:

bool

Returns:

True if the client has sent more than smarter_settings.mcpserver_rate_limit requests in the current window. Always False if the limit is 0, or the address is unknown.

smarter.apps.mcpserver.protocol.ratelimit.retry_after()[source]

Return the seconds until the current rate limit window ends, for a Retry-After header.

Return type:

int

Returns:

The seconds left in the window, at least 1.