python-sdk
python-sdk copied to clipboard
Extract reusable OAuth authorization redirect builder
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 needingredirect_handler/callback_handler - keeps
OAuthClientProviderbehavior 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 -quv 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-coveruv run --frozen ruff format --check src/mcp/client/auth/oauth2.py src/mcp/client/auth/__init__.py tests/client/test_auth.pyuv run --frozen ruff check src/mcp/client/auth/oauth2.py src/mcp/client/auth/__init__.py tests/client/test_auth.pyuv 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.