Keep shared MCP types stable in Code Mode exec descriptions (#50536)

## Why

Changing a deferred tool's output schema could add or remove the shared MCP type preamble from the `exec` description.

## What changed

Include the default or configured MCP TypeScript preamble whenever `code_mode_only` is enabled, regardless of the available tools' output schemas. Preserve an empty preamble override as a way to omit the section.

## Testing

Add a regression test that checks description stability when a deferred tool gains an MCP output schema, covering default, custom, and empty preambles. Update description expectations, request snapshots, and two Guardian context-budget test thresholds for the added preamble.

GitOrigin-RevId: 725035d6159e9da3c4beff5482c426c082e768b4
This commit is contained in:
Ahmed Ibrahim
2026-10-03 05:51:19 +00:00
committed by copyberry
parent 7d5f55bdad
commit e1b5b56a4f
22 changed files with 113 additions and 70 deletions
+5 -11
View File
@@ -304,17 +304,11 @@ pub fn build_exec_tool_description(
return sections.join("\n\n");
}
let has_mcp_tools = enabled_tools
.iter()
.chain(deferred_tools)
.any(|tool| mcp_structured_content_schema(tool.output_schema.as_ref()).is_some());
if has_mcp_tools {
let preamble = messages
.and_then(|messages| messages.mcp_typescript_preamble.as_deref())
.unwrap_or(MCP_TYPESCRIPT_PREAMBLE);
if !preamble.is_empty() {
sections.push(format!("Shared MCP Types:\n```ts\n{preamble}\n```"));
}
let preamble = messages
.and_then(|messages| messages.mcp_typescript_preamble.as_deref())
.unwrap_or(MCP_TYPESCRIPT_PREAMBLE);
if !preamble.is_empty() {
sections.push(format!("Shared MCP Types:\n```ts\n{preamble}\n```"));
}
if !enabled_tools.is_empty() {