feat(vmcp): inject user identity as HTTP headers into backend requests#5291
Open
fkztw wants to merge 1 commit into
Open
feat(vmcp): inject user identity as HTTP headers into backend requests#5291fkztw wants to merge 1 commit into
fkztw wants to merge 1 commit into
Conversation
When vmcp forwards tool calls to backend MCP servers, the authenticated user's identity (sub, email, name) is now injected as HTTP request headers: X-User-Sub: the sub claim from the authenticated token X-User-Email: the email claim (when present) X-User-Name: the name claim (when present) This allows backend MCP servers to identify the calling user without needing to implement their own OAuth token introspection. Servers can simply read these headers, which are set by the vmcp gateway after it validates the Bearer token. The injection is implemented as claimInjectionRoundTripper, added to the transport chain in createMCPClient() after the existing identityRoundTripper. When no identity is present in context (e.g. anonymous mode), no headers are injected — the tripper is a no-op. Signed-off-by: Frank Zheng <frank@tagtoo.com>
0f894e9 to
333f308
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
vmcpforwards tool calls to backend MCP servers, the authenticated user's identity is now injected as HTTP request headers:X-User-Sub: thesubclaim from the authenticated token (set when a subject is present)X-User-Email: theemailclaim (set only when non-empty)X-User-Name: thenameclaim (set only when non-empty)Motivation
When vmcp acts as an aggregating gateway, it validates the user's Bearer token via the configured incoming authentication strategy (OIDC, anonymous, or an embedded auth server). Backend MCP servers receive the forwarded request but currently have no information about which user initiated the call — only that vmcp accepted the request.
This makes it difficult for backends to:
Injecting identity claims as request headers is a common pattern in API gateway architectures — see nginx
auth_requestpropagation, Envoyext_authzresponse headers, Google IAPX-Goog-Authenticated-User-Email, and AWS API Gateway request-context identity fields.Implementation
A new
claimInjectionRoundTripperis added to the per-backend transport chain increateMCPClient(), placed after the existingidentityRoundTripper:The tripper reads the
*auth.Identityalready attached at client-creation time and sets headers for non-empty claim values. When no identity is configured (e.g. anonymous mode without a populated identity), it is a no-op and the original request is forwarded unchanged.The forwarded request is cloned before mutation; the caller-supplied request and its headers are not modified.
Type of change
Test plan
task test)task lint-fix)Four new tests cover
claimInjectionRoundTripperinroundtripper_test.go, following the same patterns as the existingidentityRoundTrippertests:X-User-SubManual verification with a backend stub confirmed the expected headers reach the downstream service.
API Compatibility
v1beta1API.Changes
pkg/vmcp/session/internal/backend/mcp_session.goclaimInjectionRoundTripperand wire it intocreateMCPClient()transport chainpkg/vmcp/session/internal/backend/roundtripper_test.goclaimInjectionRoundTripperDoes this introduce a user-facing change?
Yes. Backend MCP servers connected via vmcp will now receive
X-User-Sub,X-User-Email, andX-User-NameHTTP headers containing the authenticated user's identity claims. Servers that do not read these headers are unaffected.