Skip to content

vMCP: synthesized structuredContent copies base64 blob of embedded resources to clients #7174

Done

Description

@nilsberberich

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

  1. Backend MCP server whose tool returns a file as an embedded resource, without structuredContent, e.g.:
    {"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>"}}
    ]}
    (We hit this with @softeria/ms-365-mcp-server and MS365_MCP_BLOB_OUTPUT=true, tools download-bytes / get-mail-attachment-content.)
  2. 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.Data for blob resources.
  • Called when the backend has no structuredContent in pkg/vmcp/session/internal/backend/mcp_session.go and pkg/vmcp/client/client.go; forwarded in pkg/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

  1. added
    needs-triage
    on Nov 18, 2026
  2. danbarr commented on Nov 19, 2026

    @danbarr
    Collaborator

    The same synthesized map also changes what clients get back from plain text results, and it can break clients that use structuredContent before falling back to text.

    Example: ghcr.io/stackloklabs/osv-mcp/server query_vulnerability returns the OSV response as JSON in a single text block, with no structuredContent. After vMCP, the client receives:

    {
      "content": [{"type": "text", "text": "{\"vulns\": [...]}"}],
      "structuredContent": {"text": "{\"vulns\": [...]}"}
    }

    A client that reads structuredContent first, 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 reading structuredContent.vulns silently 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 both server/serve_handlers.go (legacy) and server/modern_envelope.go (modern). That argues for the first suggestion above: keep the synthesized map internal to composite workflow step outputs, and pass structuredContent through only when the backend actually sent one.

  3. jhrozek commented on Nov 24, 2026

    @jhrozek
    Contributor

    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 structuredContent is 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?

  4. removed
    needs-triage
    on Nov 24, 2026
  5. nilsberberich commented on Nov 24, 2026

    @nilsberberich
    ContributorAuthor

    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:

    • Stop forwarding the synthesized map on pass-through tool calls, in both the legacy and the modern response path; structuredContent reaches the client only if the backend sent one.
    • Keep composite workflows working as they are, with a test that a step without backend structuredContent still gets its outputs.
    • Unit tests for blob resources, images and a single text block without structuredContent, and for a backend that sends its own structuredContent, which must reach the client unchanged.
    • Describe the change for clients under 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.

  6. jhrozek commented on Nov 24, 2026

    @jhrozek
    Contributor

    you've got it!

  7. added a commit that references this issue on Nov 26, 2026
    e7becbf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions