Skip to main content
The mcpAuthentication policy validates incoming Bearer tokens from MCP clients against a configured OAuth 2.0 / OIDC authorization server. When enabled, Agentgateway enforces token validity before allowing any MCP traffic and optionally serves OAuth 2.0 Protected Resource Metadata at /.well-known/oauth-protected-resource/<path>.

Configuration location

mcpAuthentication is set under binds[].listeners[].routes[].policies:

Fields

string
required
The expected iss (issuer) claim in the JWT. Must exactly match the issuer URL of your authorization server.
string[]
required
A list of accepted aud (audience) values. The token must contain at least one of these values.
object
required
Source of the JSON Web Key Set (JWKS) used to verify token signatures. Exactly one of file or url must be set.
string
Token enforcement mode. When set to strict, Agentgateway rejects requests that do not carry a valid Bearer token. When omitted or set to a permissive value, tokens are validated when present but not required.
object
Optional provider hint for non-spec-compliant authorization servers. When set, Agentgateway activates a compatibility adapter that adjusts /.well-known/oauth-authorization-server responses. Exactly one of auth0 or keycloak must be specified.
object
Configures the OAuth 2.0 Protected Resource Metadata document served at /.well-known/oauth-protected-resource/<path>. MCP clients use this to discover the correct authorization server.
object
Fine-grained control over which RFC 7519 registered claims must be present in the token before validation proceeds.

Examples

When resourceMetadata is configured, Agentgateway automatically registers /.well-known/oauth-protected-resource/<path> and /.well-known/oauth-authorization-server/<path> endpoints. Include these paths in your route matches so the gateway serves them correctly.
The exp claim is always checked when it is present in a token, regardless of whether requiredClaims includes "exp". Including "exp" in requiredClaims only means the token will be rejected if the claim is absent, not that expiry checking is added.

jwtAuth

The jwtAuth policy provides generic JWT validation for any route — not limited to MCP. Unlike mcpAuthentication, it does not expose OAuth resource metadata endpoints. Use it for standard API authentication and as the authentication layer alongside mcpAuthorization. Configuration location: binds[].listeners[].routes[].policies.jwtAuth The policy supports two forms:

Fields

string
Enforcement mode. When set to strict, requests without a valid token are rejected.
string
Expected iss claim. Used in the single-provider shorthand form.
string[]
Accepted aud claim values. Used in the single-provider shorthand form.
object
JWKS source. One of file (path on disk, relative to binary working directory) or url (HTTP endpoint).
object[]
List of JWT providers for multi-provider configurations. Each provider has issuer, audiences, jwks, and jwtValidationOptions fields identical to the single-provider shorthand.
string[]
default:"[\"exp\"]"
Claims that must be present in the token. Recognized values: exp, nbf, aud, iss, sub. Defaults to ["exp"].
Once a JWT is validated, its claims are available as jwt.<claim> in CEL expressions used by mcpAuthorization and authorization policies.

apiKey

The apiKey policy authenticates requests using static API keys passed in the Authorization: Bearer header or x-api-key header. Configuration location: binds[].listeners[].routes[].policies.apiKey

Fields

object[]
required
List of valid API keys.
string
Enforcement mode. When set to strict, requests without a valid key are rejected.
API key metadata is available in CEL as apiKey.key and any custom metadata fields under apiKey.<field>.

basicAuth

The basicAuth policy authenticates requests using HTTP Basic Authentication validated against an htpasswd file. Configuration location: binds[].listeners[].routes[].policies.basicAuth

Fields

object
required
Source of the htpasswd credentials.
string
Realm name sent in the WWW-Authenticate header when authentication fails.
string
Enforcement mode. When set to strict, unauthenticated requests are rejected with 401.
Authenticated credentials are available in CEL as basicAuth.username.