LibreChat/api/server/services
J.C. Bartle 6e46fbbb59 🧊 fix: Inline-refresh OpenID session tokens at MCP OBO call time
Resolves the walk-away failure mode where MCP tool calls using OBO auth
fail with "No valid OpenID access token is available for OBO exchange"
after a user idles past their access-token lifetime. The strategy-time
snapshot on `user.federatedTokens` could expire mid-stream before
`resolveOboToken` ran, while `req.session.openidTokens` carried a still-
valid (or refreshable) token that nothing read.

- New OpenIDSessionRefresh service: per-user single-flighted closure that
  reads `req.session.openidTokens` at OBO time and inline-refreshes via
  `openid-client.refreshTokenGrant` when expired (30s skew), persisting
  via `req.session.save()`. No cookie writes (headers already flushed).
- `resolveOboToken` gains a required UpstreamTokenProvider parameter
  (typed as `() => Promise<OIDCTokens | null>`, reusing the shared shape
  from @librechat/data-schemas). Compile-time guarantee that every call
  site is updated.
- New `session_refresh_failed` OboTokenResolutionReason distinguishes
  "session expired and IdP rejected refresh" from "no upstream token
  ever existed."
- `req` threaded through createMCPTool/createMCPTools/createToolInstance
  to construct the closure with captured request, plus fail-closed
  guards in MCPConnectionFactory.getOboTokens and MCPManager.callTool
  when the closure isn't plumbed.
- Startup warning in MCPServersInitializer when OBO is configured but
  OPENID_REUSE_TOKENS is unset (the strategy populating
  user.federatedTokens is only registered under reuse, so OBO would
  fail every call without it).

Tests: 16 new in OpenIDSessionRefresh.spec.js; obo.spec.ts extended
for the new param + error reason; wiring smoke tests in MCPManager,
MCPConnectionFactory, MCPServersInitializer, and MCP.spec.js.
2026-06-11 21:36:04 -04:00
..
__tests__ 🚐 fix: Reuse Request-Scoped MCP Connections per Run (#13673) 2026-06-11 01:17:14 -04:00
Artifacts
Config
Endpoints 🚐 fix: Reuse Request-Scoped MCP Connections per Run (#13673) 2026-06-11 01:17:14 -04:00
Files
Runs
Skills 🧬 feat: Add GitHub Skill Sync (#13293) 2026-06-10 21:05:54 -04:00
start
Threads
Tools 🧊 fix: Inline-refresh OpenID session tokens at MCP OBO call time 2026-06-11 21:36:04 -04:00
ActionService.js
ActionService.spec.js
AssistantService.js
AuthService.js
AuthService.spec.js
cleanup.js
createRunBody.js
GraphApiService.js
GraphApiService.spec.js
GraphTokenService.js
initializeMCPs.js
initializeMCPs.spec.js
initializeOAuthReconnectManager.js
MCP.js 🧊 fix: Inline-refresh OpenID session tokens at MCP OBO call time 2026-06-11 21:36:04 -04:00
MCP.spec.js 🧊 fix: Inline-refresh OpenID session tokens at MCP OBO call time 2026-06-11 21:36:04 -04:00
MCPRequestContext.js 🚐 fix: Reuse Request-Scoped MCP Connections per Run (#13673) 2026-06-11 01:17:14 -04:00
OboPolicyService.js
OboTokenService.js
OboTokenService.spec.js
OpenIDSessionRefresh.js 🧊 fix: Inline-refresh OpenID session tokens at MCP OBO call time 2026-06-11 21:36:04 -04:00
OpenIDSessionRefresh.spec.js 🧊 fix: Inline-refresh OpenID session tokens at MCP OBO call time 2026-06-11 21:36:04 -04:00
PermissionService.js
PermissionService.spec.js
PluginService.js
systemGrant.spec.js
ToolService.js 🧊 fix: Inline-refresh OpenID session tokens at MCP OBO call time 2026-06-11 21:36:04 -04:00
twoFactorService.js