Skip to main content
Header forwarding passes specific headers from agent requests through to MCP servers. Use for distributed tracing, tenant context, or custom metadata that needs to reach the upstream server. You can also rename headers inline using object entries, so client-side header names can differ from what the upstream server expects.

When to Use

Your agent includes headers with context that the MCP server needs. Maybe a trace ID for distributed tracing. Maybe a tenant ID for multi-tenant servers. Maybe custom metadata your server expects. Without header forwarding, these headers stop at Portkey. With it, they pass through to the MCP server. Common scenarios:
  • Distributed tracing. Forward x-request-id, x-trace-id, x-correlation-id to correlate logs across services.
  • Multi-tenancy. Forward x-tenant-id, x-org-id for tenant-scoped operations.
  • User context. Forward x-user-id, x-user-role for upstream authorization.
  • Custom metadata. Forward application-specific headers your MCP server expects.

Configuration

Configure forward_headers when adding or editing an MCP server in the MCP Registry.

Shorthand (string array)

Forward only the headers you specify. No renaming support in this form:
Other headers from the agent request are dropped.

Allowlist mode

The same behavior with explicit configuration. Entries in the headers array can be:
  • A string — forwards the header as-is.
  • An object { "from": "<client_header>", "to": "<upstream_header>" } — forwards the header with its name changed.
In this example, x-trace-id is forwarded as-is, x-tenant-id arrives at the upstream as X-Organization-Id, and x-env arrives as X-Deploy-Environment.

All-except mode

Forward everything except headers you exclude. String entries are excluded; object entries rename forwarded headers:
Here, host and connection are excluded. All other headers are forwarded. Additionally, x-tenant-id is renamed to X-Org-Id before reaching the upstream server.
Use all-except mode carefully. It forwards more headers than you might expect, which could leak information or cause conflicts. Prefer explicit allowlists when possible.

Security

Protected Headers

These headers are never forwarded regardless of your configuration: In all-except mode, these are automatically added to the blocklist. You cannot override this behavior.

Header mapping validation

When using object entries for header renaming, both the source (from) and target (to) header names are validated against the protected headers blocklist. If either name is protected, the mapping is rejected and the header is not forwarded. Header matching on the source name is case-insensitive.

Identity Headers Are Protected

If you use Identity Forwarding, identity headers are also protected:
  • X-User-Claims
  • X-User-JWT
This prevents clients from spoofing user identity by sending fake identity headers.

Header Priority

When multiple sources provide headers, they merge in this order (later values override earlier ones): Why this order matters:
  • Authentication headers configured on the server cannot be overridden by agents
  • Static passthrough headers take precedence over agent headers
  • Identity headers always win—agents cannot spoof user identity
Example:
Result: MCP server receives X-Custom: server-value (server config wins).

Agent Configuration

Include headers in your MCP client configuration:
Or set headers per request in code:

Example: Distributed Tracing

You want to correlate MCP requests with your application’s traces. Server configuration:
Agent request:
MCP server receives:
Now your MCP server logs include the same trace IDs as your application.

Example: Multi-Tenant Server

Your internal MCP server needs tenant context to scope data access. Server configuration:
Agent request:
MCP server receives:
Your server uses these headers to filter data to the correct tenant.

Example: Header renaming

Your agent sends x-tenant-id but your upstream MCP server expects X-Organization-Id. Server configuration:
Agent request:
MCP server receives:
The x-tenant-id header is renamed to X-Organization-Id before reaching the upstream server.

Combining with Identity Forwarding

Header forwarding and identity forwarding serve different purposes: Use both together:
The MCP server receives:
  • x-request-id and x-trace-id from the agent (for tracing)
  • X-User-Claims from Portkey (for user identity)

Last modified on April 16, 2026