Repository navigation
fix(mcp): percent-encode filenames in embedded resource URIs - #3706
Open
BichengWang wants to merge 1 commit into
Open
BichengWang wants to merge 1 commit into
BichengWang wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Why are these changes needed?
reply_to_contentmaps a generated file that is not an image or audio to anEmbeddedResourcewhose URI is built asresource://{file.name}, with the raw filename (metadata["filename"]). A name with a space,#,?or/produces a URI that is invalid or that parses into the wrong parts:my report.pdf->resource://my report.pdf(space in the URI)a#b?.pdf->urlsplitgives hosta, fragmentb?.pdfdir/a b.pdf-> hostdir, path/a b.pdfThe filename is now percent-encoded (
urllib.parse.quote(name, safe="")), so the whole name stays one URI component and decodes back to the original. Names that were already URI-safe are unchanged.Related issue number
None.
Checks
AI assistance
Validation run:
test_embedded_resource_uri_keeps_filename_intactin test/mcp/test_content_mapping.py: failed before the fix (3 of 4 cases: space,#?,/), passes after.pytest test/mcp: 579 passed.ruff checkandruff format --checkon ag2/mcp and test/mcp: clean.