LiteLLM MCP OAuth: interactive and machine-to-machine flows

How to pick the right OAuth flow for each MCP server behind a self-hosted LiteLLM gateway, from PKCE for Claude Code and Cursor to client credentials for CI and services.

On this page

How LiteLLM MCP OAuth flows decide who the upstream server sees

The choice of OAuth flow is made per MCP server and per type of caller, not once for the whole gateway. When a platform team puts OAuth-protected MCP servers behind a shared LiteLLM gateway, each server needs a flow that matches whether a person or a service is making the call, because the upstream server decides what it trusts based on the token it receives. LiteLLM's MCP OAuth support covers four auth types: authorization_code with PKCE for user-facing tools, client_credentials for backend services and CI, token exchange (OBO) when the upstream must act with the caller's identity in a scoped form, and transparent passthrough when the caller's own token is forwarded. Each is configured on the server registration, so one gateway can run several of them side by side.

Teams usually reach for authorization_code with PKCE when a developer's tool, such as Claude Code or Cursor, must call an MCP server as that person, so the upstream sees the individual's identity and permissions. Client credentials fit scheduled jobs, pipelines and other services that have no user present, where the upstream should see a service identity. Token exchange is the choice when the upstream needs user context but the gateway must not forward the raw token from the caller. Passthrough is the simplest option but gives the upstream whatever the caller presented, so it suits only cases where the caller is already trusted to hold the right token. Before choosing, confirm with your identity provider which grant types it issues for each client, and check the exact field names and supported options in the LiteLLM MCP OAuth documentation for your release.

Which OAuth flow fits which MCP caller

This table compares the four ways LiteLLM can authenticate to an OAuth-protected MCP server, by caller type, what the upstream sees, who owns the token and the main risk. Read each row against the caller you are actually placing behind the gateway, then confirm the exact configuration keys in the LiteLLM MCP OAuth documentation before you commit to a design.

FlowTypical caller and upstream viewToken ownership and main risk
Authorization code with PKCEUser-facing tools such as Claude Code and Cursor, where a person signs in and the upstream sees that user's identityToken belongs to the individual user; risk is per-user consent scope and token handling in each client
Client credentialsBackend services and CI jobs with no interactive user, where the upstream sees the service identityToken belongs to the service client; risk is one shared secret granting broad access if it leaks
Token exchange (OBO)Calls where the caller's identity must reach the MCP server as a scoped token, without forwarding the raw tokenExchanged token is scoped for the MCP server; confirm exchange support and caching for your identity provider
Transparent passthroughCases where the caller's own bearer token is forwarded to the upstream unchanged, so the upstream sees the original callerToken stays with the original caller; risk is that the upstream receives a token it was not designed to trust through the gateway

How a tool call moves from client to upstream MCP server

The diagram starts with two callers: a developer's tool such as Claude Code or Cursor, which signs in through the PKCE authorization code flow, and a backend service or CI job, which uses the client credentials flow. Both send their calls to the LiteLLM gateway, which holds the upstream OAuth configuration and makes the call to the OAuth-protected MCP server. Check the trust boundary at each hand-off: the client network to the gateway, and the gateway to the upstream server, where the token that reaches the MCP server must be the one you intended.

Two client types reach one upstream MCP server through the LiteLLM gateway.

Choosing a flow for Claude Code, Cursor, services and CI

Developer tools such as Claude Code and Cursor run on a person's machine and need a person to sign in. For these callers, LiteLLM uses the authorization code flow with PKCE, so the user approves access in a browser and the resulting token reflects that user's identity and permissions. This is the right choice when the MCP server should record or restrict actions per person.

  • Redirect handling: Confirm which redirect URIs the identity provider must accept for the gateway callback, and whether the MCP server requires them to be registered exactly.
  • Client registration: Ask whether the MCP server supports dynamic client registration or requires a pre-registered public client, since PKCE clients do not hold a secret.
  • Scopes: Obtain the list of scopes the MCP server expects, and decide with the security team which ones users should be granted.
  • Token lifetime and refresh: Check how long access tokens last and whether refresh tokens are issued, because interactive sessions will need to reauthenticate when they expire.
  • Discovery metadata: Confirm the authorization and token endpoints the MCP server advertises, so the gateway configuration matches the identity provider.

