Repository navigation
Description
Summary
There is no supported pattern today for placing a backend whose upstream
accepts only user-owned OAuth tokens (GitLab, GitHub, etc.) inside a
VirtualMCPServer while preserving per-user identity at that upstream.
Two independent architectural constraints block it. This issue describes
the gap precisely, documents a confirmed working standalone workaround, and
proposes two approaches that would close it.
Concrete use case
Setup: A VirtualMCPServer fronts ~10 backends. Inbound auth is a
corporate Keycloak instance. Outbound auth for all other backends uses
outgoingAuth.source: discovered + per-backend MCPExternalAuthConfig
of type tokenExchange against a mcp-exchange-svc Keycloak client —
Keycloak mints backend-scoped JWTs from the inbound token. This works for
any backend whose upstream accepts a Keycloak-issued JWT.
Desired addition: an MCPRemoteProxy for the GitLab native MCP
endpoint
(/api/v4/mcp) behind the same vmcp gateway, with per-user identity at
GitLab (not a shared service account PAT).
Why token exchange cannot bridge this: GitLab's /oauth/token does
not implement RFC 8693 — it returns unsupported_grant_type on
urn:ietf:params:oauth:grant-type:token-exchange requests.
MCPExternalAuthConfig type: tokenExchange therefore cannot produce a
GitLab-issued token from a Keycloak JWT.
Standalone workaround (confirmed working): Run the GitLab proxy as a
standalone MCPRemoteProxy — no groupRef, no vmcp — with its own
externalAuthConfigRef → embeddedAuthServer federating to GitLab as the
sole upstream IdP. Clients do a one-time GitLab OAuth flow; the embedded
AS stores per-user refresh tokens and injects the upstream GitLab token
on each request (upstreamInject). This gives correct per-user identity
but produces two separate MCP endpoints instead of one unified gateway.
Gap 1 — IncomingAuth is gateway-wide; no per-backend override
VirtualMCPServerSpec.IncomingAuth is a single field that applies to
every client connecting to vmcp. BackendAuthConfig exists only in the
outgoing direction (vmcp → backends). There is no mechanism to say
"clients authenticating to reach the GitLab backend must go through
embeddedAuthServer; clients reaching all other backends authenticate
via Keycloak OIDC directly."
If IncomingAuth is switched to embeddedAuthServer (GitLab upstream),
Keycloak-issued tokens are no longer accepted at all, breaking every
other backend.
Gap 2 — upstreamProviders are alternates, not a chain
Multiple entries in embeddedAuthServer.upstreamProviders are treated as
alternate IdPs for the same user session (only the first is authoritative;
the operator emits a warning condition when multiple upstreams are
combined with authz policy). There is no way to say "authenticate the
client via Keycloak (inbound), and in parallel acquire and store a GitLab
token for this session to inject into the GitLab backend."
When a user authenticates through the Keycloak upstream, no GitLab token
is ever acquired. The upstreamInject pattern only works in the
standalone case because the embedded AS's sole upstream is GitLab and
every session already carries a GitLab access token.
Proposed solutions
Option A — Linked-account model in embeddedAuthServer
Extend the embedded AS to support a linked-account flow: the user's
primary authentication goes through the configured inboundProvider
(e.g., Keycloak). For each declared linkedProvider, the embedded AS
separately initiates an OAuth authorization-code flow against the
external IdP (GitLab) and persists the per-user upstream access + refresh
token in its session store, associated with the primary sub.
On each proxied request, if the target backend is the one linked to
GitLab, the stored GitLab access token is injected (upstreamInject).
For all other backends the existing Keycloak tokenExchange outgoing
auth applies unchanged.
This is the higher-value path because it preserves a single unified MCP
endpoint and keeps inbound auth on Keycloak for all clients.
Option B — Per-backend IncomingAuth override on VirtualMCPServer
Add an optional incomingAuthOverride field at the BackendRef level in
VirtualMCPServerSpec. When set, vmcp uses the specified
MCPExternalAuthConfig to validate tokens on requests routed to that
backend, bypassing the gateway-wide IncomingAuth. Clients must hold a
valid token for the backend-specific config; the gateway routes by
matching incoming bearer token issuer against registered configs.
This is the more targeted change and may be easier to implement, though
it still does not acquire GitLab tokens automatically — clients would need
to obtain them independently and present them in a backend-specific
header or scope hint, which degrades UX.
Related issues
- ToolHive should support the Identity-Assertion JWT Authorization Grant (ID-JAG / XAA) for cross-domain backend authentication #5218 — ID-JAG/XAA: an alternative bridge if GitLab ever supports
identity-assertion grants. Not available on self-managed instances
today, and depends on the upstream IdP implementing the draft spec. - Embedded auth server should support RFC 8693 token exchange so agents can act on behalf of users #5194 —
embeddedAuthServerRFC 8693 token exchange: a superset of
this request for the agentic case; the linked-account model in Option A
is the user-interactive analog.
Environment
- ToolHive operator: v0.27.0 (Kubernetes, self-managed deployment)
- Keycloak 26.3 (inbound IdP)
- GitLab self-managed (upstream backend,
/api/v4/mcp) - Confirmed by Stacklok/Yolanda on Discord (2026-05-19) that neither gap
is a misconfiguration — both are current architectural limits with no
workaround inside vmcp.
Activity
jerm-dro commentedon Jun 24, 2026
Thanks for the detailed write-up, @gastoncan. Before we confirm these as architectural gaps, one question: have you tried configuring the embedded AS with both Keycloak and GitLab as
upstreamProviders, withincomingAuth.type: embeddedAuthServer, and usingupstreamInjectfor the outgoing auth to GitLab?The
upstreamInjectoutgoing auth method supportsupstreamInject.providerNameparameter. It injects the upstream token for whichever provider the user authenticated through. If your users can authenticate via the embedded AS (federating to either Keycloak or GitLab), the GitLab backend would get the stored GitLab token injected. See the upstream token injection docs for more detail.If you have tested this and it does not cover your case, I'd be happy to discuss further.
onepabz commentedon Jul 7, 2026
We hit exactly this gap running ToolHive OSS as a declarative, operator/CRD-managed MCP gateway (no custom Go embedding).
On v0.34.0, #5725/#5733 landed the upstream-filter mechanism and the
authserver.Newfacade — but the operator's embedded auth server (pkg/authserver/runner/embeddedauthserver.go) never setsConfig.UpstreamFilter, and no CRD / Helm / env surface feeds it.SingleLegis wired end-to-end but nothing ever originates aSingleLeg: trueauthorization (and no CRD can). So composing per-user, user-owned-OAuth backends behind oneVirtualMCPServer— without forcing consent to every upstream at every login — isn't reachable declaratively today.Is a CRD-level surface planned here (a per-backend
SingleLegtrigger, or a declarativeUpstreamFilter/ per-backendIncomingAuthoverride)? Happy to help test or contribute the operator/CRD plumbing.aponcedeleonch commentedon Jul 17, 2026
@onepabz thanks for digging into the code and laying this out precisely. Your reading is correct. As of v0.34.0 the UpstreamFilter mechanism and the authserver.New facade are in OSS (#5725/#5733), but the operator's embedded auth server never sets Config.UpstreamFilter, nothing originates a SingleLeg: true authorization, and there is no CRD/Helm/env surface to drive either. The primitives exist. The declarative surface that composes per-user, user-owned-OAuth backends behind one VirtualMCPServer does not.
To answer your load-bearing question directly: that declarative surface is where we draw the OSS/Enterprise line. The per-user, per-backend connector enablement built on UpstreamFilter/SingleLeg is delivered through our Connector Gateway, which is part of Stacklok Enterprise. We are not planning to land that operator/CRD surface in OSS core, so we would not be able to take it as an OSS contribution. I'd rather be upfront about that than leave the offer open on a false premise.
The standalone auth server is a different story. We intend to upstream that into OSS, and I've followed up on #5807 with the detail since that's the better home for it. The offer to contribute is welcome there.
Your group-partitioned vMCP topology is exactly the shape of problem Connector Gateway is built for. If it's useful, we'd be glad to walk you through the Enterprise implementation and see whether it fits. Reach out and we'll set up a conversation.
gravelfreeman commentedon Sep 15, 2026
I have a similar use case, but in a self-hosted family environment.
I am running ToolHive on Kubernetes with a single
VirtualMCPServerthat aggregates multiple backends:The vMCP is protected by Pocket ID through Envoy Gateway. Each family member authenticates with their own Pocket ID account, and I would like to preserve their individual permissions.
Home Assistant MCP supports
ha-mcp-oauth, where each user authenticates with their own Home Assistant Long-Lived Access Token. However, the current vMCP flow appears to authenticate the user at the gateway and then call the backend with a shared backend identity. https://github.com/homeassistant-ai/ha-mcp/blob/master/docs/OAUTH.md#when-to-use-oauthI would like to use one unified vMCP endpoint while having ToolHive:
Would this be possible with
MCPExternalAuthConfig,embeddedAuthServer, or a future linked-account flow?Using
forwardAccessTokenwould not be sufficient in my case because the Pocket ID token is not a specific app token. I also want to avoid using a shared app's admin token for every family member.The desired result is one secured ToolHive endpoint for the family, with per-user authorization.