-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix: persist MCP tool call outputs to session storage #2388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1299,6 +1299,26 @@ def process_model_response( | |
| break | ||
| items.append(ToolCallItem(raw_item=output, agent=agent, description=_mcp_description)) | ||
| tools_used.append("mcp") | ||
|
|
||
| # Create a ToolCallOutputItem for MCP calls that have completed with output. | ||
| # This ensures MCP tool call results are persisted to session storage for replay. | ||
| if output.output is not None or output.error is not None: | ||
| # Build an MCP call output item for session persistence. | ||
| # Use call_id to link with the corresponding mcp_call item for proper | ||
| # deduplication and orphan filtering. | ||
| mcp_output_content = output.error if output.error else output.output | ||
| mcp_call_output: dict[str, Any] = { | ||
| "type": "mcp_call_output", | ||
| "call_id": output.id, | ||
| "output": mcp_output_content or "", | ||
| } | ||
|
Comment on lines
+1310
to
+1314
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When constructing the synthetic Useful? React with 👍 / 👎. |
||
| items.append( | ||
| ToolCallOutputItem( | ||
| raw_item=mcp_call_output, | ||
| output=mcp_output_content, | ||
| agent=agent, | ||
| ) | ||
| ) | ||
| elif isinstance(output, ImageGenerationCall): | ||
| items.append(ToolCallItem(raw_item=output, agent=agent)) | ||
| tools_used.append("image_generation") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By adding
mcp_callto_TOOL_CALL_TO_OUTPUT_TYPE,drop_orphan_function_callswill now treat every MCP call as requiring a matchingmcp_call_outputitem. That means sessions persisted before this change (or any caller-supplied history that only includesmcp_callitems withoutput/errorinline) will have those MCP calls dropped duringnormalize_resumed_input, losing tool history and potentially changing replay behavior. Consider exempting MCP calls that already include output/error, or backfilling an output item when normalizing legacy input.Useful? React with 👍 / 👎.