Skip to content

fix(auth): forward user-agent to oauth flow requests#2077

Open
mrutunjay-kinagi wants to merge 2 commits intomodelcontextprotocol:mainfrom
mrutunjay-kinagi:fix-1664-forward-user-agent-auth-flow
Open

fix(auth): forward user-agent to oauth flow requests#2077
mrutunjay-kinagi wants to merge 2 commits intomodelcontextprotocol:mainfrom
mrutunjay-kinagi:fix-1664-forward-user-agent-auth-flow

Conversation

@mrutunjay-kinagi
Copy link

Summary

  • forward caller User-Agent from the original MCP request into OAuth flow sub-requests
  • apply forwarding to PRM discovery, auth server metadata discovery, dynamic client registration, and token exchange/refresh requests
  • add regression coverage ensuring forwarded User-Agent is preserved throughout the 401 -> OAuth handshake path

Why

Fixes missing User-Agent propagation in Streamable HTTP auth flow requests, which can break environments that enforce WAF rules requiring User-Agent headers.

Closes #1664

Validation

  • pytest -q tests/client/test_auth.py -k "forwards_user_agent or auth_flow_with_no_tokens"
  • ruff check src/mcp/client/auth/oauth2.py tests/client/test_auth.py
  • ruff format --check src/mcp/client/auth/oauth2.py tests/client/test_auth.py

@mrutunjay-kinagi
Copy link
Author

Thanks for sharing this run.

I pushed a follow-up commit (40f173f) to address the failure pattern shown there:

  • removed a stale # pragma: no cover on tests/client/test_auth.py:48 that is now exercised by the new auth-flow test.

That was what caused Linux matrix failures in that run under strict-no-cover.

@mrutunjay-kinagi
Copy link
Author

Follow-up commit 40f173f addressed the previous Linux strict-no-cover failure, and all checks are now green.

Ready for maintainer review when you have bandwidth. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

User-Agent header in sHTTP transport is not forwarded to auth flow

1 participant