Skip to content

fix(mcp): support quoted and spaced MEDIA paths in attachment extraction#6742

Open
Dusk1e wants to merge 1 commit into
NousResearch:mainfrom
Dusk1e:fix/mcp-media-path-integrity
Open

fix(mcp): support quoted and spaced MEDIA paths in attachment extraction#6742
Dusk1e wants to merge 1 commit into
NousResearch:mainfrom
Dusk1e:fix/mcp-media-path-integrity

Conversation

@Dusk1e

@Dusk1e Dusk1e commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Problem

_extract_attachments() in mcp_serve.py uses a single-token regex
(MEDIA:\s*(\S+)) to extract attachment paths. This truncates or
malforms any path that contains spaces or is wrapped in quotes/backticks:

MEDIA: "C:\Users\\Desktop\my image.png"   → only captures `"C:\Users\\Desktop\my`
MEDIA: '/tmp/my image.png'                      → only captures `'/tmp/my`

This breaks attachments_fetch for valid Hermes outputs, especially on
Windows 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.py so _extract_attachments() no longer relies on
the single-token MEDIA:\s*(\S+) pattern. It now accepts:

  • Quoted paths ("..." and '...')
  • Backticked paths (`...`)
  • Unix absolute and tilde paths with spaces
  • Windows drive-letter paths with spaces

Extracted paths are normalized by trimming wrapping quotes/backticks and
trailing punctuation before being returned.

Why it matters

  • Real behavior bug, not a refactor.
  • Small and isolated to the MCP bridge.
  • Improves Windows compatibility.
  • Closes a consistency gap between gateway delivery parsing and MCP
    attachment parsing.

Tests

Added regression coverage in tests/test_mcp_serve.py:

  • Quoted Unix path with spaces: MEDIA: "/tmp/my image.png"
  • Quoted Windows path with spaces: MEDIA: "C:\Users\\Desktop\my image.png"
  • Backticked path: MEDIA: `/tmp/out file.mp3`
  • Trailing punctuation boundary: MEDIA: "/tmp/out.png", done
  • Existing simple-path behavior unchanged

Verification:

python -m pytest tests/test_mcp_serve.py -q
# Result: 44 passed, 39 skipped

Manual verification

  1. Call _extract_attachments() on text containing quoted MEDIA: paths
    with spaces and verify the full path is returned.
  2. Confirm existing plain MEDIA: /tmp/out.png behavior still works.
  3. Optionally run hermes mcp serve and verify attachments_fetch
    returns the full path for a message containing a quoted MEDIA: tag.

Files changed

  • mcp_serve.py — updated _extract_attachments() parser
  • tests/test_mcp_serve.py — added regression tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Medium — degraded but workaround exists tool/mcp MCP client and OAuth type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants