fix(auth): forward User-Agent header to OAuth discovery and flow requests (#3531)
Closed
TH
2mo ago+26+26+01234567890123456789-0-0-0123456789
Description
When OAuthClientProvider (via RedirectAwareAuth) issues OAuth metadata discovery and registration requests, they are sent as bare httpx2.Request instances that do not go through client.build_request(). Consequently, these requests omit the User-Agent header.
When interacting with MCP servers protected by WAFs (such as Cloudflare bot protection), user-agent-less requests are rejected with 403 Forbidden, causing the OAuth flow to fail.
This PR forwards the User-Agent header from the authenticated request to intermediate auth flow requests if not already set.
Closes #3531
Verification
- Added unit test
test_auth_flow_forwards_user_agent_headerintests/client/test_auth.py. - Ran
pytest tests/client/test_auth.py(all 161 tests passed). - Checked formatting and lint with
ruff checkandruff format.