Repository navigation
[AGE-2723] Fall back to MCP auth flow when supplied credentials get a 401 (RemoteMCP onUnauthorized) - #1314
[AGE-2723] Fall back to MCP auth flow when supplied credentials get a 401 (RemoteMCP onUnauthorized)#1314rutvij-menavlikar wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 820ffb3 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 |
PR overviewThe PR adds an MCP authentication fallback in RemoteMCP when supplied credentials receive a 401 response, reconnecting with headers obtained through the fallback flow. One open issue remains: after fallback authentication, subsequent operations reuse the cached connection without rechecking the OAuth resolver. For a DCR server, deleting a user's stored MCP authorization mid-turn does not stop subsequent tool calls using the cached bearer token, leaving a limited revocation-enforcement gap. No issues have been addressed yet. Open issues (1)
Fixed/addressed: 0 · PR risk: 5/10 Reviews |
ff51179 to
23e58bf
Compare
5fe41df to
719b56b
Compare
23e58bf to
4d5d106
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 4d5d106. Configure here.
…SS) / mapped to x-tfy-mcp-headers (TFY) (AGE-2723) Co-authored-by: Cursor <cursoragent@cursor.com>
719b56b to
9c5e000
Compare
4d5d106 to
8b48d6e
Compare
| if ('authRequired' in fallback) { | ||
| return { authRequired: fallback.authRequired }; | ||
| } | ||
| return this.connectAndRun(fallback.headers, operation, true); |
There was a problem hiding this comment.
Medium: OAuth revocation is skipped after fallback
After reconnecting with fallback.headers, subsequent operations still resolve the original caller headers and reuse the fallback connection without invoking the registered OAuth resolver again. For a DCR server, deleting the user's stored MCP authorization mid-turn therefore still permits tool calls with the cached bearer token; retain and recheck the fallback resolver on subsequent operations so local revocation returns authRequired before dispatch.
…(AGE-2723) Co-authored-by: Cursor <cursoragent@cursor.com>
8b48d6e to
820ffb3
Compare
9c5e000 to
4be02c1
Compare
|
Folded into #1313. |

Summary
Second of two stacked PRs for AGE-2723. Stacked on #1313.
#1313 lets a caller's
Authorizationinx-tfg-mcp-headersreplace an MCP server's consent flow. This PR covers the case where the upstream rejects that credential with a 401: TrueForge then falls back to the server's regular authorization flow instead of failing the tool call. The gateway doesn't do this itself; it forwards upstream 401s verbatim.Changes
ResolveHeadersResult(headers variant) gains an optionalonUnauthorizedresolver.RemoteMCPconsults it once when the upstream returns a 401, either at connect or mid-session. It first resets only the connection that carried the rejected credentials, then reconnects with the fallback headers or returnsauthRequired, which surfaces the consent URL.isAuthErroris exported and recognizesMcpConnectionErrorwith status 401. Resolvers withoutonUnauthorizedare unchanged.authorizepath, which returns a consent URL or the gateway-held token.How was this tested?
authRequired, and a 401 mid-session reconnects with the fallback headers.onUnauthorizedreturns the consent URL fromauthorize.pnpm test:trueforge(934 passing), eslint, and prettier.Checklist
pnpm typecheck/ tests / eslint /pnpm format:checkpass locally for the touched packages.env.exampleupdated if configuration or behavior changed (n/a)Note
Medium Risk
Changes authentication retry behavior for MCP tooling; mistakes could mis-route identity or skip consent, but behavior is scoped to 401 responses and one-shot fallback.
Overview
Remote MCP header resolvers can now attach an optional
onUnauthorizedcallback.RemoteMCPinvokes it once when connect or mid-session work gets a 401, resets the rejected connection, then retries with fallback headers or returnsauthRequired.isAuthErroris exported and treatsMcpConnectionErrorwith status 401 as auth failures.TrueForge / OSS MCP stores wire this for caller
Authorizationinx-tfg-mcp-headers/x-tfy-mcp-headers: credentials are tried first, but a 401 triggers the normal consent/DCR or gateway authorize path instead of failing the tool call.Reviewed by Cursor Bugbot for commit 820ffb3. Bugbot is set up for automated code reviews on this repo. Configure here.