LiteLLM MCP on-behalf-of token exchange with Entra ID

LiteLLM can exchange a caller's bearer token for a scoped token at Entra ID before calling an MCP server, so user context reaches the tool without forwarding the raw token.

On this page

How LiteLLM MCP on-behalf-of token exchange works with Entra ID

LiteLLM's on-behalf-of MCP auth lets an MCP tool act for a specific user without receiving that user's raw token. The gateway takes the caller's bearer token as the RFC 8693 subject_token, exchanges it at the identity provider for a scoped token, and forwards only that scoped token to the MCP server. The exchanged token is cached until it expires, and Microsoft Entra ID is supported natively. The practical question for your team is whether the MCP server needs to know who the user is, or only needs to trust that the gateway has already authorized the call.

Teams need on-behalf-of exchange when the upstream MCP server makes its own authorization decisions per user, such as reading a mailbox, a ticket queue or a document store where the user's own permissions apply. If the server only needs the gateway's identity, or every caller shares the same access, a simpler pattern is usually enough. Client credentials for services, or per-user upstream credentials stored per user and server, avoid the extra token hop. Read the sibling topics on LiteLLM MCP OAuth flows and per-user upstream credentials before committing to exchange.

Before you build, confirm in your Entra ID tenant which app registrations act as the gateway and as the MCP resource, which API permissions and scopes the exchanged token must carry, and whether your MCP server validates audience and scope claims. Also confirm how long your tokens live, because cache expiry follows the token lifetime. Test with a non-production user whose permissions differ from an admin, and verify that the MCP server rejects the original caller token presented directly.

Request flow from client through LiteLLM to Entra ID and the MCP server

The flow starts when a client calls the LiteLLM gateway with its own bearer token. LiteLLM uses that token as the RFC 8693 subject_token, exchanges it with Microsoft Entra ID, and receives a scoped token. The cached scoped token is then the only credential sent to the MCP server, so the caller's raw token never leaves the gateway. Check that the boundary between the gateway and the MCP server carries only the scoped token, and that the cache respects token expiry.

Caller token is exchanged inside the gateway; only the scoped token crosses to the MCP server.

What RFC 8693 token exchange changes for user context

The subject_token is the bearer token the caller already presented to LiteLLM, the access token issued by Microsoft Entra ID to the user or service that invoked the MCP tool. Under RFC 8693, LiteLLM uses that token as the input to a token exchange request at the identity provider. The identity provider checks the caller's token, then issues a new, scoped token for the upstream MCP server. LiteLLM forwards only that scoped token to the MCP server, so the caller's original token never reaches the tool. The scoped token carries the user's identity (the subject claim) and the permissions limited to the MCP server's audience, so the MCP server can act on behalf of the person who made the request without holding a credential that works against other services.

Forwarding only the scoped token narrows exposure in two ways. If the MCP server logs, caches or is compromised, the leaked credential is valid for that audience and no broader resource. The original token, which may grant access to several APIs, stays inside LiteLLM. Before go-live, confirm with your Entra ID administrator which scopes and audience values the exchange returns, and confirm in the LiteLLM MCP on-behalf-of documentation at LiteLLM docs: MCP on-behalf-of auth how the exchange settings, client credentials and expected claims are configured in your version. Those settings, not defaults assumed from this page, define what the MCP server can trust.

LiteLLM caches the scoped token until it expires, so repeated tool calls by the same user do not trigger a new exchange each time. Expiry is the operational boundary to plan for. A long-running tool call that starts close to expiry can fail partway through, and the MCP server will reject a token that lapses mid-operation. Ask the vendor and your identity team what token lifetime Entra ID issues for the exchanged token, then test a deliberately long tool call to see how the gateway and MCP server behave at expiry. Decide whether long jobs should be split into shorter steps, and confirm that the cache is evicted correctly when the user's session or permissions change.

Configuration options and when each fits

This table compares the main choices for getting user context to an MCP server: native Entra ID exchange, a generic RFC 8693 provider, passthrough, and client credentials. Read each row for when the option fits and what to confirm in LiteLLM and Entra ID before committing.