Before building, confirm these inputs with the MCP server owner and the identity provider administrator, then test the sign-in path with one developer account.

Setting up OAuth for an MCP server in LiteLLM

This sequence takes one OAuth-protected MCP server from discovery to a tested gateway connection, so each flow your callers use is confirmed to work with the right scope and token lifetime before anyone depends on it.

  1. Confirm the upstream server's OAuth metadata

    The platform owner or the MCP server's maintainer confirms which authorization server issues tokens, which grant types it supports (authorization code with PKCE, client credentials, or token exchange), which scopes exist, and where its protected resource and authorization server metadata are published. Ask for the metadata URLs and a sample scope list in writing. Done when you can fetch the metadata document and list the grants it advertises, and every flow you plan to use appears in that list.

  2. Register the MCP server in LiteLLM

    An administrator adds the server to the LiteLLM gateway with its transport and endpoint URL, as described in the MCP server setup topic. Leave the OAuth auth type unset until the identity details are confirmed, so the registration can be tested on its own first. Done when the server appears in the admin view, and a tool discovery call through the gateway returns the tool list without an authentication error.

  3. Configure the auth type for each server

    Set the auth type on the server record to match the flow chosen for each caller group: authorization code with PKCE for interactive tools such as Claude Code and Cursor, client credentials for services and CI jobs, or token exchange or passthrough where user context must reach the upstream server. Record the client ID, the authorization and token endpoints, and the scopes requested. Done when a configuration review confirms one auth type per server and no secret is stored in the config file itself.

  4. Provision the identity provider client

    The identity team creates an OAuth client for each flow. Interactive clients need the redirect URI that LiteLLM uses for the PKCE callback, with PKCE enforced. Machine clients need a confidential client with client credentials enabled and only the scopes that service requires. Store client secrets in your secret manager and keep LITELLM_MASTER_KEY in the same controlled store. Done when the identity provider shows each client, its grant types, and its scopes, and a reviewer has signed off on the scope list.

  5. Test each flow with a real caller

    Run each flow with the caller it is meant for: sign in through an interactive client such as Claude Code or Cursor for the PKCE path, and run a CI job or service account for the client credentials path. Call a tool that needs upstream authorization and confirm the upstream server accepts the request. Test one denial too, using a caller outside the allowed group. Done when each caller completes a tool call and the denied caller receives an authorization error at the gateway, not at the upstream server.

  6. Verify token scope and expiry

    Decode a sample access token from each flow, or read the token metadata from the identity provider, and check the audience, issuer, scope claims and expiry time. Confirm that the gateway refreshes or reacquires tokens as expected by letting one session outlast the first token lifetime. Check the gateway logs for the upstream call and confirm no raw token appears in them. Done when the scopes match the approved list, the expiry matches what the identity team configured, and token handling in the logs is clean.

  7. Record the configuration and hand over for review

    Document the final auth type, grant, scopes, client owners, secret locations and test results for each server in your configuration repository. Ask the security reviewer to confirm the scope list and the rotation owner for each client secret. Done when the record names an owner for every client, the test results are attached, and any change to scopes or secrets has a defined review step before it is applied.

Token handling, secrets and trust boundaries to review

Each flow in LiteLLM MCP OAuth hands the gateway credentials that can reach upstream MCP servers, so the same few places recur: where client secrets live, how redirects and PKCE verifiers are handled, how long tokens last, and what gets written to logs. The cards below set out one risk and one control for each, to review with your security team before choosing a flow.

Client secret storage

A client_credentials client secret lets any holder obtain tokens for the MCP server under that client's identity. Keep the secret in a secret manager your organization already audits, inject it into the LiteLLM process at runtime, and keep it out of the config file, container image and CI logs. Ask who can read the secret, how it is rotated, and whether a leaked value can be revoked without changing every consumer at once. The LiteLLM Enterprise secret manager integrations list is the place to confirm which managers are supported in your edition.

