← Back to Insights
ORIGINAL

Don't Put Secrets in MCP Headers — Why Mcp-Method Routing Creates a New Leak Path

MCP 2026-07-28 added header-based routing so gateways can meter on Mcp-Method and Mcp-Name without parsing JSON. That is an ops win — and a logging footgun if teams map tokens or tenant IDs into headers.

HTTP gateway routing MCP headers while a secret token leaks into access logs

One of the best ops upgrades in MCP spec 2026-07-28 is also one of the easiest ways to leak credentials: header-based routing.

Streamable HTTP requests now carry Mcp-Method and Mcp-Name so your gateway, WAF, or rate limiter can route and meter without parsing JSON bodies. That is exactly what platform teams asked for when MCP moved stateless and started behaving like ordinary HTTPS traffic.

The failure mode is predictable: someone maps a bearer token, tenant slug, API key fragment, or session cookie into a custom MCP header “for routing convenience.” Proxies log headers by default. SIEMs ingest them. Support engineers grep them. Your secret is now inventory, not authentication.

This article is the security follow-up we teased in what to rip out before the deprecation clock hits — what belongs in headers, what never does, and how to harden gateways without breaking the spec.

What changed in the spec

Before 2026-07-28, much of MCP’s routing context lived inside JSON-RPC bodies and session state. After the stateless core:

That design is intentional. It lets you write rules like:

Good for reliability. Dangerous if “routing metadata” becomes a second place to stash secrets.

The anti-pattern: headers as a secret channel

Teams reach for this when auth feels awkward in JSON or when a gateway vendor says “we can only route on headers.” Common mistakes:

Anti-patternWhy it leaks
Copy Authorization: Bearer … into X-Api-Key or a custom MCP header for routingDuplicate secret surfaces; many proxies log non-standard headers
Put tenant/user IDs that double as capability tokens in headersLog aggregation treats them as low-sensitivity — they are not
Map OAuth access tokens into parameter headers for “edge auth”Tokens outlive the request in log retention policies
Debug middleware that prints all incoming headers in productionOne verbose flag away from a credential spill

If your access log line includes the full header set, assume every value in that line will eventually be copied into a ticket, a Slack thread, or a vendor support bundle.

What belongs where

Use this split when you design remote MCP hosting:

OAuth scope design still matters — headers do not replace the permission model in OAuth and the over-permission trap. They just give you a new place to get sloppy.

Gateway and logging checklist

Run this before you expose a remote MCP server to Claude, ChatGPT, or org-wide Cursor configs:

  1. Log redaction — redact Authorization, Cookie, and any custom auth headers at the load balancer / CDN / API gateway.
  2. Allowlist header logging — log Mcp-Method, Mcp-Name, request ID, status, latency — not “all headers.”
  3. Separate routing keys from auth keys — if you route by tenant, use an opaque public tenant ID; resolve to credentials server-side.
  4. Reject header/body mismatches — if Mcp-Name says delete_repo but the body targets a different tool, fail closed (some gateways can enforce this).
  5. Retention — shorter retention on edge logs than on audit tables; tokens should not live in S3 for 90 days because “debugging was hard.”
  6. Alert on verbose modes — treat “log full request headers” flags like production firewall disables.

Pair this with allowlists and IdP-managed auth from AI agent tool access as an operating control and enterprise-managed MCP auth — headers are transport hygiene; governance is still who may connect which server.

Builder guidance: safe edge routing patterns

Pattern A — method/name only

Route on Mcp-Method + Mcp-Name alone. Keep auth in Authorization. Simplest and spec-aligned.

Pattern B — public routing labels

Add a non-secret header like X-Mcp-Pool: read-only set by your gateway after token introspection — not by the client. The client never supplies the pool name; the gateway derives it from token claims.

Pattern C — body stays authoritative

Use headers for coarse throttles only. The MCP server still validates tool name and args from the body. Headers are hints, not authority.

Avoid Pattern D — client-supplied secret headers. If the agent or connector can set it, it is not a security boundary.

What security reviewers should ask

Add these to the seven-question MCP audit for any remote server handling sensitive data:

Quick answers

Are Mcp-Method and Mcp-Name secret?

No. Treat them like HTTP path segments — useful for routing, safe to log.

Can we put a hashed token in a header?

Still avoid it. Hashes of secrets still aid offline attacks and correlate users in logs. Route on opaque non-secret IDs instead.

Does this apply to local stdio MCP?

Mostly no — this is a remote HTTP + gateway problem. Local stdio still has PAT-in-config debt; see demoware vs production-ready.

Where is the spec background?

MCP 2026-07-28 announcement and your rip-out checklist: deprecation clock.

Final thought

Header-based routing is a maturity feature. It means MCP is serious about running behind the same infrastructure as the rest of your APIs.

Do not repay that maturity by piping secrets through headers because it was convenient on a Tuesday.

Route on method and tool name. Authenticate in Authorization. Redact everything else. Then run the audit — before the logs become the breach.

GET PRACTICAL AI PLAYBOOKS WEEKLY

One clear email each Thursday

Actionable frameworks on AI execution, agents, and MCP. Join 4,200+ builders.

✓ You're in — first briefing Thursday.

Leave a comment

Be the first to share your thoughts.

Related insights

2026-08-22
Claude Code CLI vs Desktop Connectors — When to Use `claude mcp add` vs Web Connectors
Claude ships two MCP attach paths: web connectors in Desktop (cloud → your HTTPS URL) and CLI registration via `claude mcp add`. Here is a decision guide, command cheat sheet, and fallback plan when transport flags differ across CLI versions.
2026-08-22
.cursor/mcp.json Is Becoming Team Policy — The New Perimeter for Which Tools Your Repo Allows
Shared MCP config in git is replacing ad-hoc connector sprawl. Project-level .cursor/mcp.json is how teams declare which agent tools are in-bounds for a repo — and what stays in personal config with secrets.
2026-08-22
Discovery MCP Is the New App Store Search — Why Agents Find Integrations by Capability, Not Brand
Humans browse MCP directories like an app store. Agents search by capability — scrape to markdown, Postgres, create_issue. Discovery MCP turns the catalog into a tool your assistant can call. Here is what that shift means for server authors and team allowlists.