Skip to content
Latest (currently 2026.10.2) has the newest features, bug fixes, and CVE patches of Solo Enterprise for agentgateway.

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

Rate limiting for MCP

Page as Markdown

Control MCP tool call rates to prevent overload and ensure fair access to expensive tools.

Control MCP tool call rates to prevent overload and ensure fair access to expensive tools.

About

Rate limiting for MCP traffic helps you protect tool servers from abuse and control costs for expensive operations. Every MCP operation — whether it’s tools/list, tools/call, resources/read, or any other JSON-RPC method — is a single HTTP POST to the MCP endpoint. From the gateway’s perspective, there is no distinction between listing tools and actually running one.

How tool calls map to HTTP requests

Before adding limits, it helps to understand what agentgateway is counting. A typical MCP client session looks like the posts in the following table.

Client actionHTTP requests to /mcp
Connect to serverinitialize → 1 POST
List available toolstools/list → 1 POST
Call a tool oncetools/call → 1 POST
Total per tool call session~3–5 POSTs

This means a requests: 5 per-second limit doesn’t allow 5 tool calls per second. Instead, the limit allows roughly 1 tool call session per second (5 requests ÷ ~5 per session). Size your limits accordingly: think in sessions, not raw HTTP requests.

If you need to differentiate between tool calls and other MCP operations (such as to allow unlimited tools/list requests but cap tools/call requests), use per-tool rate limits with CEL descriptors to inspect the JSON-RPC method body.

Rate-limited responses

On MCP routes, most rate-limited requests return HTTP 200 with a JSON-RPC response instead of a 429, so that MCP clients can pass the error to the agent. This behavior follows the error handling section of the MCP specification. The response depends on the request type, and is the same for local and global rate limits.

RequestResponse
tools/callHTTP 200 with a tool result that has isError: true. This response requires version 2026.9.1 or later. The text is similar to rate limit exceeded (retry after 20s; limit 2, remaining 0). The LLM can use the retry time to decide when to call the tool again.
Other requests with a JSON-RPC id, such as initialize and tools/listHTTP 200 with a JSON-RPC error. The error code is -32003, and data has the limit, remaining, and retryAfterSeconds fields.
Notifications, which have no JSON-RPC id, such as notifications/initializedHTTP 429.

Each of these responses includes the rate limit response headers, such as x-ratelimit-remaining. To monitor rate limits on MCP routes, do not count 429 status codes. Instead, look for reason="RateLimit" in the access logs.

Gateway-level vs Route-level policies

You can apply rate limits at different levels to implement layered protection. Gateway-level policies act as a hard backstop across all traffic, while route-level policies provide finer-grained control.

When both a gateway-level policy and a route-level policy are defined, the route-level policy takes precedence for traffic matching that route.

Use cases

Review the following table for example use cases and configuration guidance.

What you wantHow to configure it
Cap tool call sessions per secondEnterpriseAgentgatewayPolicy on HTTPRoute, local[].requests. Remember ~5 HTTP requests per session.
Allow burst for session initializationAdd burst because each session needs several requests before the first tool call runs.
Hard ceiling across all gateway trafficEnterpriseAgentgatewayPolicy on Gateway, local[].requests.
Per-tool rate limits (for example, tighter for expensive tools)Enterprise rate limit with CEL descriptors extracting body.method and body.params.name.
Combine auth + rate limitingApply both mcp.authentication and traffic.rateLimit in the same EnterpriseAgentgatewayPolicy or use separate policies.

Also, check out the rate limiting guides for other use cases:

Before you begin

  1. Set up an agentgateway proxy.
  2. Set up access to the OpenAI LLM provider.
3. Deploy and route to an MCP server through agentgateway. For setup instructions, see Route to a static MCP server.

Local rate limiting

