Skip to content

fix(mcp): serialize structured results into content by default - #55

Merged
mekedron merged 1 commit into
mekedron:mainfrom
adamhadani:fix/mcp-content-spec-compliance
Oct 16, 2026
Merged

mekedron merged 1 commit into
mekedron:mainfrom
adamhadani:fix/mcp-content-spec-compliance

Conversation

@adamhadani

Copy link
Copy Markdown
Contributor

What

Tool results now carry the serialized JSON payload in content by default. The
opt-out moves to WOLT_MCP_COMPACT_CONTENT=1 for clients that read
structuredContent and want the smaller response.

Why

The MCP spec, under Structured Content, says:

For backwards compatibility, a tool that returns structured content SHOULD
also return the serialized JSON in a TextContent block.

newToolResultMiddleware did the reverse. The go-sdk already produces that
serialized block; the middleware replaced it with the short summary unless
WOLT_MCP_DUPLICATE_CONTENT asked for it back. For a client that reads only
content, every tool returned a bare count and nothing else.

Observed with Claude Desktop on v2.4.2, which reads content only. Its
explanation of why it stopped using the server and scraped wolt.com in a browser
instead:

I tried the Wolt connector first, but every call returns only a one-line
summary, never the data behind it. For example, a venue search came back as
"10 matches", an item search as "50 globally ranked items", and the cart as
"2 baskets", with no names, prices or IDs.

Same wolt_top call against v2.4.2, measured over stdio:

content[0].text structuredContent
default 10 top venues (13 chars) 8,847 chars
WOLT_MCP_DUPLICATE_CONTENT=1 full JSON (7,486 chars) 8,847 chars

The failure is silent: the client cannot distinguish "10 venues, details
withheld" from "10 venues with no details available", so it does not retry or
report a problem — it just works with nothing.

What this costs

Responses roughly double for clients that were relying on the compact default
and read structuredContent. That tradeoff is why the old behavior is kept
rather than removed: set WOLT_MCP_COMPACT_CONTENT=1 and it is byte-identical
to v2.4.2.

What this does not change

  • The per-request contract. _meta["wolt/duplicate_content"] keeps its
    original sense — true asks for serialized JSON, false asks for the
    summary — and still overrides the server default in both directions. Only the
    default it overrides has changed.
  • structuredContent. Untouched in every mode.
  • Error results. normalizeToolErrorResult is not touched, so ordinary tool
    errors still keep structuredContent unset and the message in content.
  • Existing configs. WOLT_MCP_DUPLICATE_CONTENT is still parsed. It is now
    a no-op, since its behavior became the default, and logs one WARN at startup
    saying it can be removed. Nothing breaks if it is left set.

Verification

Local gate from AGENTS.MD, all passing: go build ./..., gofmt -l (clean),
go vet ./..., golangci-lint run v2.4.0 (0 issues.), go test ./...,
go test -race ./..., and the version-stamp check.

End to end against the rebuilt binary, same wolt_top call:

  • default → content[0] is 7,492 chars of JSON, structuredContent intact
  • WOLT_MCP_COMPACT_CONTENT=1 → content[0] is 10 top venues, 13 chars

Tests updated in place rather than added alongside, since the existing ones
already pinned the old default: the end-to-end wolt_cart_show case now asserts
the serialized payload arrives with no _meta and the summary arrives with
_meta false, and the server-level table covers both directions.

🤖 Generated with Claude Code

The MCP spec requires that "a tool that returns structured content SHOULD
also return the serialized JSON in a TextContent block". The tool-result
middleware did the opposite: it replaced the SDK's serialized JSON with a
short summary unless WOLT_MCP_DUPLICATE_CONTENT opted back in. A client
that reads only content therefore received "10 matches" or "2 baskets"
with no names, prices or ids behind them, and no way to tell that data
was missing.

Flip the default so content carries the serialized payload, and add
WOLT_MCP_COMPACT_CONTENT=1 as the opt-out for clients that do read
structuredContent and prefer the smaller response.

The per-request contract is unchanged: _meta["wolt/duplicate_content"]
true still asks for the serialized JSON and false for the summary, so a
single client can still override the server either way.
WOLT_MCP_DUPLICATE_CONTENT is still parsed and now warns once at startup
that it can be removed, so existing configs keep working untouched.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@mekedron
mekedron merged commit 29095c0 into mekedron:main Oct 16, 2026
4 checks passed
@mekedron

Copy link
Copy Markdown
Owner

Thanks a lot for this, Adam! A great catch, and the write-up with the spec quote and the before/after measurements made it easy to review. Merged as-is with a merge commit, and it ships in v2.5.0.

mekedron added a commit that referenced this pull request Oct 17, 2026
The daily live smoke failed on 2026-10-17 at "mcp checkout preview"
with "content is not the structured summary". Wolt did not change
anything: since v2.5.0 wolt-mcp serializes the full structured result
into content by default (PR #55), while mcp-checkout-smoke still
asserted the old compact contract and rejected the JSON copy.

The checker now asserts the current contract. A successful preview
must carry content that decodes to the same JSON as structuredContent.
A typed checkout outcome (IsError with structured data) keeps the
handler's short summary in content, as before.

Fixes #56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants