fix(mcp): include threadId in both content and structuredContent in CallToolResult (#9338)

This commit is contained in:
Michael Bolin
2026-01-15 18:33:11 -08:00
committed by GitHub
parent a6324ab34b
commit 99f47d6e9a
5 changed files with 86 additions and 23 deletions

View File

@@ -34,21 +34,27 @@ pub(crate) const INVALID_PARAMS_ERROR_CODE: i64 = -32602;
/// To adhere to MCP `tools/call` response format, include the Codex
/// `threadId` in the `structured_content` field of the response.
fn create_call_tool_result_with_thread_id(
/// Some MCP clients ignore `content` when `structuredContent` is present, so
/// mirror the text there as well.
pub(crate) fn create_call_tool_result_with_thread_id(
thread_id: ThreadId,
text: String,
is_error: Option<bool>,
) -> CallToolResult {
let content_text = text;
let content = vec![ContentBlock::TextContent(TextContent {
r#type: "text".to_string(),
text: content_text.clone(),
annotations: None,
})];
let structured_content = json!({
"threadId": thread_id,
"content": content_text,
});
CallToolResult {
content: vec![ContentBlock::TextContent(TextContent {
r#type: "text".to_string(),
text,
annotations: None,
})],
content,
is_error,
structured_content: Some(json!({
"threadId": thread_id,
})),
structured_content: Some(structured_content),
}
}
@@ -398,6 +404,7 @@ mod tests {
result.structured_content,
Some(json!({
"threadId": thread_id,
"content": "done",
}))
);
}