Preserve userinfo case in resource URLs#3008
Open
CodingFeng101 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
resource_url_from_server_url()now lowercases only the scheme and host when canonicalizing an RFC 8707 resource URL, while preserving userinfo and port and still removing fragments.Why
The docstring says the function lowercases the scheme/host. The previous implementation lowercased the whole
netloc, soHTTPS://User:PaSs@EXAMPLE.COM/path#fragmentbecamehttps://user:pass@example.com/path. Userinfo is part of the URI authority and can be case-sensitive, so host canonicalization should not alter it.Validation
uv run --frozen pytest tests/shared/test_auth_utils.py::test_resource_url_from_server_url_preserves_userinfo_case -q-> 1 passeduv run --frozen pytest tests/shared/test_auth_utils.py -q-> 16 passeduv run --frozen ruff check src/mcp/shared/auth_utils.py tests/shared/test_auth_utils.pyuv run --frozen pyright src/mcp/shared/auth_utils.py tests/shared/test_auth_utils.pygit diff --check -- src/mcp/shared/auth_utils.py tests/shared/test_auth_utils.pyI also attempted the full
./scripts/testflow.shis not available on this Windows host, so I ran the script's commands in PowerShell. The full run hit unrelated existing Windows/snapshot tooling failures intests/interaction/lowlevel/test_elicitation.py(ElicitRequest...snapshot expecting_metawhile the model exposesmeta) and a latercoverage jsontemp-config read error. The targeted checks for this change pass.