Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Versions follow the merge of a `*_release-v*` branch; CI publishes to npm on tag

### Changes

- **MCP results carry the full report inside `structuredContent` (#3472, #2752 follow-up).** Claude Code 2.1.300 replaces the whole `content` array of any SUCCESSFUL MCP tool result that carries a `structuredContent` record with `JSON.stringify` of that record — error results keep their text — so every bili tool call from such a host reached the model as the bare envelope (`{"outcome":"success"}`, 21 bytes; `{"outcome":"applied","blocksCreated":1}`, 39 bytes) while the report itself went nowhere. The proxy was healthy throughout: `bili.log` shows `tool acp_cache executed via plugin (routed by body, #1685) (2455 chars, outcome=success)` for the same calls whose transcripts hold the 21-byte result, and driving `dist/mcp.js` by hand over stdio returns the full 2455-char text on `content` next to the structured record. `acp_status`/`acp_cache` return their entire payload as prose — exactly the report the model was told to paste verbatim and had nothing to paste — and `search_context`/`decompress` lost their results the same way. Result assembly now goes through `mcpToolResultEnvelope` (`src/mcp.ts`), which carries the text as `structuredContent.text`, byte-identical to `content[0].text`, alongside the machine fields. `content` stays byte-identical and a result with no `outcome`/`blocksCreated` still carries no `structuredContent` at all, so the pi, dsh and codex lanes are untouched; the structured contract only gains a field. Cost, disclosed: the report now travels twice, so the stdio result roughly doubles for the table-shaped reports (`acp_status` ranges, `acp_cache` ledger) on hosts that do read `content` — availability of the receipt outranks the payload, per #3128.
- **dsh PTC sessions get compression back: a `run_code` omnibus on the wire reads as reachable, not unreachable (#3600).** dsh PTC presets collapse EVERY tool into a single `run_code` omnibus (the SDK bindings nest inside it), so the top-level tools array carries no `compress` entry. The #3427 reachability gate read exactly that shape as "tool not host-scoped → suppress the compress surface", and released 0.1.198 suppressed every dsh PTC session: 89× `ARMED-SUPPRESSED` nudges while the window ran to 100%, then the output got clamped and the session was effectively dead — silently, while standard-mode sessions on the same install kept compressing (v0.1.197 had no tools factor in its nudge gate, so this is a release regression, not "never worked"). The gate now treats a `run_code` omnibus declaration as reachable: top-level absence is not evidence of unreachability when the omnibus swallows everything. The #3177 true negative keeps its suppression (a bare single tool that is neither `compress` nor the omnibus still drops the surface), and the #3401 positive case is unchanged.

- **dsh desktop settings pane: the embed probe is admitted for the Electron scheme origin (#3513, desktop variant).** The dsh DESKTOP app renders its settings pane from the custom scheme origin `dsh-app://app` (not an http origin like dsh web). The #3514 fix echoed the requesting Origin — but the request never reached the echo: `isTrustedAdminOrigin` only accepts http/https origins, so the probe's `GET /__bili/?embed=1` died in the trust gate with a bare 403 and no `access-control-allow-origin` — the pane stayed on "正在连接 bili 代理…" forever (real-world console: "blocked by CORS policy … from origin 'dsh-app://app'"). The gate now admits exactly that one origin (scheme `dsh-app`, hostname `app`): browsers set the Origin header themselves and the `dsh-app` scheme only exists inside the dsh Electron app, so a website can never produce that Origin — while rebinding attacks still arrive with http/https attacker hostnames and stay rejected. Foreign hostnames under the same scheme (`dsh-app://evil`) and every other custom scheme stay 403; the existing #3514 echo then covers the response.
Expand Down
1 change: 1 addition & 0 deletions scripts/live-files.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const LIVE_FILES = [
"tests/index-entry-guard.test.ts",
"tests/issue1958-routed-warn.test.ts",
"tests/issue2752-forward-partial-outcome.test.ts",
"tests/issue3472-mcp-structured-text.test.ts",
"tests/issue760-percall-conversation.test.ts",
"tests/issue927-opencode-install.test.ts",
"tests/kimi-native.test.ts",
Expand Down
37 changes: 29 additions & 8 deletions src/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,32 @@ function ensureManifest(): Promise<void> {
// partial note for clients that only render content text.
export type McpForwardedToolResult = { text: string; failed: boolean; outcome?: ToolOutcomeKind; blocksCreated?: number };

// #3472: Claude Code 2.1.300 replaces the WHOLE content array of any SUCCESSFUL
// MCP tool result that carries a structuredContent record with JSON.stringify of
// that record (reproduced over stdio: text + structuredContent → the model sees
// `{"outcome":"success"}`; text only → text; empty structuredContent → `{}`).
// Error results keep their text. Since #2752 attaches that record, every
// successful call from such a host reached the model as the bare envelope — 21
// bytes — while acp_status/acp_cache/search_context/decompress return their
// entire payload as prose, so the model was told to paste a report it never got.
// Mirror the text into the structured object (`text`, byte-identical to
// content[0].text) so a structured-only reader still receives the full receipt.
// The mirror is unconditional, not success-gated: failure receipts are
// one-liners (no payload to save) and the error-results exemption above is
// observed host-version behavior, so the receipts that matter most must not
// depend on it holding. Hosts that read content keep byte-identical envelopes,
// and a result with no outcome/blocksCreated still carries no structuredContent
// at all.
export function mcpToolResultEnvelope(out: McpForwardedToolResult): Record<string, unknown> {
const result: Record<string, unknown> = { content: [{ type: "text", text: out.text }], isError: out.failed };
if (out.outcome === undefined && out.blocksCreated === undefined) return result;
const structured: Record<string, unknown> = { text: out.text };
if (out.outcome !== undefined) structured.outcome = out.outcome;
if (out.blocksCreated !== undefined) structured.blocksCreated = out.blocksCreated;
result.structuredContent = structured;
return result;
}

export async function forwardTool(tool: string, args: unknown, timeoutMs: number = TOOL_TIMEOUT_MS, conversationIdOverride: string | undefined = undefined, nativeCaller: boolean = false): Promise<McpForwardedToolResult> {
const effectiveConversationId = conversationIdOverride ?? conversationId;
for (let attempt = 0; ; attempt++) {
Expand Down Expand Up @@ -351,14 +377,9 @@ async function handleMessage(msg: {
// #2752: the business state rides MCP structuredContent (spec
// field alongside content; clients predating it ignore it).
// isError semantics are unchanged — partial stays non-error.
const result: Record<string, unknown> = { content: [{ type: "text", text: out.text }], isError: out.failed };
if (out.outcome !== undefined || out.blocksCreated !== undefined) {
const structured: Record<string, unknown> = {};
if (out.outcome !== undefined) structured.outcome = out.outcome;
if (out.blocksCreated !== undefined) structured.blocksCreated = out.blocksCreated;
result.structuredContent = structured;
}
sendResult(id, result);
// #3472: the report text rides inside that record too; see
// mcpToolResultEnvelope.
sendResult(id, mcpToolResultEnvelope(out));
} catch (err) {
// Protocol failures are results (isError), not JSON-RPC
// errors, so the host surfaces them to the model.
Expand Down
7 changes: 5 additions & 2 deletions tests/issue2752-forward-partial-outcome.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,15 +457,18 @@ describe("#2752: the shim's tools/call response carries structuredContent on the
assert.ok(r.result, "a result object comes back");
assert.notEqual(r.result!.isError, true, "partial is NOT an error on the wire");
assert.equal(r.result!.content?.[0]?.text, `${PARTIAL_TEXT}\n${partialOutcomeNote(1)}`);
assert.deepEqual(r.result!.structuredContent, { outcome: "partial", blocksCreated: 1 });
// #3472: structuredContent also carries the full report text so
// structured-preferring hosts do not lose the receipt body.
assert.deepEqual(r.result!.structuredContent, { text: `${PARTIAL_TEXT}\n${partialOutcomeNote(1)}`, outcome: "partial", blocksCreated: 1 });
});

it("failure: isError true with its outcome still on structuredContent", async () => {
assert.ok(client);
const r = await client.request(2, "tools/call", { name: "decompress", arguments: { blockId: "b999" } });
assert.ok(!r.error, `no JSON-RPC error: ${JSON.stringify(r.error)}`);
assert.equal(r.result?.isError, true);
assert.deepEqual(r.result?.structuredContent, { outcome: "failure" });
// #3472: the failure receipt text rides structuredContent too.
assert.deepEqual(r.result?.structuredContent, { text: FAILURE_TEXT, outcome: "failure" });
});

it("legacy envelope: no structuredContent field at all", async () => {
Expand Down
Loading
Loading