Skip to main content
Not all MCP tools cost the same. A tool that runs a complex query costs far more than one returning cached data. When multiple agents share the same proxy, a single blanket rate limit either over-restricts lightweight tools or under-protects expensive ones. Tyk lets you set rate limits on individual tools, per consumer. Each agent key tracks its own independent counter: one agent exhausting their budget on a tool does not affect another agent’s counter for the same tool. Per-tool limits sit on top of Tyk’s standard per-key controls. The same policy can also set an overall rate limit and a quota for every key it issues, covering all traffic on the MCP proxy rather than one tool. See Rate limiting and Request quotas. In short, the Tyk MCP gateway enforces per-tool rate limits per consumer: every key on a policy gets its own counter for each limited tool, so one agent using up its budget does not block another agent calling the same tool. This guide rate limits the get_analytics tool on the Mock MCP Server to 3 calls per minute for a specific consumer policy, then uses MCP Inspector to verify the limit is enforced.

Before you begin

  • The Mock MCP Server running on http://localhost:7878. Set up in the quickstart.
  • An MCP proxy named Mock MCP Server with authentication enabled. See How to secure an MCP proxy.
  • Node.js 18 or later (to run MCP Inspector)
  • A Dashboard user account with policy management permissions

Instructions

Step 1: Create a policy with a per-tool rate limit

  1. In the Tyk Dashboard sidebar, click Policies, then click Add Policy.
  2. On the Access Rights tab, find Mock MCP Server in the API list and click it to add it.
  3. Expand the Mock MCP Server access rights block and scroll to Set Usage Limits by MCP Primitives/Methods.
  4. Click Add Rate Limit and configure the limit:
    • Set Rate to 3
    • Set Per to 60 seconds
    • Click Add, enter get_analytics, and set Type to Tool
    Add get_analytics as a tool primitive
  5. Click Add to confirm the primitive.
  6. Click the Configurations tab and set:
    • Policy Name: Limited Agent
    • Policy State: Active
  7. Click Create Policy. If you manage policies through the Dashboard API or as code, the same limit is an mcp_primitives entry in the policy’s access_rights for the MCP proxy. This excerpt is adapted from the MCP Gateway policies reference:
    "access_rights": {
      "{mcp-proxy-api-id}": {
        "api_id": "{mcp-proxy-api-id}",
        "versions": ["Default"],
        "mcp_primitives": [
          { "type": "tool", "name": "get_analytics", "limit": { "rate": 3, "per": 60 } }
        ]
      }
    }
    Create the Limited Agent policy

Step 2: Issue a key

  1. In the Dashboard sidebar, click Keys, then Add Key.
  2. Under Access rights, click Apply Policy and select Limited Agent.
  3. Click the Configurations tab and set an Alias such as limited-agent to identify this key in analytics.
  4. Click Create Key and copy the key.

Step 3: Verify with MCP Inspector

  1. Start MCP Inspector:
  2. Open the URL printed in your terminal.
  3. Set Transport Type to Streamable HTTP.
  4. Set URL to your MCP endpoint (find it under MCP Proxy URL in the proxy designer, then append /mcp).
  5. Add a header: Authorization = Bearer {your-api-key}.
  6. Click Connect.
  7. Click the Tools tab and select get_analytics.
  8. The tool requires a metric parameter. Enter users (or any of posts, orders, revenue).
  9. Click Run three times in quick succession. Each call succeeds. The response panel shows the analytics data from the Mock MCP Server.
  10. Click Run a fourth time. Tyk has exhausted the 3 calls per minute budget for this consumer and blocks the request. The response panel shows: MCP error -32001: Streamable HTTP error: Error POSTing to endpoint:
  11. Click any other tool (get_users, get_posts, get_products) and click Run. Those calls succeed normally. Only the get_analytics counter is exhausted.

How per-consumer and shared limits compose

Each key on the Limited Agent policy has its own counter for get_analytics. To add a limit shared by all consumers, see Policies versus middleware.
Where you set the limitWho shares the counterUse it to
Policy (mcp_primitives in access_rights)Each key has its own counterGive different consumers different budgets on the same tool
Proxy middleware (middleware.mcpTools.<tool>.rateLimit)All consumers of the proxy share one counterProtect the upstream MCP server from total overload
When both are set on the same tool, Tyk enforces both with separate counters, checks the per-key policy limit first, and blocks the request at the first limit it exceeds.