When to Use
MCP servers often need to know who is making requests—for access controls based on user roles, audit logging, or personalized responses. Without identity forwarding, the MCP server sees requests coming from Portkey, not from individual users. Identity forwarding bridges that gap. Common scenarios:- Audit logging. MCP server logs user identity for compliance
- Authorization. MCP server enforces per-user permissions
- Multi-tenancy. MCP server scopes data by user or organization
- Analytics. Track usage patterns by user or team
- Personalization. Customize responses based on user context
How It Works
Forwarding Methods
Claims Header
Send user claims as a JSON header. Simple to parse, no cryptographic verification needed.- Python
- TypeScript
Bearer Token Passthrough
Forward the original access token unchanged.Signed JWT
Portkey generates a new JWT containing user claims, signed with Portkey’s private key.- User claims (filtered by
include_claims) iss:"portkey-mcp-gateway"iat: Issued at timestampexp: Expiration timestamp
Configuration Options
| Field | Type | Default | Description |
|---|---|---|---|
method | string | Required | "claims_header", "bearer", or "jwt_header" |
include_claims | string[] | See below | Claims to include |
header_name | string | Method-specific | Custom header name |
jwt_expiry_seconds | number | 300 | JWT expiry (only for jwt_header) |
Default Header Names
| Method | Default Header |
|---|---|
claims_header | X-User-Claims |
bearer | Authorization |
jwt_header | X-User-JWT |
Default Claims
If you don’t specifyinclude_claims, Portkey includes:
| Claim | Description |
|---|---|
sub | Subject (user identifier) |
email | User’s email address |
username | Username |
user_id | Portkey user ID |
workspace_id | Workspace identifier |
organisation_id | Organization identifier |
scope | OAuth scopes |
client_id | OAuth client ID |
include_claims to add or restrict which claims are forwarded.
Verifying Signed JWTs
Forjwt_header, MCP servers verify tokens using Portkey’s public keys.
Fetch Public Keys
Verify in Your MCP Server
Standard JWT libraries fetch and cache these keys automatically:- Python
- TypeScript
Security
Identity Headers Are Protected
Portkey adds identity headers (X-User-Claims, X-User-JWT) to the protected headers list. This means:
- Clients cannot spoof identity. If an agent sends a fake
X-User-Claimsheader, it’s stripped before processing. - Identity headers have highest priority. They override any other headers with the same name.
- Header forwarding cannot bypass this. Even with
forward_headers: { mode: "all-except", headers: [] }, identity headers from clients are blocked.
JWT Security Properties
Signed JWTs provide:- Integrity: Claims cannot be modified without invalidating the signature
- Authenticity: Only Portkey can sign with its private key
- Expiry: Short-lived tokens (default 5 minutes) limit replay window
Performance
JWT Caching
Signing JWTs involves expensive cryptographic operations. Portkey caches signed JWTs to avoid this overhead:| Scenario | Latency |
|---|---|
| Cache hit | ~0.01ms |
| Cache miss (signing) | ~1ms |
- Max 10,000 cached entries
- LRU eviction when full
- Cache key includes user identity and included claims
- Cache entries expire with the JWT
JWKS Caching on MCP Server
Cache Portkey’s JWKS on the MCP server. Most JWT libraries handle this automatically with configurable TTL.Self-Hosted Setup
Self-hosted Portkey deployments usingjwt_header require a signing key.
Generate Key Pair
Configure Environment
/.well-known/jwks.json for MCP servers to verify.
Examples
Basic Claims Forwarding
Forward essential identity for logging:Signed JWT with Custom Expiry
MCP servers needing cryptographic verification with longer validity:Combined with External OAuth
Authenticate via IdP and forward validated claims to MCP servers:- User authenticates with your IdP, gets token
- User sends request to Portkey with IdP token
- Portkey validates token against your IdP
- Portkey extracts claims and forwards to MCP server
- MCP server uses claims for authorization
Use Case: Per-User Authorization
An MCP server exposes project management tools. Users should only access their own projects. Configuration:Use Case: Audit Logging
Log every tool call with user identity: Configuration:Related
| Topic | Description |
|---|---|
| External OAuth | Use your own IdP for gateway authentication |
| JWT Validation | Validate tokens from external IdPs |
| Forwarding Headers | Pass request headers to MCP servers |