LiteLLM MCP OAuth docs

Redirect URI and PKCE verifier

In the authorization_code flow, the redirect URI is the point where an authorization code is delivered, and the PKCE code verifier is the secret that proves the same client started the exchange. Register exact redirect URIs with the authorization server, avoid wildcards, and confirm that the verifier is held server-side for the duration of the login rather than passed through the browser. Test a replayed or mismatched code to see that the exchange fails.

Token lifetime and refresh

Short-lived access tokens limit what a stolen token can do, but refresh tokens are long-lived and must be stored as carefully as the client secret. Ask the identity provider for access token lifetimes and refresh rotation settings, and confirm where LiteLLM stores refresh tokens and whether they are encrypted at rest. Set a plan for revoking a user's grant when they leave or change roles, since a cached token can keep working until it expires.

Least-privilege scopes per server

A single broad scope shared by every MCP server turns one compromised token into access to all of them. Request only the scopes each server's tools need, and split servers with different sensitivity onto separate OAuth clients where the identity provider allows it. Review scope grants during onboarding of each server and again when a server adds tools, because new tools often arrive with new scopes.

Logs that exclude raw tokens

Request logs, debug output and trace spans can capture Authorization headers, token exchange responses and callback URLs that carry codes. Before enabling verbose logging, test a sample flow and search the log sink for bearer tokens, refresh tokens and authorization codes. Confirm which fields LiteLLM redacts in your version and whether your SIEM or log store keeps these records for the retention period your policy sets.

What passthrough exposes upstream

In transparent passthrough, the caller's own token is forwarded to the upstream MCP server, so that server receives a credential valid for the caller's identity and can act with it anywhere that token is accepted. Decide per server whether the upstream should trust that token, and whether an on-behalf-of exchange with narrower scope is the safer choice. List every upstream that will receive forwarded tokens, and treat each one as a trust boundary in your threat model.

Where passthrough and delegated flows add risk

Gateway-held credentials are simpler to audit and revoke, but delegated flows carry the caller's identity further into the MCP server. When LiteLLM holds a client_credentials or PKCE-issued token for an upstream server, every tool call is made as one identity the gateway owns. Audit records then show the gateway's client, not the person or service that asked for the call, unless you add your own correlation. Revocation is also straightforward: you rotate or revoke the upstream client or token in one place, and the gateway stops working for that server. Before choosing a flow, confirm with the MCP server owner which identity appears in its own logs and whether it can enforce per-user permissions, because the answer decides whether gateway-level audit is enough for your risk model.

With transparent passthrough, the caller's own bearer token is forwarded to the upstream server. The MCP server then sees the real user and can apply its own authorization, which is attractive for user-scoped data. The costs are that the gateway now handles raw tokens it did not issue, any token it can read may be replayed to the upstream server, and revocation depends on the upstream provider expiring or revoking a token that the gateway may have cached. Check with your security team whether tokens are logged anywhere in the request path, whether the audience of the token matches the upstream server, and who can change the passthrough setting for a server.

Token exchange (OBO) sits between these two options. The gateway trades the caller's token for a narrower token scoped to the upstream server, so user context reaches the server without forwarding the original credential. This reduces audience misuse, but it adds a dependency on the identity provider's exchange support and on token caching behavior, both of which you should test before production. The Entra ID exchange approach is covered on its sibling page, LiteLLM MCP on-behalf-of token exchange with Entra ID, which should be read for provider-specific details.

Limits to confirm with LiteLLM and your identity provider

The MCP OAuth flows in LiteLLM depend on the installed release, the identity provider's grant support and how the gateway runs across instances. Treat each item below as a check to complete in a test environment, not an assumption to carry into design.

Identity provider and grant type support

Confirm which identity providers your installed LiteLLM version supports for each auth type: authorization_code with PKCE for Claude Code and Cursor, client_credentials for services and CI, token exchange and transparent passthrough. Support can differ between the PKCE user flow and the machine flow, and between open source and Enterprise builds. Check the exact grant types your provider issues for each client registration before you commit to a flow.