OptionWhen it fitsTrade-offWhat to confirm
Native Entra ID exchangeCallers already authenticate with Entra ID and each MCP server needs the end user's identityTies the gateway to Entra ID app registration and consent settingsApp registrations for the gateway and each MCP server, expected audience values, and admin consent status
Generic RFC 8693 identity providerYour identity provider supports token exchange but is not Entra IDToken exchange parameters and claim mapping are configured by hand and tested per providerProvider supports the token exchange grant, the subject token type accepted, and the audience and scope parameters it returns
Scope and audience per MCP serverSeveral MCP servers need different permissions or must reject tokens meant for othersMore app registrations or scopes to maintain as servers are addedEach server validates its own audience, and the exchanged token scopes match the least privilege each tool needs
Single broad audienceA small number of servers trust the same back-end and share one permission modelA token accepted by one server may be replayed against anotherWhether servers check the audience claim, and who approves widening scopes later
Cache lifetime handlingHigh call volume where repeated exchanges would add latency and load on the identity providerCached tokens can outlive a user's revoked access until they expireHow the cache key includes user and server, how expiry is read from the token, and how revocation is handled
Passthrough of the caller's tokenThe MCP server must be the sole validator and the caller's token already has the right audienceForwards a raw token to another system, which conflicts with a no-forwarding designWhether the MCP server accepts the caller's audience and whether your policy allows raw token forwarding
Client credentials (no user context)Scheduled jobs, CI pipelines or services that act as themselves rather than for a userTool calls lose per-user attribution and per-user permissionsWhich service identity is used, its granted permissions, and how audit logs tie calls back to a team or key

How to set up on-behalf-of exchange with Entra ID

This sequence takes a LiteLLM gateway from a supported release to a state where each MCP tool call carries a scoped token derived from the caller's own identity, and where the MCP server can be shown to accept nothing else. Each step closes with a check so the platform, identity and security teams can sign off before users depend on it.

  1. Confirm the LiteLLM version and release line

    The platform team records the LiteLLM version running in the target environment and checks it against the current release line described in the project's release notes and enterprise support documentation. Upgrade first if the gateway sits on an unsupported line, because the on-behalf-of configuration should be built on the version you will run in production. Confirm that the database and Redis layout follow the production guidance for a multi-instance deployment. Check: the version, its release line and the upgrade path are written in the change record and approved by the owner of the gateway.

  2. Register the gateway and MCP server apps in Entra ID

    An identity administrator creates two app registrations in the Microsoft Entra ID tenant: one for the LiteLLM gateway, which acts as the client performing the exchange, and one for the MCP server, which exposes the API the scoped token will be issued for. Record the tenant ID, both application IDs and the directory that will hold them. Keep the gateway registration limited to the tenant that owns the users, and confirm with your identity team which tenant boundary applies to contractors or guest accounts. Check: both registrations appear in the tenant, and the identity team has the IDs recorded in the change record.

  3. Define scopes and the MCP server audience

    The identity administrator exposes one or more delegated scopes on the MCP server registration and sets its application ID URI as the audience that tokens must carry. Grant the gateway registration permission to request those scopes on behalf of signed-in users, and decide with the MCP server owner which tools map to which scopes. Keep scopes narrow, because the scope list is what limits a user's delegated access once the gateway performs the exchange. Check: a test sign-in for a sample user shows the expected scope claim in a token issued for the MCP server audience, and the owner of the MCP server agrees with the scope list.

  4. Configure the token exchange in LiteLLM

    The platform engineer adds the MCP server's OBO settings to the gateway configuration, pointing it at the Entra ID tenant, the gateway client and the target audience and scope. LiteLLM uses the caller's bearer token as the RFC 8693 subject token, exchanges it at the identity provider and forwards only the resulting scoped token upstream. Keep the configuration in version control and reference secrets by name rather than by value. Check: the configuration validates on a non-production instance, and the proxy starts without errors that reference the exchange settings.

  5. Store client secrets in a secret manager

    The security team places the gateway's client secret in the secret manager the organization already runs, and the platform team configures LiteLLM to read it at startup instead of from a file or environment variable committed to a repository. Set a rotation date with the identity team and record who can read the secret. Confirm that the LITELLM_MASTER_KEY is also held in the same controlled location, as the production guidance recommends. Check: the secret is retrieved at runtime from the manager, no plaintext copy exists in configuration files or logs, and the rotation owner is named in the runbook.

  6. Test the exchange with a user token

    A tester signs in as a test user through the client that will call the gateway, obtains a bearer token from Entra ID and sends an MCP tool call through LiteLLM. The tester confirms that the call succeeds for a user who holds the required scope and fails for a user who does not. Repeat the call a second time within the token lifetime to confirm that the cached scoped token is reused, then after expiry to confirm it is refreshed. Check: the expected allow and deny results are recorded, and the cache behavior matches the token expiry in the test logs.

  7. Verify that the MCP server receives only the scoped token

    The security engineer inspects what reaches the MCP server during the test, using a test endpoint, a controlled proxy or the server's own request logs. The check confirms that the upstream request carries the scoped token for the MCP server audience, and that the caller's original bearer token, which was issued for the gateway, is not forwarded. Review the audience, scope and subject claims in the received token against the expected values from the earlier steps. Check: the captured request contains only the scoped token, the claims match the design, and the result is attached to the change record before users are onboarded.

