Configure a WAF for MCP traffic
- Applies to
- Gatewayruntime for API, AI, and MCP gateways
- Hosting
- Managed EdgeManaged DedicatedSelf-Hosted
A web application firewall (WAF) tuned for browser traffic often blocks
legitimate Model Context Protocol (MCP) requests. MCP clients aren't browsers.
They send JSON-RPC messages in POST bodies that carry whatever text a user or
model puts in a tool call, they can't solve a JavaScript challenge or a CAPTCHA,
and AI platforms send their requests from shared cloud addresses. Default WAF
rules read each of those traits as a sign of an attack.
This page explains where a WAF can break MCP traffic, how to recognize a WAF
block, and how to add exceptions that keep the WAF on for everything else. The
guidance applies to routes that use the MCP Gateway's
McpProxyHandler and to routes that use
the MCP Server handler.
Where a WAF sits
A WAF can block MCP traffic in two places:
- In front of your gateway. You proxy your custom domain through a WAF such as Cloudflare, Akamai, or AWS WAF with CloudFront. Requests from MCP clients pass through the WAF before they reach Zuplo. See Zuplo + WAF/DDoS Services for how each WAF connects to Zuplo.
- In front of an upstream MCP server. The MCP server that a gateway route proxies to sits behind its own WAF, for example an Application Load Balancer with AWS WAF. Requests from Zuplo pass through that WAF before they reach the server.
The same rules cause trouble in both places, but the fix for the second one also involves proving that a request came from your gateway. See Protect an upstream MCP server behind a WAF.
Recognize a WAF block
A WAF block rarely looks like a WAF block from inside an MCP client. Look for these signs:
- The client reports a connection failure, an unexpected content type, or a JSON
parse error, and the raw response is an HTML page with a
403or503status instead of a JSON-RPC message. - The server works when you call it with
curlfrom your own machine, but fails from a hosted AI platform such as ChatGPT or Claude. - Sign-in fails before the client ever calls a tool, because the client can't read the OAuth metadata documents.
- Some tool calls fail and others succeed, depending on what the arguments contain. For example, a call that passes a SQL query or a code snippet fails, and a call that passes a plain search term works.
- The request never appears in your Zuplo logs. When the WAF in front of the gateway blocks a request, the gateway never sees it.
To confirm, search the WAF's event log (Security Events in Cloudflare, sampled requests or WAF logs in AWS) for the MCP route's path. The log entry names the rule that matched.
What blocks MCP traffic
| WAF feature | Why it blocks MCP traffic |
|---|---|
| Bot management and challenges | Challenges, CAPTCHAs, and bot scores assume a browser. An MCP client can't run a JavaScript challenge, so it receives an HTML challenge page. Settings that block AI bots can also block AI platforms by design. |
| Managed rulesets (OWASP, SQL injection, XSS, RCE) | Tool arguments and results often contain SQL, shell commands, HTML, file paths, or source code. Signature rules match that text even though the request is legitimate. |
| Request body size limits | A tools/call request with a long prompt, a document, or a large argument object exceeds limits such as the 8 KB body rule in the AWS managed core rule set. |
| User-Agent rules | Server-to-server requests often carry a library's User-Agent or none at all. Rules that block a missing or non-browser User-Agent, such as NoUserAgent_HEADER in AWS, match them. |
| Per-IP rate limits and IP reputation | A hosted AI platform sends requests for many users from a small set of cloud addresses, and so does your gateway when it calls an upstream. One busy tenant can push everyone over a per-IP limit. |
| Geographic or hosting-provider blocks | Requests from AI platforms come from cloud data centers, which some rules treat as suspicious or place in an unexpected country. |
| Method and content-type rules | MCP requests are POST with Content-Type: application/json and Accept: application/json, text/event-stream. Responses can be text/event-stream. Rules that allow only typical form or page traffic fail. |
| Proxy timeouts and response buffering | A slow tool call can exceed a proxy's response timeout, and a proxy that buffers responses delays or breaks streamed results. |
| Rules that require credentials on every request | OAuth discovery and sign-in requests carry no bearer token. A rule that requires an Authorization header blocks sign-in before the client gets a token. |
Add narrow exceptions
Turning the WAF off for your whole domain fixes MCP traffic, but it also removes protection from everything else. Instead, follow these principles:
-
Scope each exception to MCP paths. Match the hostname and the path prefix of your MCP routes, such as
/mcp/, and thePOSTmethod. Leave every other path under the full rule set. -
Skip individual rules, not whole rulesets. Use the WAF event log to find the specific rules that match MCP requests, and skip or relax only those.
-
Log before you block, and keep logging. Switch a rule to log-only (Log in Cloudflare, Count in AWS WAF) on MCP paths, watch the results, and keep logging turned on for your exceptions so you can still see what they let through.
-
Replace challenges with authentication. MCP routes already authenticate every request with an MCP OAuth policy, so a browser challenge adds nothing there. Turn challenges off on MCP paths and rely on the token instead.
-
Rate limit by user, not by IP address. Apply Zuplo rate limiting per authenticated user so that users who share an AI platform's addresses don't share a limit. Keep a WAF rate limit only as a high ceiling against floods.
-
Keep OAuth discovery and sign-in reachable. MCP clients fetch these paths without a token, and some of them from a browser:
/.well-known/oauth-protected-resource/*/.well-known/oauth-authorization-serverand/.well-known/oauth-authorization-server/*/__zuplo/oauth/*(or your configuredbasePath)/__zuplo/auth/connections/*, if a route uses upstream OAuth
See the MCP Gateway reference for the full list of endpoints the gateway serves.
An exception exempts requests from the rules it skips, so anyone can send a request that matches it. Keep the exception as narrow as the traffic allows, and make sure the route itself enforces authentication.
If your WAF or CDN sits in front of a custom domain, it must also forward the
original Host header or set X-Forwarded-Host, or the gateway advertises the
wrong issuer. See
Custom domain → wrong issuer in AS metadata.
Cloudflare
Cloudflare evaluates WAF custom rules before managed rules, so a custom rule with the Skip action can exempt MCP traffic from specific managed rules, rate limiting rules, or Super Bot Fight Mode.
-
In the Cloudflare dashboard, open Security → Events for your zone and filter by your MCP path. Note the service and the rule ID of each blocked request.
-
Open Security → Security rules (Security → WAF on older dashboards) and create a custom rule. Use an expression that matches only your MCP routes:
Code -
Set the action to Skip and select only what the events showed: specific managed rules, rate limiting rules, or Super Bot Fight Mode. Turn on Log matching requests.
-
Add a second rule with the same steps for the OAuth discovery and sign-in paths, if any rule blocks them:
Code -
Deploy the rules and repeat the failing request. Confirm in Security → Events that the request now matches your skip rule.
A few Cloudflare settings need attention outside custom rules:
- Bot Fight Mode (Free plan) applies to the whole zone and a skip rule can't bypass it. If it challenges MCP clients, turn it off or upgrade to a plan with Super Bot Fight Mode, which a skip rule can bypass.
- AI bot blocking blocks requests from AI services. If you turned it on, confirm that it doesn't block the AI platforms your users connect from.
- Challenge rules (Managed Challenge, JS Challenge, or Interactive Challenge) never succeed for an MCP client. Exclude MCP paths from them.
- Proxy read timeout. Cloudflare closes a proxied connection if the origin sends nothing for 100 seconds. Keep slow tool calls under that limit, or stream progress from the server.
AWS WAF
The AWS managed core rule set (AWSManagedRulesCommonRuleSet) contains the two
rules that most often block MCP traffic: SizeRestrictions_BODY, which blocks
request bodies larger than 8 KB, and NoUserAgent_HEADER, which blocks requests
without a User-Agent.
- Open the web ACL's sampled requests or WAF logs and filter by your MCP path to find the matching rules.
- In the managed rule group, override the action of each matching rule to Count. Count keeps the rule visible in metrics and logs without blocking.
- To keep blocking on other paths, add a custom rule after the managed rule
group that blocks requests carrying the rule's label (for example
awswaf:managed:aws:core-rule-set:SizeRestrictions_Body) unless the path starts with your MCP prefix.
Apply the same approach to other managed rule groups, such as the SQL database or known bad inputs rule sets, if their rules match tool arguments. Set the limit of any rate-based rule with shared AI platform addresses in mind.
Other WAFs
Akamai, Fastly, Azure Front Door, and other WAFs use the same building blocks under different names: a match condition on hostname and path, a per-rule exception or log-only mode, and bot management settings. Apply the principles above with your provider's tools. For setup details, see Akamai, Fastly, and AWS WAF and Shield.
Protect an upstream MCP server behind a WAF
When the upstream MCP server sits behind a WAF, the WAF sees requests from your gateway, not from the original MCP client. Apply the same exceptions to the upstream's MCP path, and then lock that path down so that only your gateway can use it.
On Managed Edge, requests to the upstream come from many edge locations, so an IP allowlist isn't practical. Use a shared secret header instead:
-
Store a random value in an environment variable marked as a secret, for example
UPSTREAM_ORIGIN_SECRET. -
Add a
set-headers-inboundpolicy to the MCP route that sets the secret on every request to the upstream:config/policies.json -
In the upstream's WAF, block requests to the MCP path unless the header matches the secret. Redact the header from the WAF's logs.
Use a header other than Authorization for the secret. When a route uses
upstream OAuth, the gateway sends the upstream
access token in Authorization. If the upstream runs its own OAuth server,
leave its discovery and sign-in paths public, because users' browsers reach them
directly.
For other ways to restrict an upstream to your gateway, such as mTLS or a secure tunnel, see Securing your backend. Managed Dedicated deployments can also use custom networking for private connectivity.
Verify the fix
Send an initialize request through the WAF with the headers an MCP client
sends:
Code
A route protected by an MCP OAuth policy answers with 401 and a
WWW-Authenticate: Bearer header. That response came from Zuplo, so the WAF let
the request through. A 403 or 503 with an HTML body means the WAF still
blocks the request. Repeat the test with a large or code-heavy request body to
check the managed rules, and then connect a real client from the AI platform
your users rely on.