mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 19:08:59 -05:00
[PR #22341] fix: surface OAuth auth prompt for default MCP tools via toast + popup #26621
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/22341
Author: @MedlockM
Created: 3/6/2026
Status: 🔄 Open
Base:
dev← Head:fix/mcp-oauth-default-tools-and-token-refresh📝 Commits (4)
d20fcderefactor: simplify MCP OAuth 2.1 401 detection in middleware3c1c4e1refactor: simplify MCP OAuth callback redirect logic0420874refactor: remove dead code from OAuth popup flow6fe57a8Merge branch 'dev' into fix/mcp-oauth-default-tools-and-token-refresh📊 Changes
6 files changed (+153 additions, -5 deletions)
View changed files
📝
backend/open_webui/main.py(+6 -0)📝
backend/open_webui/utils/mcp/client.py(+3 -2)📝
backend/open_webui/utils/middleware.py(+34 -0)📝
backend/open_webui/utils/oauth.py(+9 -2)📝
src/lib/components/chat/Chat.svelte(+91 -1)📝
src/routes/+layout.svelte(+10 -0)📄 Description
Problem
Two issues identified in #20858:
No pre-flight check: Users have no way to know that one of their default OAuth 2.1 tools is not yet authenticated. The chat silently fails with "Failed to connect to MCP server" and no prompt to authorize.
No mid-session reauth: If a refresh token expires for any reason during a conversation, the pre-flight check cannot catch it. There is currently no mechanism to re-authenticate without leaving the chat.
Out of scope: This PR does not address the API/headless path (raised by @jk-f5 in #20858) — when OAuth 2.1 MCP tools are called programmatically without a browser UI. That scenario requires a different approach and should be handled in a separate PR.
Solution
Pre-flight toast (before sending a message):
Mid-session reauth toast (during a conversation):
Pull Request Checklist
devBannercomponent,periodic_*task pattern,get_sessions_by_user_idpattern)devfix:Testing
Tested against 4 OAuth 2.1 MCP servers (Atlassian, Zapier, Notion, Linear).
Changelog Entry
Fixed
src/lib/components/chat/Chat.svelteoauth_reauth_toasthandler, OAuth popup storage listenersrc/routes/+layout.sveltebackend/open_webui/utils/middleware.pyoauth_reauth_toasteventbackend/open_webui/utils/mcp/client.pydisconnect()fixbackend/open_webui/utils/oauth.pyreturn_urlparameter inhandle_callbackfor popup redirectbackend/open_webui/main.pyreturn_urlthrough authorize/callback endpointsScreenshots or Videos
Video of the pre-flight oauth process
Capture vidéo du 2026-03-13 19-57-15.webm
Video of the mid-session oauth process
Capture vidéo du 2026-03-13 18-39-58.webm
Multiple unauthenticated tools — stacked toasts:

Credit
Approach inspired by @Lemmons ' interrupt-based flow from their branch. Simplified to use toasts instead of modal dialogs, and duck-typed 401 detection instead of a custom exception class.
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.