feat(mcp): add browser OAuth for remote servers - #5316
Merged
Conversation
chengyongru
force-pushed
the
codex/mcp-oauth
branch
2 times, most recently
from
August 10, 2026 08:38
7a6da99 to
fedc6ee
Compare
chengyongru
force-pushed
the
codex/mcp-oauth
branch
from
August 10, 2026 10:24
db80aff to
f518559
Compare
Collaborator
Author
|
ux待优化, 但是这个pr已经不适合再扩张了 |
This was referenced Aug 11, 2026
fuutott
added a commit
to fuutott/nanobot
that referenced
this pull request
Aug 14, 2026
…actor, exec/security hardening Absorbed from HKUDS/nanobot (b3b0517..221e8a4): - feat(mcp) HKUDS#5316: native browser OAuth for remote MCP servers (mcp_oauth.py + webui/mcp_oauth_api.py; auth: "oauth" marker; MCP SDK OAuthClientProvider). - refactor HKUDS#5343: move MCP lifecycle out of AgentLoop into an MCPProvider; from_config now takes a caller-owned tool_registry; close_mcp -> aclose. - Security: exec.allowPatterns shell-chain bypass fix, exec path-guard hardening (double-slash / redirection / named-user home), Docker privilege-drop hardening, stop leaking API keys into subprocess env, web credential-URL redaction (keep creds out of logs / Jina reader / SW caches). - WebUI: tabbed pane workbench (HKUDS#5322), MCP management dialog, PWA support, native folder picker, settings split by domain (HKUDS#5323), session drag polish. - Providers: DeepSeek V4 Pro Responses; gemini tool-history across model switch. - Session: history stored outside workspace, symlink-migration rejection, storage relocation. Local customisations — MCP OAuth now COEXISTS with upstream's native flow (upstream is browser-only; our fork keeps the headless path for containers): - schema.py: unified auth field to `OAuthConfig | Literal["oauth"] | None` ("oauth" -> upstream browser flow; OAuthConfig object -> our headless device_code/client_credentials). - mcp.py: re-applied _resolve_oauth_token bearer injection inside upstream's new open_single_server, selected by auth-type; upstream's oauth_auth httpx.Auth handles the "oauth" marker. request_headers now also feeds streamableHttp. - loop.py: _oauth_refresh_loop reads self.tools_config.mcp_servers (post-HKUDS#5343 self._mcp_servers is gone), gated to isinstance(cfg.auth, OAuthConfig); kept our from_config subagent factory + tool_registry param together. - Dropped orphaned fork reload_single_server (its module-level deps were removed by HKUDS#5343); the refresh loop now refreshes tokens on disk and the live session picks them up on next reconnect (reactive, matching upstream). Removed its two fork tests; fixed test_oauth_refresh_task to use tools_config. - docker-compose.yml: kept SYS_ADMIN + unconfined apparmor/seccomp for the bubblewrap sandbox (upstream's no-new-privileges model breaks bwrap; we run as nanobottie via direct USER, not upstream's entrypoint drop). - conftest.py: kept fork plugin-path setup alongside upstream's session isolation fixture. strip_history / web exclusive-timeout / utf-8-sig / mcp_auth CLI / plugin channels all preserved. Verified: ruff clean; host sweep ~4270 passed. One expected Windows-only failure (test_equivalent_workspace_paths_share_one_store: WinError 1314 on an unguarded symlink() in a new upstream test — passes on Linux). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.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
config.jsonand hot-reload tools after authorizationUX
The primary flow is Apps -> MCP -> Connect -> provider consent.
load, and presents one field for pasting the complete URL from the browser address bar; users do
not need to identify or extract the authorization code
closes the OAuth popup
no longer mistaken for closed popups
from 320px upward; wider two-column layouts only activate when the settings pane has enough usable
width
implementation-detail notices
while unrelated or genuine connection failures remain visible
Security and compatibility
consuming the one-use state
or unauthenticated HTTP mutation
request with the existing SSRF guard and pinned DNS transport
returns tokens in WebUI payloads
without explicit headers
Verification
153 passed— MCP OAuth, MCP tool, preset, settings route, and WebSocket HTTP regression tests986 passed— complete WebUI test suitebasedpyright— 0 errors, 0 warnings, 0 notesruff checkandbun run lint— passedbun run build— passedsuppression of the expected pre-authorization reload failure, and no horizontal overflow at 320px
or desktop width; browser console remained at 0 errors and 0 warnings
nanobot logo and project website
The live smoke tests intentionally stopped before third-party account consent. Callback exchange,
persistence, reconnect, expiry, cancellation, and hot-reload paths are covered by deterministic tests.
Closes #5297