fix(mcp): extract text from EmbeddedResource content blocks in tool results - #13736
fix(mcp): extract text from EmbeddedResource content blocks in tool results#13736jpterry wants to merge 1 commit into
Conversation
|
I hit the same issue via QMD One small implementation note from the duplicate: I routed both normal and |
|
Is there anything I can do to move this along? |
…esults MCP tools that return file/document content (e.g. qmd's 'get' and 'multi_get') use EmbeddedResource blocks (type: 'resource') rather than TextContent blocks (type: 'text'). Per MCP spec §5.6.2, these nest their payload under block.resource.text (TextResourceContents) or block.resource.blob (BlobResourceContents). The tool result handler only checked for block.text, silently dropping EmbeddedResource blocks and returning empty strings to the agent. Changes: - tools/mcp_tool.py: add elif branch in _make_tool_handler's content extraction loop to handle block.resource.text and block.resource.blob - tests/tools/test_mcp_tool.py: add three tests covering text resources, binary blob resources, and mixed TextContent + EmbeddedResource results Discovered via @tobilu/qmd MCP server (v2.1.0) whose get/multi_get tools return EmbeddedResource blocks for document retrieval.
b7883f7 to
ec162ee
Compare
|
Updated branch to address conflicts. Can this PR be approved to run the CI checks? |
|
#31356 looks like a more complete fix than this one. |
What does this PR do?
MCP tools that return file/document content use
EmbeddedResourcecontent blocks (type: "resource") where the text payload lives atblock.resource.text(per MCP spec §5.6.2 — Tool Result Content). The tool result handler in_make_tool_handleronly checked forblock.text(which exists onTextContentblocks), silently droppingEmbeddedResourceblocks and returning empty strings to the agent.Discovered via the
@tobilu/qmdMCP server (v2.1.0), whosegetandmulti_gettools returnEmbeddedResourceblocks for document retrieval. Any MCP server returning resource-type content blocks would hit the same issue.Type of Change
Changes Made
tools/mcp_tool.py: Addedelif hasattr(block, "resource")branch in_make_tool_handler's content extraction loop to handleblock.resource.text(TextResourceContents) andblock.resource.blob(BlobResourceContents)tests/tools/test_mcp_tool.py: Added three tests:test_embedded_resource_text— EmbeddedResource with text contenttest_embedded_resource_blob— binary blob produces placeholdertest_mixed_text_and_embedded_resource— mixed TextContent + EmbeddedResourceHow to Test
EmbeddedResourcecontent blocks (e.g.@tobilu/qmdv2.1.0 withgettool)mcp_qmd_get)Or run the unit tests:
pytest tests/tools/test_mcp_tool.py -q(169 pass, 3 new)Checklist
Code
pytest tests/ -qpasses (169 MCP tool tests)Documentation & Housekeeping