Skip to content

fix(mcp): extract EmbeddedResource content blocks from tool results - #50999

Closed
kingofkillers91 wants to merge 1 commit into
NousResearch:mainfrom
kingofkillers91:fix/mcp-embedded-resource-content
Closed

kingofkillers91 wants to merge 1 commit into
NousResearch:mainfrom
kingofkillers91:fix/mcp-embedded-resource-content

Conversation

@kingofkillers91

Copy link
Copy Markdown

Problem

MCP servers that return type="resource" content blocks (EmbeddedResource in the MCP SDK) have their results silently dropped by Hermes' MCP client. The client only extracts text from TextContent and ImageContent blocks, ignoring EmbeddedResource blocks entirely.

Affected tools: GitHub MCP get_file_contents (v1.4.0+), Playwright MCP, filesystem servers, and any MCP server that embeds file content as resource blocks.

Symptom: get_file_contents returns "successfully downloaded text file (SHA: ...)" — the metadata text block — but the actual file content in the resource block is dropped. The agent sees an empty result.

Root Cause

tools/mcp_tool.py extracts content from tool results in three places, all using hasattr(block, "text") only:

  1. Main tool result loop (~line 3194) — iterates result.content, extracts .text and image blocks, drops everything else
  2. Error text extraction (~line 3174) — same pattern for error responses
  3. _extract_tool_result_text() (~line 909) — extracts text from ToolResultContent blocks, same gap

The MCP spec defines EmbeddedResource with type="resource" where the payload lives at .resource.text (or .resource.blob for binary). These blocks have no top-level .text attribute.

Fix

Patch all three extraction points to also check for hasattr(block, "resource") and extract .resource.text:

# Added before the image_tag fallback:
if hasattr(block, "resource"):
    resource = block.resource
    if hasattr(resource, "text") and resource.text:
        parts.append(resource.text)
        continue

Verification

Before patch:

mcp_github_get_file_contents → {"result": "successfully downloaded text file (SHA: abc123)"}

After patch (tested with GitHub MCP v1.4.0):

mcp_github_get_file_contents → {"result": "successfully downloaded text file (SHA: abc123)\ninterface:\n  display_name: \"Loop Library\"..."}

Content from the resource block is now included alongside the metadata text.

Related

MCP servers (e.g. GitHub MCP v1.4.0 get_file_contents) return file content
as type="resource" blocks with the payload in .resource.text, not as
type="text" blocks. Hermes was silently dropping these, producing empty
results like "successfully downloaded text file" with no actual content.

Patch all three extraction points in tools/mcp_tool.py:
1. Main tool result loop (~line 3194) — extract .resource.text before
   falling through to image handling
2. Error text extraction (~line 3174) — same treatment for error blocks
3. _extract_tool_result_text() (~line 909) — handle resource blocks in
   tool result content items

Fixes NousResearch#30601
Signed-off-by: kingofkillers91
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists tool/mcp MCP client and OAuth duplicate This issue or pull request already exists labels Jun 22, 2026
@alt-glitch

Copy link
Copy Markdown
Contributor

Duplicate of #31356 — same MCP EmbeddedResource (type=resource) text-extraction fix in tools/mcp_tool.py. #31356 is the canonical open PR for this; prior duplicates: #13736, #18118, #3655 (all closed), originating issue #26972. The fix here is the same resource.text extraction gap. Marking duplicate of the canonical open PR.

@teknium1

Copy link
Copy Markdown
Collaborator

This is now fixed on main via PR #64556 (salvaged from #64061, which materializes binary blobs to the document cache and covers ResourceLink/Audio in addition to embedded resource text). Your fix addressed the same underlying bug — thanks for the contribution, and sorry we couldn't take this one; five PRs ended up targeting the same dropped-resource-block issue.

@teknium1 teknium1 closed this Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists 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.

MCP tool results with EmbeddedResource (resource) blocks are silently dropped

3 participants