Security risks in token exchange and how to contain them

Token exchange puts a second, more powerful credential into the request path, so each step can leak, widen or misattribute user rights. The cards below cover the risks that matter most for LiteLLM MCP on-behalf-of token exchange with Entra ID, and what to verify in your own tenant and gateway before go-live.

Raw token leakage through logs and headers

The caller's bearer token is the subject_token in the exchange, so it is the most sensitive value the gateway handles. If it reaches request logs, trace exporters, error messages or headers forwarded to the MCP server, every reader of those systems can replay it until it expires. Confirm that the gateway's logging configuration redacts the Authorization header, that debug logging is off in production, and that only the scoped token is sent upstream.

MCP OBO docs

Over-broad scopes on the exchanged token

The exchanged token is only as narrow as the scope requested at Entra ID. A gateway configured with a broad or default scope can hand an MCP server far more delegated permission than any single tool call needs. Ask which scope each MCP server requires, request only that scope in the exchange configuration, and review the consent granted to the gateway's app registration in your tenant.

Cache exposure and cache key scope

The gateway caches exchanged tokens until expiry, so a cache entry is a live credential. If the cache key does not include both the user identity and the target MCP server, one user's scoped token could be served to another caller or to a different server. Verify how the cache key is built, who can read the cache store, and that the cache is held in a store with access controls that match the gateway's own secrets.

Confused deputy risk at the MCP server

A confused deputy occurs when the MCP server accepts any request from the gateway and trusts the gateway's identity instead of the user's. An attacker who reaches the MCP server directly, or who manipulates the gateway's routing, can then act with the user's rights. Validate the audience and issuer claims on every exchanged token, and consider rejecting calls that do not carry a gateway-signed assertion, as described in the zero-trust MCP sibling topic.

Client secret handling for the exchange

The gateway authenticates to Entra ID with a client credential when it performs the exchange, and that secret can mint tokens for every user who signs in to the app. Store it in a secret manager rather than in the config file or environment of a shared host, scope the app registration to the MCP APIs it must reach, and plan rotation with a tested overlap window. Confirm the secret's expiry date in your tenant before go-live.

Audit trails linking user, gateway and tool call

An investigation needs one record that ties the human caller, the gateway key or team, the MCP server and the tool invoked together. Without this link, a tool call looks like it came from the gateway's service identity. Confirm that the gateway records the Entra ID subject or object ID with each MCP call, that the record reaches the log store your security team uses, and that retention matches your policy.

Running token exchange in production with multiple gateway instances

The first design decision for production is where the exchanged token cache lives. A token cache is per instance unless you configure shared state. If each LiteLLM proxy pod keeps its own in-memory cache, a user's request can hit a different instance than the one that holds the scoped token, so the gateway performs a fresh exchange at the identity provider. That adds latency and load on Microsoft Entra ID, and it multiplies the number of tokens issued for one user. LiteLLM's production guide requires Redis 7.0 or newer once more than one proxy instance runs, for shared rate limits, router state and cache. Confirm with the LiteLLM documentation for MCP on-behalf-of auth whether the exchanged-token cache uses that shared Redis, and test it by sending the same user's calls through two instances and counting exchanges in the identity provider's sign-in logs.

