Prerequisites: You should have a working FrontMCP server with at least one tool. See Your First Tool if you need to get started.
What You’ll Build
By the end of this guide, your server will have:- Per-user rate limiting on tools
- Concurrency control to prevent resource exhaustion
- Execution timeouts to catch hanging requests
- IP filtering for production security
- Redis-backed distributed rate limiting
Step 1: Add Rate Limiting to a Tool
1
Configure rate limiting on a tool
Add a This limits each user to 30 search requests per minute.
rateLimit option to your tool decorator:2
Register the tool and enable guard
Enable the guard system in your app configuration:
3
Test the rate limit
Start your server and send rapid requests. After 30 requests within a minute, the server returns a
429 error:Step 2: Add Concurrency Control
Prevent expensive tools from running too many instances simultaneously.1
Add concurrency to a tool
2
Understand queue behavior
When all slots are occupied:
- With
queueTimeoutMs: 0(default), the request is immediately rejected withConcurrencyLimitError(429). - With
queueTimeoutMs: 15_000, the request waits up to 15 seconds. If a slot opens, it proceeds. If not, it fails withQueueTimeoutError(429).
maxConcurrent: 1:Step 3: Add Execution Timeout
Protect against hanging requests by setting a maximum execution time.1
Add timeout to a tool
ExecutionTimeoutError (408).2
Set a default timeout for all tools
Instead of adding Tools with their own
timeout to every tool, set a default at the app level:timeout override the default. Tools without timeout use the app default.Step 4: Global Rate Limiting
Add a server-wide rate limit that applies to all requests, regardless of which tool is called.1
Configure global limits
2
Combine with per-tool limits
Global and per-tool limits work independently. A tool can have its own stricter limit:Even if the global limit allows 500 requests/min per IP, this tool is limited to 5 requests/min per user.
Step 5: IP Filtering
Block malicious IPs and restrict access to known networks.1
Configure IP filtering
2
Understand filter precedence
The deny list is always checked first:
- IP on deny list → blocked (403,
IpBlockedError) - IP on allow list → allowed
- IP on neither list →
defaultActionapplies ('allow'or'deny')
defaultAction: 'deny', only IPs explicitly on the allow list can access your server.3
Enable proxy trust
If your server is behind a load balancer or reverse proxy, the client IP will be the proxy’s IP unless you enable
trustProxy:Step 6: Production Setup with Redis
In-memory storage works for development but does not persist across restarts or share state between server instances. Use Redis for production.1
Configure Redis storage
2
Verify distributed behavior
With Redis storage:
- Rate limit counters are shared across instances — a user hitting different instances still sees a single limit.
- Semaphore tickets use atomic operations — concurrency is enforced globally.
- Pub/sub notifications make semaphore slot release detection near-instant.