-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
Description
I’m using the openai-agents-python SDK with local MCP servers (MCPServerStdio / MCPServerStreamableHttp) and had a question about how tool calls are persisted to session storage.
While instrumenting session persistence, I noticed a difference between function tools and local MCP tools, and wanted to check whether this behavior is intentional or a potential oversight.
Environment
SDK: openai-agents-python @ e0bde88…
MCP usage: local MCP servers, not Hosted MCP (HostedMCPTool)
Session persistence: custom SessionStorage implementation
Observed behavior
When logging the items passed from the SDK into session storage, I consistently see:
Persisted:
- User messages
- Assistant messages
- Handoff function calls (transfer_to_*)
- Function tool calls (@function_tool)
Missing:
- Local MCP tool calls (from MCP servers)
This behavior appears consistent across turns.
Minimal pseudocode illustrating this
class CustomSessionStorage(SessionStorage):
async def add_items(self, items: list[dict]) -> None:
for item in items:
log(item.get("type"), item)
Observed item types:
- message
- tool_call (function tools)
- handoff
Not observed
- Any item corresponding to local MCP tool calls
This logging reflects exactly what the SDK passes into SessionStorage; no filtering is applied on my side.
Possible root cause (from code review)
From reviewing the SDK internals, it looks like:
- Local MCP tools execute out-of-band in
turn_resolution.py - They do not appear to create
ToolCallItemobjects?
As a result, they never reachsession_items_for_turn()and are not included insave_result_to_session()
This may explain why function tools and MCP tools behave differently with respect to session persistence?
Current workaround
I can observe local MCP tool activity via SSE streaming events (e.g. tool_call.in_progress), which provides real-time visibility. However, this doesn’t help with session replay or rehydration, since those events are not persisted.
Questions
- Is the exclusion of local MCP tool calls from session persistence intentional?
- Are MCP tool calls expected to be non-replayable / non-persisted by design?
- If not intentional, would the correct fix be:
- creating ToolCallItems for MCP tools during turn resolution, or
- extending session persistence to capture MCP tool execution metadata?
- Is there a recommended pattern for persisting MCP tool calls if session replay is needed?
Documentation context
The sessions documentation mentions that
tool calls, etc. are automatically stored
which led me to expect parity between function tools and MCP tools. I didn’t see any explicit exception noted for local MCP tools.
Docs referenced: https://openai.github.io/openai-agents-python/
Prior checks
I’ve read the Agents SDK documentation
I’ve searched existing GitHub issues and didn’t find one addressing local MCP tool persistence specifically
Happy to clarify or test changes if this turns out to be unintended behaviour.
Cheers,
Kieran