mcp-auth-proxy icon indicating copy to clipboard operation
mcp-auth-proxy copied to clipboard

feat request: Support OAuth 2.0 Client Credentials flow for machine-to-machine MCP clients

Open antigenius0910 opened this issue 6 months ago • 2 comments

Problem

mcp-auth-proxy currently only supports the authorization_code + refresh_token grant flow, which requires a human user to authenticate interactively via a browser. This blocks a growing use case: automated systems (CI/CD pipelines, agent bots, background services) that need to connect to MCP servers without human interaction.

The MCP specification has a formal extension for exactly this — io.modelcontextprotocol/oauth-client-credentials — which enables automated clients to authenticate using a client_id and client_secret directly, with no browser redirect or user session required.

Use Case

A concrete example: an AI agent bot deployed in Kubernetes (e.g. openab) needs to call MCP tools at runtime without holding a raw upstream service token. The preferred model is:

  1. Ops team registers an Okta service app (grant_type=client_credentials) — access controlled by Okta group membership, auditable, revocable
  2. Bot presents client_id + client_secret to mcp-auth-proxy
  3. Proxy validates credentials against the upstream OIDC provider (Okta), issues its own internal JWT (same as today's authorization_code path)
  4. Bot uses proxy-issued JWT for all subsequent MCP calls

This keeps the same access control model as human users (OIDC group-based, IdP-audited) without requiring browser interaction.

What Would Need to Change

After reading the source, the delta is smaller than expected. The proxy already uses fosite as its OAuth 2.0 framework, which ships OAuth2ClientCredentialsGrantFactory out of the box.

pkg/idp/idp.go — compose.Compose block (~line 80):

// Current
compose.OAuth2AuthorizeExplicitFactory,
compose.OAuth2RefreshTokenGrantFactory,
compose.OAuth2TokenIntrospectionFactory,
compose.OAuth2PKCEFactory,

// Add:
compose.OAuth2ClientCredentialsGrantFactory,

handleOauthAuthorizationServer (~line 377):

// Current
GrantTypesSupported: []string{"authorization_code", "refresh_token"},

// Change to:
GrantTypesSupported: []string{"authorization_code", "refresh_token", "client_credentials"},

New upstream validation path:

The main design question is how the proxy validates incoming client_credentials against the upstream OIDC provider. Two options:

  • Option A (delegate to upstream): Forward the client_credentials request to the upstream OIDC token endpoint (e.g. Okta), verify the returned token, then issue a proxy JWT — consistent with the existing authorization_code path where Okta is the source of truth.
  • Option B (local store): Accept pre-registered client credentials locally using fosite's existing client store without upstream delegation — simpler but disconnects from upstream IdP access control.

Option A is recommended for deployments where the upstream IdP manages access control for service apps via group membership rules.

Is This on Your Roadmap?

Happy to contribute a PR if this is a direction you'd like to go. Would welcome your thoughts on the upstream validation design before starting implementation.

antigenius0910 avatar May 17 '26 11:05 antigenius0910

@hrntknr

when you have time~

antigenius0910 avatar May 26 '26 13:05 antigenius0910