Forward session and turn headers to MCP HTTP requests#15011
Forward session and turn headers to MCP HTTP requests#15011nicholasclark-openai merged 8 commits intomainfrom
Conversation
Co-authored-by: Codex <[email protected]>
|
All contributors have signed the CLA ✍️ ✅ |
Co-authored-by: Codex <[email protected]>
|
I have read the CLA Document and I hereby sign the CLA |
|
Thanks @pakrym. The goal here is to propagate session/turn IDs into MCP calls as headers. The tricky part is that rmcp_client is long-lived and reused across calls, so I want to avoid introducing shared mutable header state that could create races or reduce MCP call concurrency. I’m going to spend some time seeing if I can simplify the design. |
Set Codex Apps MCP request headers once per active turn and clear them on turn end, instead of threading request-scoped headers through every tool call. Keep RMCP header injection limited to streamable HTTP tools/call requests so list/init paths stay unchanged and concurrent tool calls on the same client are not serialized. Co-authored-by: Codex <[email protected]>
Add the new request_headers test fixture state, update the streamable HTTP recovery test to pass the new client constructor argument, and satisfy the argument comment lint for clearing turn-scoped MCP request headers. Co-authored-by: Codex <[email protected]>
| ) { | ||
| self.abort_all_tasks(TurnAbortReason::Replaced).await; | ||
| self.clear_connector_selection().await; | ||
| self.sync_mcp_request_headers_for_turn(turn_context.as_ref()) |
There was a problem hiding this comment.
The MCP client lifecycle is different than that of a turn and can issues parallel calls, so there's an inherent race condition changing headers inside of a turn. Given turns seem sequential, we set the headers as a turn is starting and unset them once done. This allows to have the headers in the MCP calls without needing blocking concurrency or introducing a race.
Summary
Testing