Local rate limiting runs in-process on each agentgateway proxy replica. The following steps show how to apply a per-route rate limit and verify its behavior with rapid tool call sessions.

  1. Apply a rate limit directly to the MCP HTTPRoute. The following example allows 5 tool calls per second with a burst of up to 15 (5 base + 10 burst) before the request is rate limited. The burst headroom is important for MCP clients: during session initialization, an agent typically fires initialize → tools/list → several tools/call requests back-to-back. Without burst capacity, the MCP server would hit the limit before doing any real work. For the response that a rate-limited request gets, see Rate-limited responses.

    kubectl apply -f- <<EOF
    apiVersion: enterpriseagentgateway.solo.io/v1alpha1
    kind: EnterpriseAgentgatewayPolicy
    metadata:
      name: mcp-rate-limit
      namespace: default
    spec:
      targetRefs:
      - group: gateway.networking.k8s.io
        kind: HTTPRoute
        name: mcp
      traffic:
        rateLimit:
          local:
          - requests: 5
            unit: Seconds
            burst: 10
    EOF
  2. Verify that the policy is attached.

    kubectl get EnterpriseAgentgatewayPolicy mcp-rate-limit -n default -o yaml

    Both Accepted and Attached conditions must be True.

  3. Use an MCP client to call tools in a tight loop.

    The following example assumes you have the MCP Inspector CLI installed. If prompted, install the MCP Inspector packages.

    for i in $(seq 1 20); do
      npx @modelcontextprotocol/inspector#0.21.2 \
        --cli "http://$INGRESS_GW_ADDRESS/mcp" \
        --transport http \
        --method tools/call \
        --tool-name echo \
        --tool-arg message='Hello World!'
    done
    for i in $(seq 1 20); do
      npx @modelcontextprotocol/inspector#0.21.2 \
        --cli "http://localhost:8080/mcp" \
        --transport http \
        --method tools/call \
        --tool-name echo \
        --tool-arg message='Hello World!'
    done

    Example output:

    {
      "content": [{ "type": "text", "text": "Echo: Hello World!" }]
    }
    ...
    {
      "content": [{ "type": "text", "text": "rate limit exceeded (retry after 0s; limit 15, remaining 0)" }],
      "isError": true
    }
    ...
    Failed to connect to MCP server: MCP error -32003: rate limit exceeded
    Failed with exit code: 1
    ...

    Each MCP Inspector run opens a new session, so it sends several requests (initialize, notifications/initialized, and tools/call). The first few runs succeed until the burst of 15 requests is used up. After that, a rate-limited tools/call returns a tool result with isError: true, and a rate-limited initialize makes the Inspector fail to connect with error -32003. Occasionally, the Inspector reports Error POSTing to endpoint: rate limit exceeded instead, when the notifications/initialized notification is the request that is rate limited.

Per-tool rate limits with CEL descriptors

Local rate limiting treats every POST to /mcp identically. But some tools are more expensive than others, and so they deserve tighter limits. With the enterprise rate limit service and CEL descriptors, you can look inside the MCP request body and apply different ceilings per tool name.

Note

