Bind MCP OAuth handlers per provider - #44607
Conversation
|
Verification review — reviewed this PR's diff (per-provider OAuth handler closures for MCP). What I checked:
Verdict: Clean. The closure-over-port pattern correctly prevents concurrent OAuth flows from interfering with each other's SSH hint messages and callback listeners. |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for isolating the mutable callback-port race with per-provider closures. Current main still has that race: _configure_callback_port() writes _oauth_port at tools/mcp_oauth.py:828-832, and both construction paths pass global-reading handlers (tools/mcp_oauth.py:945-946; tools/mcp_oauth_manager.py:544-555).
Problems
- The new redirect factory starts at
tools/mcp_oauth.py:402without current main's_raise_if_non_interactive(...)boundary guard (tools/mcp_oauth.py:557). - The callback factory binds at
tools/mcp_oauth.py:464without current main's pre-bind guard (tools/mcp_oauth.py:643). Those protections were added in755194ffe9a117c70a81505ecf4cade1fbc5af26; applying this June snapshot would regress background OAuth fail-fast behavior.
Suggested changes
- Salvage the closures into the current guarded handlers, keeping both guards inside the factory-produced handlers.
- Update the closure tests to assert no URL/browser/listener activity for non-interactive flows, alongside the closed-over-port assertions.
Automated hermes-sweeper review.
| file=sys.stderr, | ||
| def _make_redirect_handler(callback_port: int | None): | ||
| """Return a redirect handler bound to one OAuth flow's callback port.""" | ||
| async def _handler(authorization_url: str) -> None: |
There was a problem hiding this comment.
Please preserve current main's _raise_if_non_interactive(...) guard inside this factory before URL output or browser launch. The equivalent current handler guards at tools/mcp_oauth.py:557 (commit 755194ffe); omitting it reintroduces background OAuth flows that cannot be completed.
|
Resolved on main via PR #65622, which merged the same per-provider closure approach (salvaged from #44872, with #5345 by @caseyg as the earliest submission — all credited). Thanks for the contribution @LeonSGP43! |
Summary
Closes #44588