From 7c71d6dc1a582801dafe4e40bfc68b37cd081cd1 Mon Sep 17 00:00:00 2001 From: Dustin Healy <54083382+dustinhealy@users.noreply.github.com> Date: Wed, 19 Aug 2026 11:21:39 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=82=20fix:=20Preserve=20OpenID=20Re-Au?= =?UTF-8?q?th=20Errors=20Through=20MCP=20Tool=20Error=20Classification=20(?= =?UTF-8?q?#15010)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The MCP tool-call catch block classifies errors by message substring, so an OpenIDReauthRequiredError raised during header resolution was rewritten into an MCP OAuth configuration prompt and its class identity discarded. The typed error now passes through ahead of the heuristic, so the actionable re-authentication message reaches the caller intact. --- api/server/services/MCP.js | 6 +++++ api/server/services/MCP.spec.js | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/api/server/services/MCP.js b/api/server/services/MCP.js index d00b4053d3..0c351996fa 100644 --- a/api/server/services/MCP.js +++ b/api/server/services/MCP.js @@ -35,6 +35,7 @@ const { hasRuntimeUrlPlaceholders, containsGraphTokenPlaceholder, isOAuthServer, + OpenIDReauthRequiredError, } = require('@librechat/api'); const { Time, @@ -1125,6 +1126,11 @@ function createToolInstance({ error, ); + /** Carries the actionable re-auth message; the substring heuristic below would misreport it as an OAuth configuration problem */ + if (error instanceof OpenIDReauthRequiredError) { + throw error; + } + /** OAuth error, provide a helpful message */ const isOAuthError = error.message?.includes('401') || diff --git a/api/server/services/MCP.spec.js b/api/server/services/MCP.spec.js index c03d0e8902..976e6f81e8 100644 --- a/api/server/services/MCP.spec.js +++ b/api/server/services/MCP.spec.js @@ -1642,6 +1642,54 @@ describe('User parameter passing tests', () => { ); }); + it('preserves OpenIDReauthRequiredError through the OAuth error classification', async () => { + const { OpenIDReauthRequiredError } = require('@librechat/api'); + const mockUser = { id: 'reauth-user', role: 'USER' }; + const mockRes = { write: jest.fn(), flush: jest.fn() }; + const { getRoleByName } = require('~/models'); + getRoleByName.mockResolvedValue({ + permissions: { + [PermissionTypes.MCP_SERVERS]: { + [Permissions.USE]: true, + }, + }, + }); + const reauthError = new OpenIDReauthRequiredError( + 'OpenID token is expired or unavailable; re-authentication is required to resolve {{LIBRECHAT_OPENID_ACCESS_TOKEN}}.', + ); + mockGetMCPManager.mockReturnValue({ + callTool: jest.fn().mockRejectedValue(reauthError), + }); + + const mcpTool = await createMCPTool({ + res: mockRes, + user: mockUser, + config: { requiresOAuth: false }, + toolKey: `test-tool${D}test-server`, + provider: 'openai', + userMCPAuthMap: {}, + availableTools: { + [`test-tool${D}test-server`]: { + function: { + description: 'Cached tool', + parameters: { type: 'object', properties: {} }, + }, + }, + }, + }); + + await expect( + mcpTool.invoke( + {}, + { + configurable: { user: mockUser }, + metadata: { provider: 'openai', thread_id: 'thread-1', run_id: 'run-1' }, + toolCall: {}, + }, + ), + ).rejects.toBe(reauthError); + }); + it('does not label OBO authentication failures as unconfigured MCP OAuth', async () => { const mockUser = { id: 'obo-user', role: 'USER' }; const mockRes = { write: jest.fn(), flush: jest.fn() };