Repository navigation
[PR] fix(mcp): the report text rides inside structuredContent (#3472) - #3639
aolshevskiy wants to merge 3 commits into
Conversation
…3472) ranxianglei#2752 put the machine state (outcome/blocksCreated) on MCP structuredContent only. Hosts that prefer structuredContent when present (Claude Code via its MCP bridge) drop the content text, so every success call reached the model as bare {"outcome":"success"} and the whole report was lost. Carry the full report inside structuredContent too (structured.text, byte-identical to content[0].text); the machine fields stay additive alongside it. Legacy envelopes without outcome/blocksCreated keep shipping no structuredContent at all.
The ranxianglei#2752/ranxianglei#3472 result assembly lives inline in `handleMessage`, so the only way to pin its shape is through a spawned shim over stdio — 216 lines of JSON-RPC harness per suite. Move it to exported `mcpToolResultEnvelope` and pin it host-free: legacy results still carry no `structuredContent`, `content` stays byte-identical, `text` rides alongside `outcome`/`blocksCreated`, and `structuredContent.text === content[0].text` holds for every shape (including an empty report — one shape, so no reader has to ask why the field vanished). Zero wire change, proven by the untouched ranxianglei#3472 wire suite still passing: the assembly is moved, not altered. The comment now records what the observation actually was rather than "some hosts prefer structuredContent": Claude Code 2.1.300 substitutes `JSON.stringify(structuredContent)` for the whole `content` array on SUCCESSFUL results only, reproduced over stdio (text + structuredContent → the model sees `{"outcome":"success"}`; text only → text; empty structuredContent → `{}`). The mirror stays unconditional rather than success-gated: failure receipts are one-liners with no payload to save, and the error-results exemption is host-version behavior, so the receipt that matters most must not depend on it holding.
(ai: vllm-qwen/qwen3.8-27b) Duplicate screening — 查重: 重复 #3474 (first-come), consolidated. This PR and #3474 fix the exact same defect in the same mechanism: same symptom (CC 2.1.300 drops the report text from MCP success results), same root cause (#2752 attaches Independent review (my own read of the diff, not the body's):
中文结构化八问:
判定: 可合 —— 代码正确、最小、单一生产点、向后兼容、测试有牙、diff 干净。但它是 #3474 的重复,已并入 #3474(现 head Thanks for the clean, well-scoped contribution — especially keeping the original authorship on the fix commit and deferring the outputSchema question to its own issue rather than inflating this one. |
(ai: deepseek/deepseek-flash)
Closes #3472.
Duplicate screening (§7.1) found #3472 (the report) and #3474 (an open fix by the bot). This PR is #3474's head rebased onto current master plus two additive commits. The fork cannot push to #3474's branch, so it lands here; if you prefer, fast-forward #3474's branch to this head and close this one — the trees are identical apart from
tests/mcp-tool-result-envelope.test.ts, so a squash also works. Commits:39d8cd7f— [PR] fix(mcp): structuredContent carries the full report text (#3472) #3474 as pushed (structuredContent.text, wire suite,scripts/live-files.mjsentry), author preserved.0cea1ccf—mcpToolResultEnvelopeextracted as an exported seam + host-free suite; the text mirror itself is unchanged.77e2c6fa— CHANGELOG entry, which [PR] fix(mcp): structuredContent carries the full report text (#3472) #3474 does not have.Problem
Since #2752 the MCP shim attaches
structuredContent: {outcome, blocksCreated}to results carrying machine state. Claude Code 2.1.300 replaces the wholecontentarray of a successful result that carries such a record withJSON.stringify(structuredContent)— error results keep their text. So every success call reached the model as the bare envelope ({"outcome":"success"}, 21 bytes) whileacp_status/acp_cachereturn their entire payload as prose: the model was told to paste a report it never received.search_contextanddecompresswere unusable the same way. Repro + impact: #3472.#3472 left open whether the client or its MCP bridge drops the text. It is the client, pinned to 2.1.300 with a stdio probe under the real binary — text +
structuredContent→ the model sees{"outcome":"success"}; text only → the text; emptystructuredContent→{}. In-repo corroboration:tests/fixtures/vertex-anthropic/README.md:14records the capture client asclaude-cli/2.1.300 (external, sdk-cli), andbili.logholdstool acp_cache executed via plugin (routed by body, #1685) (2455 chars, outcome=success)for the same calls whose transcripts contain the 21-byte result. Proxy healthy throughout —dist/mcp.jsdriven by hand over stdio returns the full text oncontentalongside the structured record.Fix
src/mcp.ts— result assembly moves intomcpToolResultEnvelope, which carries the text asstructuredContent.text, byte-identical tocontent[0].text, alongside the machine fields.Behavior change disclosure (MCP tool-result wire shape)
structuredContent:{outcome?, blocksCreated?}structuredContent:{text, outcome?, blocksCreated?}— additive field onlycontent[0].textbyte-identical in every case → content-reading hosts (dsh, codex, pi's owndetailschannel) unaffectedstructuredContentat all → pre-[Gap][pi/plugin] compress 的 partial 结果在宿主转发层被压成普通非错误结果,缺少结构化可见状态 #2752 clients see exactly the old shapeisErrorsemantics unchanged: partial stays non-error, refused/failure stay errorsTwo judgement calls, stated so they can be vetoed:
!out.failed. Considered success-gating it (2.1.300 exempts error results) and rejected: error receipts are one-liners with no payload to save, and the exemption is host-version behavior, so the receipts that matter most must not depend on it continuing to hold.textis always present, even"", sostructuredContent.text === content[0].textis an invariant rather than a per-shape rule.Cost, disclosed
The report travels on both carriers, so stdio result size roughly doubles for the table-shaped reports (
acp_statusranges,acp_cacheledger) on hosts that do readcontent. Availability of the receipt outranks the payload (#3128); option 3 in #3472 (outputSchemaper tool) is the durable shape and deserves its own issue rather than widening this one.Tests
tests/issue3472-mcp-structured-text.test.ts(from [PR] fix(mcp): structuredContent carries the full report text (#3472) #3474): wire-level through the REAL stdio shim + canned proxy —acp_status,acp_cache/search_context/decompressbodies recoverable fromstructuredContentalone,compressapplied/partial keep their machine fields with the text alongside (partial incl. the marker line),refusedkeepsisError: true, legacy envelope ships nostructuredContent. Registered inscripts/live-files.mjs.tests/mcp-tool-result-envelope.test.ts(new): the envelope host-free — legacy byte-identical,textalongsideoutcome/blocksCreated, thecontent[0].text === structuredContent.textinvariant across every shape, empty report, failure receipt.tests/issue2752-forward-partial-outcome.test.ts: the twodeepEqualpins extended to the new shape.Local: 35/35 across the three suites;
npm run typecheckadds no new errors (jimp/mediaOnlyare pre-existing environment gaps in this checkout);check-unused-exportsandcheck-test-import-graphclean. Full-suite verdict comes from CI on this head.