Plan for failure and drift before go-live. If Entra ID is unreachable, exchanges fail, so decide whether affected tool calls should return an error to the caller or fall back to a cached token that has not yet expired; the second option only works while cached tokens remain valid. Clock skew between gateway pods and Entra ID can make a freshly issued token look expired or not yet valid, so keep all nodes on synchronized time and check token validation errors after any node change. Long-running tool calls can outlive a scoped token, so confirm how the gateway refreshes or re-exchanges mid-call and set expectations for tools that run longer than the token lifetime. For key rotation, the signing keys used to validate tokens rotate on the identity provider's schedule, and the gateway must pick up new keys without a restart. Rehearse rotation in a non-production tenant, and record which Entra ID app registration, client secret or certificate each gateway instance uses. Some of these controls depend on edition, so check the Enterprise feature list in the LiteLLM Enterprise documentation before you commit to an architecture.

Limits to confirm in your environment

The token exchange touches your identity provider, your MCP server's authorization model, the gateway cache and the LiteLLM release you run. Each of the cards below is a point where an assumption can fail, so confirm it against your own tenant and servers before the design is signed off.

Entra ID tenant configuration

Confirm which tenant layout you run: single tenant or multi-tenant app registrations, guest users from partner tenants, and whether the caller's token is issued for the audience the gateway expects. The exchange depends on the subject token being valid at the identity provider, so a token issued for a different app registration can fail the exchange in ways that look like a gateway fault. Ask your identity team to test one token from each user population you plan to support.

MCP OBO docs

Fit with the MCP server's authorization model

Check whether your MCP server can accept an exchanged token and enforce user-level permissions from its claims. Some servers validate only audience and scope, while others read user, group or role claims to filter tools or data. If the server ignores user context, the exchange adds a hop without adding control. Review how each tool maps to a permission before you rely on the scoped token for access decisions.

Cache behavior against token lifetimes

Tokens are cached until expiry, so the lifetime your identity provider assigns directly sets how long a cached exchanged token stays usable. Confirm the access token lifetime in your Entra ID policies, and check how the gateway handles a revoked user or disabled account while a cached token is still valid. Decide whether a shorter lifetime is acceptable for sensitive tools, and test what happens at the moment of expiry.

Enterprise need for SSO and audit

Decide whether open-source features cover your sign-in and audit requirements. The admin UI SSO is free only up to a limit of 5 users from v1.76.0, and audit logs, JWT authentication with identity provider tokens and organization RBAC sit in the Enterprise edition. Confirm with your license and compliance owners whether the token exchange events must appear in audit records before you choose the edition.

Enterprise docs

Version-specific behavior on your release

Confirm that the OBO flow and Entra ID support exist in the exact LiteLLM release you plan to run, not only in the current documentation. The release line you choose determines which fixes you receive, and support covers the four most recent stable minor versions. Test the exchange on your chosen release in a staging environment and record the version in your change plan, so upgrades trigger a repeat test.

Supported release window
4 minor versions
LiteLLM releases

Questions teams ask before running on-behalf-of with Entra ID

How much effort do the Entra ID app registrations and LiteLLM configuration take?

The effort depends mostly on how many identity configurations you need, not on LiteLLM itself. Each setup involves registering the LiteLLM application in Entra ID, defining the API scopes that the MCP server will accept, granting the exchange permissions that LiteLLM needs, and then mapping each MCP server to its scope in LiteLLM's MCP configuration. Drivers include whether you already have an app registration for the gateway, how many MCP servers need distinct scopes, how your tenant structures consent and admin approval, and whether you have separate development and production tenants. Ask any partner to break its quote into identity work, LiteLLM configuration and testing, so you can see which parts your own staff could take over.

Can our team set up on-behalf-of token exchange internally?

A team with working knowledge of OAuth 2.0, OpenID Connect and Entra ID administration can usually build a first flow internally, because LiteLLM's documentation describes the exchange step and Entra ID supports it natively. The harder part is the surrounding design: deciding which user claims the MCP server trusts, how token lifetimes interact with the cache, and how failures surface to callers. If your team already runs LiteLLM in production and has an identity engineer who owns the tenant, the work is a focused project. If either is missing, a fixed-scope engagement with written deliverables can cover the gap. Either way, confirm the current LiteLLM release line before you start, since configuration details can change between versions.

What do identity and platform staff need to contribute?

Identity staff need to own the Entra ID side: app registrations, exposed scopes, client secrets or certificates, consent and admin approval, and conditional access policies that might block the exchange. Platform staff need to own where LiteLLM runs, how its secrets are stored, how the gateway is reached by callers, and how the MCP servers are reachable from the gateway. Security reviewers should check that the subject token is never logged and that the scoped token reaches only the intended server. Plan time for these people early, because consent and secret rotation often wait on approval queues rather than on engineering work.