LiteLLM MCP OAuth docs

Token refresh for each flow

Find out whether LiteLLM refreshes access tokens automatically for the interactive PKCE flow, and what happens when a refresh token expires or is revoked. Client credentials tokens have no user to re-consent, so confirm how the gateway requests a new token before expiry. Test a session that outlives the access token lifetime and record whether users are prompted again or calls fail silently.

Token caching behavior

Ask how LiteLLM caches upstream tokens, where the cache lives and how long entries persist. A cache held in process memory behaves differently from one shared across proxy instances. Confirm that revoking a client or user at the identity provider stops reuse of cached tokens within a time window you can accept, and document that window for your security team.

Multi-instance consistency with Redis

Running more than one proxy instance means token state, rate limits and router state must agree across pods. LiteLLM's production guide requires Redis 7.0 or newer once more than one instance runs. Confirm which OAuth state, if any, is stored in Redis, what happens when an instance restarts mid-flow, and whether a PKCE callback can land on a different instance than the one that started the login.

Version-specific behavior on the supported line

LiteLLM supports the four most recent stable minor versions for open source and Enterprise deployments. MCP OAuth behavior can change between minor releases, so pin the version you test and retest after each upgrade on that line. Confirm the behavior against the release notes for the exact version you run, including the current release listed on the releases page, rather than relying on this page or older blog posts.

Supported minor versions
4
LiteLLM releases

Secret storage for client credentials

Client secrets used for client_credentials flows are long-lived credentials that unlock upstream tools. Confirm whether your LiteLLM build reads them from an external secret manager or only from configuration, and who can view them in the admin UI. Plan rotation with the identity provider and check that a rotated secret takes effect without a full gateway redeploy.

Questions buyers ask about LiteLLM MCP OAuth setup

How much effort does choosing a flow add to a LiteLLM MCP setup?

Choosing a flow adds design work before any configuration: each upstream MCP server needs a decision on whether callers authenticate as themselves (PKCE authorization code), as a service (client credentials), or through token exchange or passthrough. The effort grows with the number of servers and with how many distinct identity providers and client registrations are involved. Each flow also needs its own token lifetimes, scopes and test cases, so the work is mostly planning and verification rather than typing settings. Ask any partner to list each server and the flow it will use before quoting.

Can an internal team set up LiteLLM MCP OAuth without outside help?

Yes, if the team has someone comfortable with OAuth 2.0 concepts, the identity provider's admin console and the LiteLLM proxy configuration. The hard part is rarely LiteLLM itself. It is getting consistent client registrations, redirect URIs, scopes and audience values across an identity provider and several MCP servers, and testing each path with real users. Teams that have run an SSO integration before usually find the MCP work familiar. Teams without that experience often benefit from a short planning review to confirm the flow for each server before they build.

What do we need to provide during an MCP OAuth engagement?

The work depends on four inputs from your side:

  • Administrator access to the identity provider to create applications, scopes and client secrets for the gateway
  • The owners of each MCP server, who confirm supported grant types, token audiences and how they validate tokens
  • A small group of test users for interactive flows such as Claude Code and Cursor, covering each team that will sign in
  • A named owner for the secret store and for approving changes to scopes and redirect URIs

Without these, flow decisions stall because the gateway cannot be tested end to end.

How long does MCP OAuth work depend on the upstream server?

Duration depends mostly on the upstream server, not on LiteLLM. A server with clear OAuth metadata, documented scopes and a test tenant can be connected quickly. A server that needs custom token validation, a different audience per caller, or changes from its own vendor or team will take longer, because those changes sit outside the gateway. Ask the server owner whether the server publishes OAuth metadata, which grant types it accepts and whether a non-production identity tenant exists before any timeline is agreed.

Can client credentials and PKCE run on the same LiteLLM gateway?

Yes. A single LiteLLM gateway can serve interactive users through the authorization code flow with PKCE and backend services or CI jobs through client credentials, as long as each MCP server entry declares the flow it expects. The two flows produce different token types: PKCE tokens represent a signed-in person, while client credential tokens represent a service identity. Keep them separate in the identity provider, use distinct client IDs, and check that permissions on each MCP server reflect the right identity type.

Which risks should we review before enabling token passthrough?

Passthrough forwards the caller's own token to the upstream server, so the upstream server must accept that token's audience and scopes and must not rely on the gateway being the only caller. The main risks are over-broad scopes, tokens reaching servers they were not issued for, and gaps in audit trails because the upstream sees the end user rather than the gateway. Review each passthrough server with its owner, confirm the audience check on the server side, and test that a token issued for one server is rejected by another.

Does a flow choice change what we need to log and retain?

Yes. Interactive flows tie tool calls to a named person, while client credentials tie them to a service identity, and token exchange can record both. Confirm that the gateway's logs and the upstream server's logs record the same identity for each call, and decide how long those records are kept under your own policy. Review this with your compliance team early, because the answer determines which identifiers appear in the logs and who can see them.

Official LiteLLM documentation to read before deciding

Start with the LiteLLM MCP OAuth documentation before choosing a flow, because it is the primary reference for the three decisions this page covers: whether a user signs in interactively through the authorization code flow with PKCE for tools such as Claude Code and Cursor, whether a service or CI job authenticates with the client credentials flow, or whether the caller's identity must be exchanged or passed through to the upstream server. Read it with your MCP server owner's documentation open side by side, since the upstream server decides which grant types, scopes and token audiences it will accept. Confirm in the current docs which auth type each of your servers supports before you draw the architecture.

Next, read the virtual keys documentation to understand what a LiteLLM key can and cannot represent. Virtual keys govern who may call the gateway and under which budget and model limits, which is separate from the credential LiteLLM uses to reach an upstream MCP server. The point of confusion to resolve early is whether a person's identity should travel to the upstream server at all, or whether the gateway should act with a service identity and enforce per-user permissions itself. Check the key scope you plan to issue against the flow you pick so that a delegated token does not end up with broader access than the user holds.

Finally, read the LiteLLM Enterprise documentation and the admin UI SSO page to confirm which identity features you need and which edition provides them. SSO in the admin UI is free for up to 5 users from v1.76.0, and Enterprise is required beyond that, so a team of more users that wants SCIM, JWT authentication with identity provider tokens or audit logs should price that edition before committing to an OAuth design that depends on it. Ask your LiteLLM contact to confirm in writing which edition covers the token exchange and passthrough behavior you intend to use, because feature availability can differ between open source and Enterprise releases.

How DeployOpen scopes and delivers MCP OAuth work

DeployOpen plans, builds and documents LiteLLM MCP OAuth flows inside infrastructure you control, starting from which clients and services call each OAuth-protected MCP server. Each engagement is fixed-scope, with the flows, test cases and handover agreed in writing before work starts.

How we scope

  • We inventory each MCP server, its OAuth provider, grant types and whether users or services call it
  • We map each caller to an auth type: PKCE for user-facing tools, client credentials for services and CI
  • We agree in writing which token exchange or passthrough paths are in scope and which stay out
  • We record the identity provider, redirect URIs, scopes and secret storage the written scope depends on

How we build

  • We configure the PKCE authorization code flow for user-facing clients such as Claude Code and Cursor
  • We configure client_credentials for backend services and CI, with credentials held in your secret manager
  • We set up token exchange or transparent passthrough only where the agreed scope requires them
  • We test each flow for expired tokens, revoked clients, wrong audiences and missing scopes before handover

How we hand over

  • We document each auth type, the client configuration and the owner of each upstream credential
  • We provide runbooks for rotating client secrets and for revoking a user's access to an MCP server
  • We walk your platform and security teams through the test results and open items
  • We deliver configuration as files your team can review and keep in version control

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers after handover
  • We can retest OAuth flows after LiteLLM upgrades, identity provider changes or new MCP servers
  • We help your team confirm LiteLLM release line and feature availability before each change
  • Support scope and response expectations are written into the retainer agreement before work starts

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.