Deduplicate MCP text fallbacks in Code Mode output (#63540)

## Why

MCP tools can return structured data alongside a JSON text fallback for
clients that need it. Printing the whole result in Code Mode can show
the same data twice.

## What changed

Enable `features.code_mode_mcp_result_dedup` to let `text()` omit
`content` when it prints an original, successful MCP result whose only
content block is a plain text fallback that parses to the same JSON as
`structuredContent`. The JavaScript result retains both fields.

Carry the result format through gRPC so the host can distinguish MCP
results from ordinary JSON. The feature is off by default.

## Testing

Add coverage for both feature flag settings, for printing original MCP
results and copies through gRPC, and for comparing equivalent JSON.

GitOrigin-RevId: a8b0b42f5375d9744c235a0e663090dd5982e37e
This commit is contained in:
Charlie Marsh
2026-11-24 04:49:27 +00:00
committed by copyberry
parent 714bc44f0d
commit 96681d86f0
81 changed files with 955 additions and 143 deletions
@@ -87,7 +87,9 @@ pub(super) fn text_callback(
} else {
args.get(0)
};
let can_omit_fallback = super::mcp_result::can_omit_fallback(scope, value);
let text = match serialize_output_text(scope, value) {
Ok(text) if can_omit_fallback => super::mcp_result::without_fallback(&text).unwrap_or(text),
Ok(text) => text,
Err(error_text) => {
throw_type_error(scope, &error_text);