To use a BYO rate limit service instead of the built-in enterprise rate limit service, see the agentgateway docs.

  1. Create a RateLimitConfig with per-tool rate limit rules. The following example applies different limits to different tools. Expensive tools (trigger-long-running-operation and sampleLLMCall) are limited to 3 calls per minute, while all other tool calls are limited to 10 calls per minute.

    kubectl apply -f- <<EOF
    apiVersion: ratelimit.solo.io/v1alpha1
    kind: RateLimitConfig
    metadata:
      name: mcp-tool-rate-limit
      namespace: agentgateway-system
    spec:
      raw:
        domain: "mcp-tools"
        descriptors:
        - key: mcp_method
          value: "tools/call"
          descriptors:
          - key: tool_name
            value: "trigger-long-running-operation"
            rateLimit:
              requestsPerUnit: 3
              unit: MINUTE
          - key: tool_name
            value: "sampleLLMCall"
            rateLimit:
              requestsPerUnit: 3
              unit: MINUTE
          - key: tool_name
            rateLimit:
              requestsPerUnit: 10
              unit: MINUTE
        rateLimits:
        - actions:
          - cel:
              expression: 'json(request.body).with(body, body.method == "tools/call" ? "tools/call" : "other")'
              key: "mcp_method"
          - cel:
              expression: 'json(request.body).with(body, body.method == "tools/call" ? string(body.params.name) : "none")'
              key: "tool_name"
    EOF

    The CEL expressions inspect the JSON-RPC body on every request:

    • mcp_method: Returns "tools/call" only when the JSON-RPC method field matches exactly. For other MCP operations like initialize or tools/list, it returns "other", which has no configured limit. This means those operations are never throttled.
    • tool_name: Extracts the tool name from params.name so each tool gets its own counter bucket. Combined with mcp_method, the rate limit service receives a two-key descriptor like mcp_method=tools/call, tool_name=trigger-long-running-operation and looks up the matching rule.
  2. Apply the rate limit by using an EnterpriseAgentgatewayPolicy resource. The following example targets the MCP HTTPRoute.

    kubectl apply -f- <<EOF
    apiVersion: enterpriseagentgateway.solo.io/v1alpha1
    kind: EnterpriseAgentgatewayPolicy
    metadata:
      name: mcp-tool-rate-limit
      namespace: default
    spec:
      targetRefs:
      - group: gateway.networking.k8s.io
        kind: HTTPRoute
        name: mcp
      traffic:
        entRateLimit:
          global:
            rateLimitConfigRefs:
            - name: mcp-tool-rate-limit
              namespace: agentgateway-system
    EOF
  3. Verify that the policy is attached.

    kubectl get EnterpriseAgentgatewayPolicy mcp-tool-rate-limit -n default -o yaml

    Both Accepted and Attached conditions must be True.

  4. Send multiple requests to different tools and verify that each tool has its own independent rate limit.

    Each tool maintains an independent counter. Exhausting the budget for trigger-long-running-operation (3 requests per minute) has no effect on the echo tool (10 requests per minute) because they have separate rate limit counters.

    # trigger-long-running-operation: 3/min limit — rate limited on the 4th call
    for i in $(seq 1 5); do
      npx @modelcontextprotocol/inspector#0.21.2 \
        --cli "http://$INGRESS_GW_ADDRESS/mcp" \
        --transport http \
        --method tools/call \
        --tool-name trigger-long-running-operation \
        --tool-arg duration=1 \
        --tool-arg steps=1
    done
    
    # echo: 10/min limit — all 5 pass through
    for i in $(seq 1 5); do
      npx @modelcontextprotocol/inspector#0.21.2 \
        --cli "http://$INGRESS_GW_ADDRESS/mcp" \
        --transport http \
        --method tools/call \
        --tool-name echo \
        --tool-arg message='Hello World!'
    done
    # trigger-long-running-operation: 3/min limit — rate limited on the 4th call
    for i in $(seq 1 5); do
      npx @modelcontextprotocol/inspector#0.21.2 \
        --cli "http://localhost:8080/mcp" \
        --transport http \
        --method tools/call \
        --tool-name trigger-long-running-operation \
        --tool-arg duration=1 \
        --tool-arg steps=1
    done
    
    # echo: 10/min limit — all 5 pass through
    for i in $(seq 1 5); do
      npx @modelcontextprotocol/inspector#0.21.2 \
        --cli "http://localhost:8080/mcp" \
        --transport http \
        --method tools/call \
        --tool-name echo \
        --tool-arg message='Hello World!'
    done

    Example output:

    # trigger-long-running-operation calls (3/min limit)
    {
      "content": [{ "type": "text", "text": "Long running operation completed. Duration: 1 seconds, Steps: 1." }]
    }
    {
      "content": [{ "type": "text", "text": "Long running operation completed. Duration: 1 seconds, Steps: 1." }]
    }
    {
      "content": [{ "type": "text", "text": "Long running operation completed. Duration: 1 seconds, Steps: 1." }]
    }
    {
      "content": [{ "type": "text", "text": "rate limit exceeded (retry after 60s; limit 3, remaining 0)" }],
      "isError": true
    }
    {
      "content": [{ "type": "text", "text": "rate limit exceeded (retry after 60s; limit 3, remaining 0)" }],
      "isError": true
    }
    
    # echo calls (10/min limit) - all succeed
    {
      "content": [{ "type": "text", "text": "Echo: Hello World!" }]
    }
    {
      "content": [{ "type": "text", "text": "Echo: Hello World!" }]
    }
    {
      "content": [{ "type": "text", "text": "Echo: Hello World!" }]
    }
    {
      "content": [{ "type": "text", "text": "Echo: Hello World!" }]
    }
    {
      "content": [{ "type": "text", "text": "Echo: Hello World!" }]
    }

Cleanup

You can remove the resources that you created in this guide.
kubectl delete RateLimitConfig mcp-tool-rate-limit -n agentgateway-system
kubectl delete EnterpriseAgentgatewayPolicy mcp-rate-limit -n default
kubectl delete EnterpriseAgentgatewayPolicy mcp-tool-rate-limit -n default