fix(mcp): support quoted and spaced MEDIA paths in attachment extraction#6742
Open
Dusk1e wants to merge 1 commit into
Open
fix(mcp): support quoted and spaced MEDIA paths in attachment extraction#6742Dusk1e wants to merge 1 commit into
Dusk1e wants to merge 1 commit into
Conversation
This was referenced May 5, 2026
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.
Problem
_extract_attachments()inmcp_serve.pyuses a single-token regex(
MEDIA:\s*(\S+)) to extract attachment paths. This truncates ormalforms any path that contains spaces or is wrapped in quotes/backticks:
This breaks
attachments_fetchfor valid Hermes outputs, especially onWindows where file paths commonly include spaces.
This is distinct from the earlier fix in
gateway/platforms/base.py:the gateway path extraction was already hardened there, but the MCP
bridge still had the older, narrower parser.
What changed
Updated
mcp_serve.pyso_extract_attachments()no longer relies onthe single-token
MEDIA:\s*(\S+)pattern. It now accepts:"..."and'...')`...`)Extracted paths are normalized by trimming wrapping quotes/backticks and
trailing punctuation before being returned.
Why it matters
attachment parsing.
Tests
Added regression coverage in
tests/test_mcp_serve.py:MEDIA: "/tmp/my image.png"MEDIA: "C:\Users\\Desktop\my image.png"MEDIA: `/tmp/out file.mp3`MEDIA: "/tmp/out.png", doneVerification:
Manual verification
_extract_attachments()on text containing quotedMEDIA:pathswith spaces and verify the full path is returned.
MEDIA: /tmp/out.pngbehavior still works.hermes mcp serveand verifyattachments_fetchreturns the full path for a message containing a quoted
MEDIA:tag.Files changed
mcp_serve.py— updated_extract_attachments()parsertests/test_mcp_serve.py— added regression tests