Skip to content

fix(mcp): MCP OAuth broken - PEP 525 generator delegation bug (#12400) - #12409

Closed
vominh1919 wants to merge 1 commit into
NousResearch:mainfrom
vominh1919:fix/12400-mcp-oauth-pep525
Closed

fix(mcp): MCP OAuth broken - PEP 525 generator delegation bug (#12400)#12409
vominh1919 wants to merge 1 commit into
NousResearch:mainfrom
vominh1919:fix/12400-mcp-oauth-pep525

Conversation

@vominh1919

Copy link
Copy Markdown
Contributor

Problem

MCP OAuth is broken because async for item in super().async_auth_flow(request): yield item does not forward asend() values back to the inner generator.

This is a known PEP 525 limitation — the async for ... in iteration protocol does not support bidirectional communication. The MCP SDK's OAuthClientProvider.async_auth_flow (built on httpx.Auth) uses asend() to receive the HTTP response from the caller. Without manual forwarding, the inner generator silently receives None, breaking token exchange and refresh.

Fix

Replace the async for ... yield delegation with explicit bidirectional forwarding that properly handles asend(), athrow(), and aclose().

Files Changed

  • tools/mcp_oauth_manager.pyHermesMCPOAuthProvider.async_auth_flow method (lines 128-130 → bidirectional forwarding pattern)

Closes #12400

…ync_auth_flow

The plain 'async for item in super().async_auth_flow(request): yield item'
pattern does NOT forward asend() values back to the inner generator due to
a PEP 525 limitation.  The MCP SDK's auth flow (httpx.Auth flow) expects
the caller to asend() the HTTP response back in, so without manual
forwarding the flow silently receives None and OAuth token exchange /
refresh breaks.

Fixes NousResearch#12400
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists tool/mcp MCP client and OAuth labels Apr 23, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely stale — #12717 (merged) already fixed the same MCP OAuth bidirectional auth_flow issue. Please verify this is still needed.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the thorough write-up and the correct diagnosis of the PEP 525 limitation, @vominh1919!

This is an automated hermes-sweeper review. After verifying against current main, this PR is superseded:

The fix is already live on main. Closing as implemented.

@teknium1 teknium1 closed this Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Medium — degraded but workaround exists tool/mcp MCP client and OAuth type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: MCP OAuth broken for all servers — NoneType has no status_code in HermesMCPOAuthProvider.async_auth_flow

3 participants