mirror of
https://github.com/openai/codex.git
synced 2026-11-24 23:20:47 +00:00
## 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
53 lines
1.6 KiB
Rust
53 lines
1.6 KiB
Rust
use codex_code_mode::CellId;
|
|
use codex_code_mode::CodeModeNestedToolCall;
|
|
use codex_code_mode::CodeModeSessionDelegate;
|
|
use codex_code_mode::CodeModeToolResult;
|
|
use codex_code_mode::NotificationFuture;
|
|
use codex_code_mode::ToolInvocationFuture;
|
|
use codex_protocol::ToolName;
|
|
use pretty_assertions::assert_eq;
|
|
use serde_json::json;
|
|
use tokio::sync::Semaphore;
|
|
use tokio_util::sync::CancellationToken;
|
|
|
|
pub(crate) struct LargeToolResultDelegate {
|
|
pub(crate) started: Semaphore,
|
|
pub(crate) release: Semaphore,
|
|
}
|
|
|
|
impl CodeModeSessionDelegate for LargeToolResultDelegate {
|
|
fn invoke_tool<'a>(
|
|
&'a self,
|
|
invocation: CodeModeNestedToolCall,
|
|
_cancellation: CancellationToken,
|
|
) -> ToolInvocationFuture<'a> {
|
|
Box::pin(async move {
|
|
if invocation.tool_name == ToolName::plain("fast") {
|
|
return Ok(CodeModeToolResult::from(json!({ "value": "isolated" })));
|
|
}
|
|
assert_eq!(invocation.tool_name, ToolName::plain("large"));
|
|
self.started.add_permits(/*n*/ 1);
|
|
self.release
|
|
.acquire()
|
|
.await
|
|
.map_err(|_| "large tool release closed".to_string())?
|
|
.forget();
|
|
Ok(CodeModeToolResult::from(
|
|
json!({ "value": "x".repeat(8 * 1024 * 1024) }),
|
|
))
|
|
})
|
|
}
|
|
|
|
fn notify<'a>(
|
|
&'a self,
|
|
_call_id: String,
|
|
_cell_id: CellId,
|
|
_text: String,
|
|
_cancellation: CancellationToken,
|
|
) -> NotificationFuture<'a> {
|
|
Box::pin(async { Ok(()) })
|
|
}
|
|
|
|
fn cell_closed(&self, _cell_id: &CellId) {}
|
|
}
|