---
title: How to rate limit MCP tool calls
description: Count calls per person in a rolling window at your MCP server or a gateway, and return refusals as tool errors. A Claude Code hook covers one laptop.
canonical: https://mcp1.com/blog/rate-limit-mcp-tool-calls
last-updated: 2026-11-16
---

# How to rate limit MCP tool calls

Count calls per person in a rolling window at your MCP server or a gateway, and return refusals as tool errors. A Claude Code hook covers one laptop.

![](https://avatars.githubusercontent.com/u/1297371?s=96&v=4)Eldad FuxFounder and CEO, Appwrite

 Calls this minute

- github\_\_search\_code12:04:51Allowed
- github\_\_search\_code12:04:51Allowed
- github\_\_search\_code12:04:52Allowed
- github\_\_search\_code12:04:52Rate limited

 Calls this minute

- github\_\_search\_code12:04:51Allowed
- github\_\_search\_code12:04:51Allowed
- github\_\_search\_code12:04:52Allowed
- github\_\_search\_code12:04:52Rate limited

To rate limit MCP tool calls, count calls per person in a rolling window at a point every call passes through, your own MCP server or a gateway in front of your servers, and refuse calls over the limit. Return the refusal as a tool error the model can read, with the limit and when to retry, so the agent slows down instead of retrying straight away. MCP clients have no rate limit setting, though a Claude Code hook can approximate one on a single machine.

## Why do MCP tool calls need a rate limit?

A person clicking through a dashboard makes a few requests a minute. An agent can make dozens, and nothing in the protocol slows it down. The cases that hurt:

- A loop. A tool returns an error the model misreads, and it calls the same tool again with the same arguments until the session ends.
- Fan-out. Subagents or parallel tool calls each search the same service at once, so one question turns into many requests in a few seconds.
- A shared quota. GitHub allows 5,000 REST requests an hour per user token. If a team’s agents share one token, one runaway session spends the hour for everyone.
- Metered APIs. Search, enrichment and data vendors bill per call, and an agent repeating a query costs real money each time.

The upstream service will limit you eventually, but its limit is blunt: it answers 429 to everyone on that credential, and it can’t tell which person or agent caused it.

## Where can you enforce the limit?

Only a layer that sees every call, and knows who made it, can apply a fair limit:

LayerWhat it can do

Client

No built-in setting in Claude Code, Cursor, VS Code or Codex. A Claude Code hook can count calls on one machine, which a person can turn off.

Your MCP server

Limit per authenticated user, if you run the server. You can’t change a vendor’s hosted server.

Gateway

Limit per person across every server and client behind it, including vendor servers you don’t control.

Upstream API

Already limits per credential or per account, after the fact, with no idea which agent was looping.

## How do I rate limit MCP calls in Claude Code?

Use a `PreToolUse` hook. Claude Code names MCP tools `mcp__<server>__<tool>`, so the matcher `mcp__.*` runs the hook before every MCP call. When the hook exits with code 2, Claude Code blocks the call and passes the hook’s stderr to the model. This script allows 60 calls in any 60 seconds:

.claude/hooks/mcp-rate-limit.sh

```
#!/usr/bin/env bash
# Allow at most LIMIT MCP tool calls in any 60 seconds, across this machine's Claude Code sessions.
LIMIT=${MCP_CALLS_PER_MINUTE:-60}
LOG="${TMPDIR:-/tmp}/claude-mcp-calls.log"
now=$(date +%s)
recent=$(awk -v cutoff=$((now - 60)) '$1 > cutoff' "$LOG" 2>/dev/null)
count=$(printf '%s' "$recent" | grep -c .)
if [ "$count" -ge "$LIMIT" ]; then
  echo "Rate limit: $LIMIT MCP calls a minute. Wait before the next call, and combine requests where you can." >&2
  exit 2
fi
printf '%s\n%s\n' "$recent" "$now" | grep . > "$LOG.tmp" && mv "$LOG.tmp" "$LOG"
```

Make it executable, then register it in the project’s settings:

.claude/settings.json

```
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "mcp__.*",
        "hooks": [
          { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/mcp-rate-limit.sh" }
        ]
      }
    ]
  }
}
```

The count is shared by every Claude Code session on the machine, since they write to the same file, and parallel calls can slip one or two past the limit. It stops a loop on a laptop. It does nothing for Cursor, ChatGPT, a CI job or anyone who edits their settings, which is why it’s a safety net and not a control.

## How do I add a rate limit to my own MCP server?

Key the limit on the authenticated user, the subject of the access token, not on IP address or MCP session. One person can open many sessions, and a whole office can share one IP. A sliding window in memory is enough for a single process:

TypeScript

```
const WINDOW_MS = 60_000
const LIMIT = 60
const calls = new Map<string, number[]>()

function allow(subject: string) {
  const now = Date.now()
  const recent = (calls.get(subject) ?? []).filter((t) => now - t < WINDOW_MS)
  const ok = recent.length < LIMIT
  if (ok) recent.push(now)
  calls.set(subject, recent)
  return ok
}

// In the tools/call handler, before the tool runs. subject comes from the verified access token.
if (!allow(auth.subject)) {
  return {
    isError: true,
    content: [{ type: 'text', text: `Rate limit reached: ${LIMIT} calls a minute. Wait a minute, or combine requests.` }],
  }
}
```

Return the refusal as a tool result with `isError: true`, not a JSON-RPC protocol error. The MCP spec puts tool execution errors in the result so the model sees them and can adjust, while clients often surface protocol errors to the user instead. With more than one server instance, move the counter to a shared store such as Redis, or each instance allows the full limit.

Count refused calls too

Count every call against the limit, including ones your access rules deny. An agent looping on a tool it isn’t allowed to use is still a loop, and it still fills your logs.

## What limit should I set?

Work back from what you’re protecting:

- A shared upstream quota: divide it by the people who share the credential. Ten people on one GitHub token share 5,000 requests an hour, about 8 a minute each if they all work at once, so a per-person limit far above that only moves the 429 upstream.
- A metered API: set a daily budget in the vendor’s console as well. A per-minute limit stops a loop quickly; it doesn’t cap a slow, steady overspend.
- Loops in general: pick a number a person working with an agent rarely reaches, then read the refusals in your logs for a week and adjust.

Whatever the number, record each refusal with who hit it and which tool. A person who hits the limit every day either has a broken workflow or needs a higher one, and the log tells you which. [MCP audit logging](https://mcp1.com/blog/mcp-audit-logging) covers what else to keep for each call.

## Rate limits in MCP1

MCP1 is a gateway, so the limit applies to every call through it, from every client and to every server, including hosted ones like [GitHub](https://mcp1.com/servers/github) and [Notion](https://mcp1.com/servers/notion). Each person gets a number of calls per minute across the workspace, 120 by default. Admins change it under Settings, General, or set `0` to turn it off. It is also part of the workspace policy file:

policy.yaml

```
version: 1
settings:
  rateLimitPerMinute: 120
```

Every call counts, whether it was allowed, blocked by a rule or one of MCP1’s own tools. Over the limit, the agent gets a tool error that names the limit and asks it to try again shortly, and the refusal is recorded in the audit log as denied with “Rate limit exceeded”, under the person’s name and client. The [docs](https://mcp1.com/docs) cover the other limits, and the Individual plan is free to [start with](https://mcp1.com/signup).

## Common questions

### Does the MCP spec define rate limits?

No. It leaves limits to servers and the services behind them. It does say tool execution errors belong in the result with isError, which is how a limit should reach the model.

### Should a rate-limited MCP call return HTTP 429?

Return a tool result with isError: true and a message stating the limit. A 429 or protocol error tends to reach the client, not the model, so the agent can’t adjust.

### Can Cursor or VS Code rate limit MCP tools?

Neither has a rate limit setting. Approvals slow writes down, but read calls run freely, so put the limit on the server or a gateway.

### What does MCP1 limit by default?

120 calls per person per minute across the workspace, counting allowed and blocked calls. Admins change it in Settings or set 0 to turn it off.

Give your team one URL

Create a workspace, install your servers and share a gateway with a group. Free for individuals.

[Start with MCP1](https://mcp1.com/signup)[Read the docs](https://mcp1.com/docs)

## More from the blog

[ Terminal$ claude mcp add --transport http github api.githubcopilot.com/mcp/githubConnectedHow to connect GitHub MCP to Claude CodeRun claude mcp add with https://api.githubcopilot.com/mcp/ and a fine-grained token. Read-only mode, toolsets, permission rules and team setup.![](https://avatars.githubusercontent.com/u/1297371?s=96&v=4)Eldad FuxFounder and CEO, Appwrite](https://mcp1.com/blog/github-mcp-claude-code)[ SupportIntercomRead-onlyLinearRead-onlyNotionRead-onlyStripeRead-onlyMCP servers for support teams: what to connect firstStart with your helpdesk, Linear, Notion and Stripe, read-only first. What they answer together, which writes to hold back and a shared setup.![](https://avatars.githubusercontent.com/u/1297371?s=96&v=4)Eldad FuxFounder and CEO, Appwrite](https://mcp1.com/blog/mcp-servers-for-support-teams)

---

This is the markdown copy of https://mcp1.com/blog/rate-limit-mcp-tool-calls. Site index for agents: https://mcp1.com/llms.txt
