Title: fix(client): preserve existing query params on OAuth authorization_endpoint by Bartok9 · Pull Request #2779 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: fix(client): preserve existing query params on OAuth authorization_endpoint by Bartok9 · Pull Request #2779 · modelcontextprotocol/python-sdk
X Title: fix(client): preserve existing query params on OAuth authorization_endpoint by Bartok9 · Pull Request #2779 · modelcontextprotocol/python-sdk
Description: Summary The OAuth authorization-code grant now preserves any query parameters already present on the server-advertised authorization_endpoint instead of producing a malformed double-? URL. User-facing impact: clients can complete OAuth against servers whose authorization_endpoint carries query params (e.g. Salesforce's .../authorize?prompt=select_account). Motivation Closes #2776. _perform_authorization_code_grant built the redirect URL with: authorization_url = f"{auth_endpoint}?{urlencode(auth_params)}" When the server's authorization_endpoint already has a query string, this yields an invalid URL with two ? separators. The reporter's real-world example: Salesforce advertises https://test.salesforce.com/services/oauth2/authorize?prompt=select_account The client then navigated to ...authorize?prompt=select_account?response_type=code&... — the second ? is invalid, so the existing prompt param is swallowed into the value and the request is rejected. Root cause Blind string concatenation of ? + encoded params, with no handling for a pre-existing query component on the endpoint. Fix New _build_authorization_url(auth_endpoint, auth_params) helper: urlparse the endpoint, merge its existing query (parse_qsl) with the flow-generated auth_params, then urlunparse back into a single well-formed query string. Flow-generated params win on key conflicts (the client's response_type, state, PKCE challenge, etc. are authoritative). None-valued params are dropped rather than serialized as the literal string "None" (preserves prior effective behavior; keeps the signature type-correct as Mapping[str, str | None]). Diff: 2 files, +103/-3. Tests Added TestAuthorizationEndpointWithQuery in tests/client/test_auth.py: test_build_authorization_url_no_existing_query — baseline, single ?. test_build_authorization_url_preserves_existing_query — the #2776 Salesforce case; server prompt survives alongside flow params, exactly one ?. test_build_authorization_url_flow_params_win_on_conflict — precedence rule. test_perform_authorization_preserves_endpoint_query — end-to-end through _perform_authorization_code_grant, asserting the captured redirect URL is well-formed. Verification uv run pytest tests/client/test_auth.py — 100 passed, 1 xfailed uv run pyright src/mcp/client/auth/oauth2.py — 0 errors uv run ruff format / ruff check — clean Did NOT change any unrelated behavior; flow param precedence and None handling preserve the previous effective output for endpoints without a query string.
Open Graph Description: Summary The OAuth authorization-code grant now preserves any query parameters already present on the server-advertised authorization_endpoint instead of producing a malformed double-? URL. User-fa...
X Description: Summary The OAuth authorization-code grant now preserves any query parameters already present on the server-advertised authorization_endpoint instead of producing a malformed double-? URL. User-fa...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/2779
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:42c193d8-7bc2-aa33-ceb5-3ab7c42f20bf |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A036:17A656:1428041:1A929C1:6A5C5907 |
| html-safe-nonce | 3d55296c7d0ea3b730fa07f03486950e1eee8b5c4c5bca0acb900f01e6becbe6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDM2OjE3QTY1NjoxNDI4MDQxOjFBOTI5QzE6NkE1QzU5MDciLCJ2aXNpdG9yX2lkIjoiMTU4NjAzNDI2MzQ0NzA2Njg4NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ddfb0600920eb559e3cf5da85e37adf970f968870c1f1cda916cca09e40b90da |
| hovercard-subject-tag | pull_request:3800890238 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/modelcontextprotocol/python-sdk/pull/2779/files |
| twitter:image | https://avatars.githubusercontent.com/u/259807879?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/259807879?s=400&v=4 |
| og:image:alt | Summary The OAuth authorization-code grant now preserves any query parameters already present on the server-advertised authorization_endpoint instead of producing a malformed double-? URL. User-fa... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width