Repository navigation
[AGE-2723] x-tfg-mcp-headers: pass MCP credentials and skip consent - #1313
Merged
Merged
Conversation
rutvij-menavlikar
requested review from
chiragjn,
debajyoti-truefoundry,
heerambavi1998 and
thesujai
as code owners
November 10, 2026 08:13
🦋 Changeset detectedLatest commit: 9695d62 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
5 tasks done
rutvij-menavlikar
force-pushed
the
rutvij/age-2723_1
branch
from
November 10, 2026 09:24
5fe41df to
719b56b
Compare
rutvij-menavlikar
force-pushed
the
rutvij/age-2723_1
branch
2 times, most recently
from
November 10, 2026 11:18
9c5e000 to
4be02c1
Compare
rutvij-menavlikar
force-pushed
the
rutvij/age-2723_1
branch
from
November 10, 2026 11:48
f38f92b to
98a4163
Compare
…h 401 fallback (AGE-2723) Co-authored-by: Cursor <cursoragent@cursor.com>
rutvij-menavlikar
force-pushed
the
rutvij/age-2723_1
branch
from
November 10, 2026 12:04
98a4163 to
6d85393
Compare
# Conflicts: # packages/trueforge/src/apis/turns.ts
…authorize on TrueFoundry turns (AGE-2723)
…723) Co-authored-by: Rutvij Menavlikar <rutvij-menavlikar@users.noreply.github.com>
…E-2723) Co-authored-by: Rutvij Menavlikar <rutvij-menavlikar@users.noreply.github.com>
…oken (AGE-2723)" This reverts commit e36c89c. Co-authored-by: Rutvij Menavlikar <rutvij-menavlikar@users.noreply.github.com>
…2723) Co-authored-by: Cursor <cursoragent@cursor.com>
…E-2723) Co-authored-by: Rutvij Menavlikar <rutvij-menavlikar@users.noreply.github.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e4449a4. Configure here.
rutvij-menavlikar
enabled auto-merge (squash)
November 18, 2026 09:10
chiragjn
reviewed
Nov 18, 2026
chiragjn
reviewed
Nov 18, 2026
chiragjn
reviewed
Nov 18, 2026
chiragjn
reviewed
Nov 18, 2026
chiragjn
reviewed
Nov 18, 2026
chiragjn
reviewed
Nov 18, 2026
chiragjn
reviewed
Nov 18, 2026
chiragjn
reviewed
Nov 18, 2026
chiragjn
approved these changes
Nov 18, 2026
rutvij-menavlikar
disabled auto-merge
November 18, 2026 11:00
…dling (AGE-2723) - callerHeaders -> serverOverrideHeaders, withCallerMcpHeaders -> withServerOverrideHeaders, mergeCallerHeaders -> mergeOverrideHeaders, registeredHeaders -> storeHeaders - TrueFoundry 401 consent: if/else with clearer 422 messages - RemoteMCP: explicit isAuthError branch before the recovery hook
rutvij-menavlikar
enabled auto-merge (squash)
November 18, 2026 12:10
rutvij-menavlikar
disabled auto-merge
November 18, 2026 12:11
Co-authored-by: Rutvij Menavlikar <rutvij-menavlikar@users.noreply.github.com>
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
Implements AGE-2723: x-tfg-mcp-headers support to pass tokens and skip auth on MCP servers.
A server whose entry has a top-level
Authorization(any casing) skips its consent check (TrueFoundryauthorizeor open-source DCR) and uses the caller's credential instead. If the server rejects that credential with a 401, TrueForge falls back to the server's regular auth flow. This mirrors the TrueFoundry gateway'sx-tfy-mcp-headershandling, where anauthorizationheader skips token resolution.Changes
Authorization, DCR consent is skipped; without it, the entry is layered on top of the server's normal auth. Standalone (sqlite) mode now uses the same resolver.Authorization,/authorizeis skipped and the entry is sent as a flatx-tfy-mcp-headerson that server's gateway proxy connection (the gateway rejects a nested map there). The gateway Bearer stays the caller's. Entries withoutAuthorizationkeep today's behavior.ResolveHeadersResultgains an optionalonUnauthorized. On a 401 at connect or mid-session,RemoteMCPclears the rejected connection/session and retries once with the fallback headers, or returnsauthRequiredso the turn pauses with the consent URL. Fallback isauthorizein TrueFoundry mode and DCR or configured headers in open-source mode; the caller's non-Authorizationheaders are kept.perServerMcpHeadersmoved fromtruefoundry/tomcp/since both modes use it.x-tfg-mcp) servers and virtual MCPs are unchanged.How was this tested?
authorize, open-source forwarding and skipped DCR) and two coreRemoteMCPtests (401 at connect, 401 mid-session).tests/core/mcp, trueforgetests/unit/mcpandtests/unit/truefoundry, eslint and prettier on changed files.Checklist
pnpm typecheck/ tests / eslint /pnpm format:checkpass locally for the touched packages.env.exampleupdated if configuration or behavior changed (no config changes)Note
High Risk
Changes authentication header composition, consent timing, and 401 handling for all remote MCP connections in both open-source and TrueFoundry modes.
Reviewed by Cursor Bugbot for commit 9695d62. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary
Implements AGE-2723: x-tfg-mcp-headers support to pass tokens and skip auth on MCP servers.
x-tfg-mcp-headersis an optional per-server header map on the TrueForge request; it may carry its ownAuthorizationfor that MCP server. It is unrelated to TrueForge request auth, which is never sent to the MCP server in open-source mode.Malformed values, nested entries in open-source mode, and the managed
mcp-session-id/mcp-protocol-versionheaders are rejected with 400.Changes
Open-source mode
Authorization, else the stored access token (refreshed as needed); otherwise the manifest's static headers.Authorization).Authorization→mcp.auth_required(DCR consent), as on main.Authorization→ hard fail; else DCR →mcp.auth_requiredwith a fresh DCR consent URL (the stored token is kept until the OAuth callback replaces it); else → hard fail.TrueFoundry mode
x-tfy-mcp-headers; the gatewayAuthorizationstays the gateway Bearer./authorizeis no longer called before connecting./authorize). No entry →/authorize:auth_required+ URL →mcp.auth_required;auth_requiredwithout a URL → 422 as on main;authenticated/not_required→ 422.authorizationinx-tfy-mcp-headersit skips its own token resolution and forwards an upstream 401 as-is, so such a 401 never means consent is needed.Core (
@truefoundry/trueforge-core)ResolveHeadersResultgains an optionalauthRequiredOnUnauthorizedhook. On a 401,RemoteMCPcalls it once: consent → reset the rejected connection and returnauthRequired; undefined → rethrow the 401; a thrown error (e.g. the 422) propagates. No TrueFoundry-specific logic.Other
perServerMcpHeadersmoved fromtruefoundry/toruntime/since both modes use it; the TrueFoundry-only nested schema lives intruefoundry/virtualMcpHeaders.ts.buildResolveMcpServerStoreso the header is honored; the turn session header keeps the 401 hook.How was this tested?
tests/core(361 passed): 401 with consent (at connect, mid-session with reconnect), no consent, lookup error propagates.tests/unit(938 passed): header parsing; open-source DCR skip, merge, DCR 401 hook kept without entryAuthorization; TrueFoundryx-tfy-mcp-headersfor any entry, no up-front authorize, 401 hook only without an entry, consent / 422 mappings, delegate and exchange token assertions.eslint --max-warnings=0, prettier.Checklist
pnpm typecheck/ tests / eslint /pnpm format:checkpass locally for the touched packages.env.exampleupdated if configuration or behavior changed (no config changes)