Skip to main content

Connect a standard MCP client with OAuth

Goal: let an off-the-shelf MCP client (one that follows the MCP 2026-07-28 authorization spec) call tools through the Agentic Auth connector proxy, with the user signing in at your identity provider, and no Agentic Auth code in the client.

Available from authzai 0.4.0

Every setting on this page is off by default. With them off, the proxy behaves as before.

How it fits together​

Your IdP stays the authorization server. Agentic Auth never runs a login page, an authorization endpoint or client registration: the client and your IdP do those, with PKCE, exactly as they would for any OAuth-protected MCP server.

  1. The client calls the proxy with no token and gets 401 with a WWW-Authenticate header pointing at the proxy's Protected Resource Metadata.
  2. That metadata names your IdP. The client signs the user in there and gets an access token issued for the proxy.
  3. The proxy validates the token itself: signature, issuer, audience, expiry and signing algorithm. A bad token stops here, before any policy decision.
  4. On the first call with a token, the proxy starts a session through consent. The control plane verifies the token again and roots the session at the verified user.
  5. Every tool call then gets the usual per-call decision. The upstream tool receives a narrowed hop token, never the client's token.

1. Register the client at your IdP​

Register the MCP client as an OAuth client at your IdP, the way you would for any public client that uses the authorization code flow with PKCE. Make sure that:

  • access tokens can be issued for the proxy's public URL as their audience (RFC 8707 resource indicators), for example https://mcp-proxy.example.com;
  • tokens carry the client's identifier in azp (or client_id);
  • tokens are signed with an asymmetric algorithm, by default RS256, ES256 or EdDSA.

Note the client ID. You map it to an agent in step 3.

On the control plane:

AGENTIC_AUTH_PRINCIPAL_IDP_ISSUER=https://idp.example.com
AGENTIC_AUTH_PRINCIPAL_IDP_JWKS_URL=https://idp.example.com/.well-known/jwks.json
AGENTIC_AUTH_VERIFIED_CONSENT_ENABLED=true
AGENTIC_AUTH_CLIENT_MAPPING_ENABLED=true
# The audiences consent accepts: the proxy's URL, since the proxy relays the user's token.
AGENTIC_AUTH_CONSENT_IDP_AUDIENCES=https://mcp-proxy.example.com
# What the proxy holds to call consent. Never give a proxy the admin token.
AGENTIC_AUTH_CONSENT_TOKEN=<a long random secret>

The control plane refuses to start if verified consent is on without the IdP settings, or client mapping is on without verified consent.

3. Map the client to an agent​

An IdP client is identified, not authorized. It acts as a registered agent only when an admin says so, and its sessions then run in that agent's scope:

curl -X POST https://authz.example.com/v1/agents/$AGENT_ID/clients \
-H "Authorization: Bearer $ADMIN_TOKEN" \
-d '{"client_id": "desktop-client"}'

A client with no mapping, or one mapped to an agent with no pinned manifest, is refused with CLIENT_NOT_AUTHORIZED and next: cold_start. Agentic Auth never creates an agent for an unknown client. To give a new agent its first manifest, see onboard an agent with no manifest.

One client maps to one agent. One agent may have several clients, such as a desktop app and a CLI.

4. Configure the proxy as a protected resource​

AGENTIC_AUTH_GATEWAY_OAUTH_RESOURCE_ENABLED=true
AGENTIC_AUTH_GATEWAY_RESOURCE_URL=https://mcp-proxy.example.com
AGENTIC_AUTH_GATEWAY_IDP_ISSUER=https://idp.example.com
AGENTIC_AUTH_GATEWAY_CONSENT_TOKEN=<the control plane's CONSENT_TOKEN>
# Leave CONSENT_SCOPE unset: the client mapping chooses the scope.
agentic-auth-boundary mcp-proxy proxy.yaml

The proxy fetches your IdP's keys before it starts serving (from IDP_JWKS_URL, or from the IdP's discovery document), and refuses to start if it cannot. It also refuses to start with observe mode on: observe mode forwards calls it would have denied, and the only token it could forward is the client's.

The same settings make the gateway a protected resource.

5. Check it​

curl -si -X POST https://mcp-proxy.example.com/mcp \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"search"}}'
# HTTP/1.1 401 Unauthorized
# www-authenticate: Bearer resource_metadata="https://mcp-proxy.example.com/.well-known/oauth-protected-resource", scope="kb.public"

curl -s https://mcp-proxy.example.com/.well-known/oauth-protected-resource
# {"resource": "https://mcp-proxy.example.com",
# "authorization_servers": ["https://idp.example.com"],
# "scopes_supported": ["kb.public"], ...}

Then point your MCP client at https://mcp-proxy.example.com/mcp and sign in. After a call, query its delegation chain: the root shows the user as https://idp.example.com#<sub>, principal_source: verified, and the client ID.

To see the whole flow without an IdP, run examples/mcp-oauth/run_local.py in the public repository.

What gets refused, and where​

SituationAnswer
No token401 with the challenge above
Bad signature, wrong issuer, wrong audience, expired, or a disallowed algorithm401, error="invalid_token", and which check failed. No policy decision is made
Token in the query string400, error="invalid_request"
The token's scope claim lacks the tool's data class403, error="insufficient_scope"
Your IdP's keys unreachable, none cached503, retryable. Never an allow
Client not mapped, or its agent has no pinned manifestCLIENT_NOT_AUTHORIZED, next: cold_start
The manifest does not allow the toolThe usual policy refusal, such as OUT_OF_SCOPE

Refusals before a session exists have no audit row, because there is no session to attach one to. They are recorded in the edge trace and metrics, and logged with a token fingerprint, never the token.

Removing a mapping, and stopping a client now​

Removing a mapping (DELETE /v1/agents/$AGENT_ID/clients/desktop-client) stops new sessions. It does not end sessions already running: they expire within SESSION_TTL_SECONDS. To stop a client immediately, revoke its agent.

You can run the proxy as a protected resource while the control plane still has verified consent off, by setting AGENTIC_AUTH_GATEWAY_ASSERTED_ROOT_SCOPE on the proxy. The proxy then tells consent who the user is instead of letting consent check, so sessions are recorded as asserted and refusals say root_of_authority: asserted. In this mode the consent token can start a session for any user, so treat it as a step on the way to verified consent, not a place to stay.

Optional: publish the control plane's authorization server metadata​

AGENTIC_AUTH_AS_METADATA_ENABLED=true serves /.well-known/oauth-authorization-server: token exchange, keys and consent, and no authorization or registration endpoint. Registration also checks each MCP server's own authorization server and rejects a declared data class that server does not issue. It needs AGENTIC_AUTH_ISSUER to be an https URL, which changes iss in new tokens, so update any offline verifier pinned to the old issuer first.