Skip to content

Extract reusable OAuth authorization redirect builder#2856

Draft
maxpetrusenkoagent wants to merge 1 commit into
modelcontextprotocol:mainfrom
maxpetrusenkoagent:hermes/oss-pr-2026-06-13-mcp-python-sdk-1743
Draft

Extract reusable OAuth authorization redirect builder#2856
maxpetrusenkoagent wants to merge 1 commit into
modelcontextprotocol:mainfrom
maxpetrusenkoagent:hermes/oss-pr-2026-06-13-mcp-python-sdk-1743

Conversation

@maxpetrusenkoagent

Copy link
Copy Markdown

Summary

Fixes #1743.

Extracts the reusable OAuth authorization redirect step from OAuthClientProvider into a public helper for proxy/server-side use cases:

  • adds OAuthAuthorizationRedirect, a resumable authorization redirect result containing the authorization URL, OAuth state, and PKCE verifier
  • adds build_authorization_redirect(...) so callers can build and persist the browser redirect step without needing redirect_handler / callback_handler
  • keeps OAuthClientProvider behavior routed through the new helper
  • preserves existing authorization endpoint query parameters and hides the PKCE verifier from repr(...)

Verification

  • uv run --frozen pytest tests/client/test_auth.py tests/interaction/auth/test_flow.py -q
  • uv run --frozen coverage erase && uv run --frozen coverage run -m pytest tests/client/test_auth.py tests/interaction/auth/test_flow.py && uv run --frozen coverage combine && uv run --frozen coverage report --include='src/mcp/client/auth/oauth2.py,src/mcp/client/auth/__init__.py' --fail-under=0 && UV_FROZEN=1 uv run --frozen strict-no-cover
  • uv run --frozen ruff format --check src/mcp/client/auth/oauth2.py src/mcp/client/auth/__init__.py tests/client/test_auth.py
  • uv run --frozen ruff check src/mcp/client/auth/oauth2.py src/mcp/client/auth/__init__.py tests/client/test_auth.py
  • uv run --frozen pyright src/mcp/client/auth/oauth2.py src/mcp/client/auth/__init__.py tests/client/test_auth.py
  • ./scripts/test → 1786 passed, 5 skipped, 1 xfailed, 100.00% coverage, strict-no-cover clean

Review

Local autoreview found no blocking issues. It suggested preserving existing authorization endpoint query parameters and hiding the PKCE verifier in repr; both are included and covered by regression tests.

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.

Extract OAuth flow logic into reusable components for proxy use cases

1 participant