fix: preserve OAuth authorization endpoint query params#2787
Conversation
966555b to
fd42072
Compare
fd42072 to
d606a76
Compare
|
The remaining red job is This PR only changes the OAuth redirect query handling and its targeted auth tests; the same workflow has the other Python/OS matrix entries passing. I am treating this one as unrelated/flaky unless maintainers see a link I missed. |
|
Closing this older OAuth query-parameter fix in favor of #2829. #2829 covers the same authorization-endpoint behavior on the same client auth path, keeps the existing endpoint query parameters, adds the targeted regression test, and is currently green across the matrix. Keeping both open would split review over duplicate fixes. |
Fixes #2776.
Summary
The OAuth authorization URL builder always appended SDK parameters with a literal
?:f"{auth_endpoint}?{urlencode(auth_params)}"That breaks authorization servers whose metadata already includes endpoint-level query parameters. Salesforce sandbox auth endpoints are one example:
The generated URL became
...?prompt=select_account?response_type=..., so the OAuth parameters were folded into the existingpromptvalue instead of being sent as query parameters.This change parses the endpoint query first, preserves existing parameters, and appends the SDK-generated OAuth parameters with normal form encoding.
Validation
PYTHONPATH=src python -m pytest tests/client/test_auth.py -q -k authorization_endpoint_preserves_existing_queryPYTHONPATH=src python -m pytest tests/client/test_auth.py -qpython -m py_compile src/mcp/client/auth/oauth2.py tests/client/test_auth.pypython -m ruff check src/mcp/client/auth/oauth2.py tests/client/test_auth.pygit diff --check upstream/main..HEADI also tried
python -m pyright src/mcp/client/auth/oauth2.py tests/client/test_auth.py, but the local run failed on pre-existing environment/type-resolution issues intests/client/test_auth.pybefore isolating this patch.