Repository navigation
Description
Summary
When a backend tool result has no structuredContent, vMCP synthesizes one from the content array via conversion.ContentArrayToMap and forwards it to the client. For embedded resources (type: "resource" with blob), this copies the full base64 payload into structuredContent.resource. Clients that show structuredContent to the model (e.g. Claude Code) then put the whole base64 file into the model context, although the client already handles the resource itself (Claude Code saves it as a file and shows only the path).
Steps to reproduce
- Backend MCP server whose tool returns a file as an embedded resource, without
structuredContent, e.g.:(We hit this with{"content": [ {"type": "text", "text": "{\"name\":\"f.xlsx\",\"contentType\":\"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\"size\":11379}"}, {"type": "resource", "resource": {"uri": "file:///f.xlsx", "mimeType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "blob": "<base64>"}} ]}@softeria/ms-365-mcp-serverandMS365_MCP_BLOB_OUTPUT=true, toolsdownload-bytes/get-mail-attachment-content.) - Call the tool through vMCP (v0.66.0) from Claude Code.
Expected
The client receives the resource; structuredContent is either absent or does not duplicate the binary payload. With a local stdio test server returning the same result shape (no vMCP in between), Claude Code stores the file and the model sees only [Resource from …] Binary content (…) saved to <path>.
Actual
The client also receives structuredContent: {"text": "...", "resource": "<full base64>"}. In Claude Code the model sees the base64 in the tool result; for larger files the result exceeds the output limit and is stored a second time as a ~1.33× larger .txt.
Code
pkg/vmcp/conversion/content.go,ContentArrayToMap: first resource →result["resource"] = item.Datafor blob resources.- Called when the backend has no
structuredContentinpkg/vmcp/session/internal/backend/mcp_session.goandpkg/vmcp/client/client.go; forwarded inpkg/vmcp/server/serve_handlers.go(StructuredContent: result.StructuredContent).
The doc comment says the map is meant for template variable substitution in composite tools, but it also ends up in the wire result of plain pass-through tool calls.
Suggestion
- Do not send the synthesized map to clients for pass-through tool calls (keep it internal for composite workflows), or
- at least skip blob resources (and probably images) in the synthesized map, or replace them with metadata (uri, mimeType, size).
The spec treats structuredContent as optional output that should match an outputSchema; tools without outputSchema arguably should not gain one on the way through the gateway.
Workaround
A proxy in front of the backend adds a small structuredContent (name, contentType, size) to such results; vMCP then uses it unchanged.
Environment
ToolHive operator / vMCP v0.66.0, Kubernetes; client Claude Code 2.1.326 (macOS).
Activity
danbarr commentedon Nov 19, 2026
The same synthesized map also changes what clients get back from plain text results, and it can break clients that use
structuredContentbefore falling back to text.Example:
ghcr.io/stackloklabs/osv-mcp/serverquery_vulnerabilityreturns the OSV response as JSON in a single text block, with nostructuredContent. After vMCP, the client receives:{ "content": [{"type": "text", "text": "{\"vulns\": [...]}"}], "structuredContent": {"text": "{\"vulns\": [...]}"} }A client that reads
structuredContentfirst, as the spec suggests for structured output, gets{"text": "<string>"}instead of the tool's JSON, which is a shape no backend ever produced. In our case a script readingstructuredContent.vulnssilently found no vulnerabilities for packages that have a dozen advisories. Calling the server directly behaves correctly.The map comes from the same fallback (
pkg/vmcp/client/client.go,if structuredContent == nil { structuredContent = conversion.ContentArrayToMap(contentArray) }). It reaches the wire through bothserver/serve_handlers.go(legacy) andserver/modern_envelope.go(modern). That argues for the first suggestion above: keep the synthesized map internal to composite workflow step outputs, and passstructuredContentthrough only when the backend actually sent one.jhrozek commentedon Nov 24, 2026
Thanks for the detailed report, and thanks to Dan for the OSV example. I confirmed this in the code. When a backend returns no
structuredContent, the vMCP backend client builds one from the content array so composite tool templates can use it. That map is also returned to clients on normal pass-through calls. So blob resources and images get their base64 copied into it, and a single text block becomes{"text": "..."}, a shape the backend never produced.The composite workflow engine already does its own conversion when
structuredContentis nil, so I think the right fix is to pass through only what the backend actually sent and keep the synthesized map internal to workflows. We'll treat this as a bug. Would you be willing to open a PR, or should we pick it up?nilsberberich commentedon Nov 24, 2026
Thanks for confirming, and thanks to Dan for the OSV example. Your fix approach sounds right to us.
I'd like to work on this. Plan:
structuredContentreaches the client only if the backend sent one.structuredContentstill gets its outputs.structuredContent, and for a backend that sends its ownstructuredContent, which must reach the client unchanged.docs/and in the PR as before/after, since clients that relied on the synthesized map (e.g.{"text": ...}) will no longer get it.Before opening the PR, I'll verify it on our test gateway with the original M365 case. I'll wait for the assignment before starting.
jhrozek commentedon Nov 24, 2026
you've got it!
Pass through only backend-sent structuredContent (stacklok#7309)