fix(mcp): plumb OAuth redirect host config - #21482
nocturnum91 wants to merge 1 commit into
Conversation
d841856 to
306d715
Compare
160064c to
275ba2f
Compare
Add loopback-only redirect_host handling for MCP OAuth callback URIs, including IPv6/localhost listener support and provider-local callback binding. Rebuild cached providers when OAuth config changes and invalidate stale dynamic client registrations whose redirect URIs no longer match. Tests: uv run --extra dev pytest tests/tools/test_mcp_oauth.py tests/tools/test_mcp_oauth_metadata.py -q
275ba2f to
fd6c270
Compare
teknium1
left a comment
There was a problem hiding this comment.
Thanks for addressing the redirect-host mismatch; current main still hard-codes 127.0.0.1 in the metadata, pre-registered-client, and listener paths (tools/mcp_oauth.py:655,849,876).
Problems
- The new handlers at
tools/mcp_oauth.py:594and:687do not retain current main's non-interactive fail-fast guards attools/mcp_oauth.py:557and:643(from755194ffe). Salvage must preserve those guards before printing an authorization URL or binding listeners. localhostis forced to bind both AF_INET and AF_INET6 (tools/mcp_oauth.py:155), then any failed family aborts the flow (:720-735). This breaks IPv4-only localhost hosts even when their resolver and browser use IPv4.- The callback replacement omits main's interactive paste-back fallback (
tools/mcp_oauth.py:667-683), which the MCP guide documents atwebsite/docs/user-guide/features/mcp.md:225-230.
Suggested changes
- Integrate the host/URI plumbing with the current guard and paste-back contracts intact.
- Select supported loopback families for
localhostand add IPv4-only coverage. - Document
oauth.redirect_hostand its accepted loopback values.
Automated hermes-sweeper review.
| into BOTH loopback families and bind both. Literal addresses | ||
| (``127.0.0.1`` / ``::1``) keep their single-family behavior. | ||
| """ | ||
| if bind_host == "localhost": |
There was a problem hiding this comment.
localhost is expanded to AF_INET6 unconditionally, while the later bind loop fails the entire flow if either family is unavailable. An IPv4-only host can resolve and use localhost successfully over IPv4; choose available resolved loopback families rather than making IPv6 mandatory.
|
|
||
| Opens the browser automatically when possible; always prints the URL | ||
| as a fallback for headless/SSH/gateway environments. | ||
| async def _redirect_handler_impl( |
There was a problem hiding this comment.
Please preserve current main's _raise_if_non_interactive(...) before this implementation prints an authorization URL or opens a browser. 755194ffe added that boundary guard for cached-but-unusable tokens in gateway/cron/background contexts.
|
|
||
| # The callback server is already running (started in build_oauth_auth). | ||
| # We just need to poll for the result. | ||
| async def _wait_for_callback_impl( |
There was a problem hiding this comment.
Carry forward the current interactive _paste_callback_reader race into this provider-local implementation. Main currently supports SSH users pasting the redirect URL when no tunnel is available, and the MCP guide documents that workflow.
What does this PR do?
Adds MCP OAuth redirect-host plumbing so configured loopback redirect hosts are reflected consistently in redirect URI generation and callback listener binding.
Related Issue
N/A.
Type of Change
Changes Made
oauth.redirect_hostplumbing for MCP OAuth redirect URIs.127.0.0.1,localhost,::1,[::1]).How to Test
Verification performed during refresh:
VERDICT: CLEAN.mainand updated with--force-with-lease.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passNote: I ran focused/regression tests locally for the changed MCP OAuth redirect-host behavior and am relying on GitHub Actions for the full matrix.
Documentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AFor New Skills
N/A — this PR does not add a skill.
Screenshots / Logs
N/A. Relevant verification is in local focused test output, Codex review logs, and GitHub Actions checks.