modelcontextprotocol / modelcontextprotocol/python-sdk

OAuth handler doesn't support redirect URLs with params

Open Beginner friendly
#2,776 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auth bug P2
Dominant language
Python
Stars
24.3k
Forks
4k
Avg merge
1d 1h
Merged PRs (30d)
31

Description

Initial Checks
Description

The oauth redirect handler uses the following logic (https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/client/auth/oauth2.py#L356-L357) to attach parameters to the redirect URL supplied by the server:

        authorization_url = f"{auth_endpoint}?{urlencode(auth_params)}"
        await self.context.redirect_handler(authorization_url)

Unfortunately, this breaks if the auth_endpoint supplied by the server already has URL parameters. For example, at https://api.salesforce.com/.well-known/oauth-authorization-server/platform/mcp/v1/sandbox/platform/sobject-all you can see that the salesforce mcp server has an authorization endpoint of https://test.salesforce.com/services/oauth2/authorize?prompt=select_account.

The end result is that the client tries to visit a URL that loooks like https://test.salesforce.com/services/oauth2/authorize?prompt=select_account?response_type=code&..., which is incorrect.

Example Code

Python & MCP Python SDK
python3 3.13.2
mcp 1.27.2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/mcp/client/auth/oauth2.py at lines 356-357, where the authorization URL is assembled before redirect_handler is called. Check how the server-provided endpoint and authorization parameters are joined. Done means endpoints that already contain query parameters produce a valid URL with both the existing and newly added parameters.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
authentication
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.