Repository navigation
Pass through only backend-sent structuredContent - #7309
Merged
ChrisJBurns merged 2 commits intoNov 26, 2026
Merged
ChrisJBurns merged 2 commits into
ChrisJBurns merged 2 commits into
Conversation
When a backend tool result had no structuredContent, vMCP built one
from the content array (ContentArrayToMap) and returned it to clients
on plain pass-through calls. Clients that read structuredContent first
got {"text": "..."} instead of the tool's output, and blob resources
and images had their base64 payload copied into structuredContent.
The backend client and the session connector now keep structuredContent
only when the backend sent an object. Composite workflows are
unaffected: the workflow engine already builds step output from content
when structuredContent is nil. The Legacy result builders now omit the
member instead of encoding a typed nil map as "structuredContent": null.
Fixes stacklok#7174
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Nils Berberich <[email protected]>
ChrisJBurns
reviewed
Nov 25, 2026
ChrisJBurns
left a comment
Collaborator
There was a problem hiding this comment.
See the inline comments.
Without a synthesized structuredContent, an inner tool result that has no text content item (for example only an image or a blob resource) reaches code mode scripts as None. State this in the toMCPResult comment and the architecture doc, and pin it with a decorator test so the behavior stays deliberate. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Nils Berberich <[email protected]>
ChrisJBurns
approved these changes
Nov 26, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7309 +/- ##
==========================================
+ Coverage 82.09% 82.16% +0.07%
==========================================
Files 927 932 +5
Lines 93959 94526 +567
==========================================
+ Hits 77132 77664 +532
- Misses 16822 16857 +35
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Collaborator
|
/retest |
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a backend tool result has no
structuredContent, vMCP builds one from the content array (conversion.ContentArrayToMap) and returns it to the client on plain pass-through calls. That map was meant for composite workflow templates, but clients that readstructuredContentfirst get a shape the backend never produced:{"text": "..."}for a text result, and the full base64 payload of blob resources and images copied intostructuredContent. With a backend that returns files as embedded resources, the client stores the file, but the base64 also lands in the model context throughstructuredContent(see #7174 for the file case and the OSV example in the comments).toolResultFromMCP, shared by the Legacy and Modern backend paths) and the session connector (mcpSession.CallTool) now keepstructuredContentonly when the backend sent an object. Nothing is synthesized fromcontent; a non-object value is still dropped, now with a Debug line on both paths.contentwhenstructuredContentis nil (tool steps and forEach), and the.contenttemplate context is built fromcontentanyway.coreToolHandler,DefaultHandlerFactory.CreateToolHandler,adaptToolsForFactory) assigned a possibly nilmap[string]anyto theany-typedmcp.CallToolResult.StructuredContent. Once the map is usually nil, that typed nil would be encoded as"structuredContent": null. A small helper,conversion.ToMCPStructuredContent, returns an untyped nil instead; code mode'stoMCPResultuses it in place of its own guard. The Modern envelope already omitted the member.vmcp.ToolCallResult.StructuredContent,ContentArrayToMap, code mode), anddocs/arch/10-virtual-mcp-architecture.mdgets a short section on tool call results so clients can see what to expect.Fixes #7174
Type of change
Test plan
task test)task test-e2e)task lint-fix)Unit tests added or extended:
pkg/vmcp/client:toolResultFromMCPwith a blob resource, an image and a single text block withoutstructuredContent(result has none,contentunchanged), a backend object (passed through unchanged) and a non-object value (dropped).pkg/vmcp/session/internal/backend: the same cases throughmcpSession.CallToolagainst the package's fake backend (it can now return a configuredtools/callresult).pkg/vmcp/server: Legacytools/callresult marshalled to JSON: the member is absent withoutstructuredContentand forwarded unchanged with an object.DefaultHandlerFactory.CreateToolHandlerleaves the field untyped nil.conversion.ToMCPStructuredContenthas its own table test.pkg/vmcp/composer: a tool step and a forEach inner step whose backend result has onlycontentstill exposeoutput.text.pkg/vmcp/codemode: an inner result with only an image or only a blob resource reaches the script asNone, and the payload does not reach the script result.Without the production change, the new client, session, Legacy wire and handler factory tests fail; the composer test and the code mode test pass before and after: the first guards the workflow engine's existing fallback, the second pins the script-side contract for results without text content.
task lint-fix,task lintandtask license-checkreport no issues, andtask testpasses locally.Manual test: the change backported onto v0.69.0 (in that release
toolResultFromMCPhas no logger parameter, so its Debug lines useslog) and deployed as the vMCP image of a test gateway, with@softeria/ms-365-mcp-server(MS365_MCP_BLOB_OUTPUT=true) as a backend and Claude Code 2.1.332 as the client. In that deployment a filtering proxy sits in front of the backend; its workaround from the issue (adding a smallstructuredContentto file results) was switched off for the test, so the backend's result reached vMCP withoutstructuredContent:download-bytesfor a small .xlsx: the client receives a short text element with name, content type and size, plus the resource; Claude Code stores the file and the model sees only[Resource from … at file:///….xlsx] Binary content (…, 1.7KB) saved to …(about 370 characters). No base64 in the tool result and no overflow file. On v0.66.0 without the workaround, the same tool put the full base64 into the result (92,448 characters for a 69 KB .docx).structuredContent: the client received the plain text result.structuredContent: received once and unchanged.Changes
pkg/vmcp/client/client.gostructuredContentintoolResultFromMCPpkg/vmcp/session/internal/backend/mcp_session.gomcpSession.CallTool; Debug line for a dropped non-objectpkg/vmcp/conversion/content.goToMCPStructuredContent;ContentArrayToMapdoc limited to workflowspkg/vmcp/server/serve_handlers.go,server/adapter/handler_factory.go,server/sessionmanager/factory.goToMCPStructuredContent(no"structuredContent": null)pkg/vmcp/codemode/decorator.gopkg/vmcp/types.goToolCallResult.StructuredContentdocdocs/arch/10-virtual-mcp-architecture.mdstructuredContentpassthrough"Does this introduce a user-facing change?
Yes. Clients calling backend tools through vMCP:
structuredContentstructuredContent: {"text": "<the text>"}structuredContentstructuredContentstructuredContent: {"resource": "<full base64>", …}structuredContentstructuredContentstructuredContent: {"image_0": "<base64>"}structuredContent{"resource": …, "text": …}structuredContentthat is not an object (e.g. an array)contentstructuredContentstructuredContentobjectClients that read
structuredContentbeforecontentnow get the backend's own output. Clients that relied on the synthesized keys (text,text_1,image_0,resource) no longer get them.Code mode: an inner tool call whose backend sends no
structuredContentnow goes through the script engine's content fallback. A JSON text result reaches the script as the parsed value, and a plain (non-JSON) text result as the string of the first text item, instead of{"text": "<string>"}. This matches what the existing code mode tests already expect. An inner result with no text content item (for example only an image or a blob resource) reaches the script asNoneinstead of{"image_0": "<base64>"}or{"resource": "<blob>"}; binary payloads are not passed into scripts. Scripts that readr["text"]from such results, ortext_1/image_0/resource, need to change.Composite tools: no change; step output and the
.contenttemplate context are still built fromcontentwhen the backend sends nostructuredContent.Implementation plan
Approved implementation plan
ContentArrayToMapis applied in two backend producers,toolResultFromMCP(pkg/vmcp/client, Legacy and Modern backend paths) andmcpSession.CallTool(pkg/vmcp/session/internal/backend). The workflow engine does not need it there: it falls back toContentArrayToMap(result.Content)itself for tool steps and forEach.StructuredContentis the backend's object or nil.serve_handlers.go,adapter/handler_factory.go,sessionmanager/factory.go): setstructuredContentonly when present, otherwise the typed nil map is encoded asnull. The Modern envelope and code mode already guard against this.types.go,ContentArrayToMap, code mode).structuredContent(blob, image, text as{"text": ...}). Code mode scripts get the parsed JSON for JSON text results instead of{"text": "<string>"}. Described as before/after in the PR.structuredContent; own object unchanged; non-object dropped), session connector the same, wire result on the Legacy path (member absent, nonull) and on the Modern path if not yet covered, composite tool step and forEach still exposeoutput.text, code mode. Adapt or remove tests that pin the old behavior. Locallytask lint,task test,task license-check.docs/arch/10-virtual-mcp-architecture.md.Special notes for reviewers
structuredContentwhen the map is empty (len(...) > 0), the Legacy builders forward{}. That was already the case before; I left it alone to keep this PR to the bug, and the new doc section states it. Happy to align it here or in a follow-up if you prefer.adaptToolsForFactory(sessionmanager/factory.go) gets the same helper but no dedicated test: its handlers are only invoked through the optimizer, whosecall_toolresult is converted back with a type assertion and then leaves through the guarded Legacy or Modern builder.ContentArrayToMapitself is unchanged and still used by the workflow engine and the template expander.newModernCallToolResulttest already checks that the member is omitted withoutstructuredContent. For code mode, the existing tests already exercise a text-only inner result parsed as JSON; a test for the non-text case was added after review. No existing test pinned the synthesized map.🤖 Generated with Claude Code