How does on-behalf-of differ from passthrough or client credentials?

On-behalf-of keeps the user's identity in the call: LiteLLM exchanges the caller's bearer token for a scoped token that the MCP server accepts, so the server knows which user made the request. Passthrough forwards the caller's token as-is, which exposes the raw token to the upstream server and ties it to that server's audience. Client credentials use a service identity with no user context, which suits CI jobs and background services but cannot enforce per-user permissions. Choose on-behalf-of when the MCP server must make decisions based on who the user is. Choose client credentials when the work is performed as a service. Review the sibling guidance on OAuth flows before deciding.

What should we test before going live?

Test the full path from a real user token through the exchange to the MCP server, then test the cases where it should fail. Useful checks include a valid user receiving the expected tools, a user without the right scope being refused, an expired or revoked token being rejected, and a scoped token that cannot be used against a different MCP server. Confirm that the cache honors token expiry and that logs do not contain raw bearer tokens. Also test what happens when Entra ID is unavailable. Record the results and the LiteLLM and Entra ID versions tested, so you have evidence for your security review.

What changes when we add more MCP servers?

Each new MCP server adds its own audience or scope, its own mapping in LiteLLM, and its own test cases, so the work grows with the number of servers and the number of distinct permission levels rather than with traffic. Shared scopes reduce configuration but make it harder to separate what each server can do. Separate scopes give clearer boundaries but more app registrations to maintain. Plan for ongoing ownership: when a server's API changes, its scope definitions and tests must change too. Ask whether a retainer for testing and upgrades fits your plan, since DeployOpen offers ongoing support as a separate arrangement.

When on-behalf-of is the right choice for MCP tools

Use on-behalf-of token exchange when the MCP tool has to act with the signed-in user's own identity and permissions, so that the upstream system can apply the same access rules it applies to that user. A typical case is a tool that reads a user's mailbox, files or tickets, or writes records that must show who made the change. In LiteLLM's design, the caller's bearer token becomes the RFC 8693 subject token, the identity provider issues a scoped token for the MCP server, and only that scoped token travels onward. Before choosing this path, confirm that the upstream server accepts tokens from your Entra ID tenant, that it validates the audience and scopes you intend to request, and that users in every team that will call the tool already hold the rights the tool needs in the upstream system.

If the work is service-only, such as a nightly sync job, a CI check or a server-side report that runs with no user present, client credentials is the better fit. The MCP server then sees the service's identity and must enforce its own rules for that identity, so per-user audit trails and per-user permissions do not apply. If the upstream system issues its own tokens to each user (for example, a SaaS tool that requires its own OAuth grant), exchanging an Entra ID token does not help, and per-user upstream credentials are the right model. For interactive tools used from clients such as Claude Code or Cursor, review the sibling topic on LiteLLM MCP OAuth before choosing, because the PKCE authorization code flow changes where the user signs in.

How DeployOpen scopes and delivers LiteLLM MCP identity work

DeployOpen treats LiteLLM MCP on-behalf-of token exchange with Entra ID as an identity change to a self-hosted gateway, not a one-line configuration. We agree the scope in writing, build and test the exchange inside your own infrastructure, and hand over the configuration and runbooks your identity and platform teams need to operate it.

How we scope

  • Written scope lists the MCP servers, Entra ID app registrations and token audiences that will use the exchange
  • Mapping of which callers, teams and keys need user context forwarded to each MCP server
  • Agreed decisions on caching behavior, token lifetimes and what happens when the exchange fails

How we build

  • Configure the LiteLLM gateway and Entra ID settings in your tenant so only the scoped token reaches each MCP server
  • Test exchange behavior, expiry handling and cache reuse against your own identity and MCP server setup
  • Run security checks on token handling, including confirming raw caller tokens are never forwarded upstream

How we hand over

  • Delivery of configuration, app registration settings and token flow documentation for your engineers
  • Written test results with findings, fixes and a retest of the exchange path
  • Walkthrough with your identity, security and platform teams so they can review and run the setup

How we support

  • Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts
  • Ongoing support, upgrades and continuous testing are available as a retainer
  • Quotes follow from the written scope, so ask for the scope items that drive effort before signing

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.