Skip to content

Forward session and turn headers to MCP HTTP requests#15011

Merged
nicholasclark-openai merged 8 commits intomainfrom
nicholasclark/tool-call-task-headers
Mar 19, 2026
Merged

Forward session and turn headers to MCP HTTP requests#15011
nicholasclark-openai merged 8 commits intomainfrom
nicholasclark/tool-call-task-headers

Conversation

@nicholasclark-openai
Copy link
Copy Markdown
Contributor

Summary

  • forward request-scoped task headers through MCP tool metadata lookups and tool calls
  • apply those headers to streamable HTTP initialize, tools/list, and tools/call requests
  • update affected rmcp/core tests for the new request_headers plumbing

Testing

  • cargo test -p codex-rmcp-client
  • cargo test -p codex-core (fails on pre-existing unrelated error in core/src/auth_env_telemetry.rs: missing websocket_connect_timeout_ms in ModelProviderInfo initializer)
  • just fix -p codex-rmcp-client
  • just fix -p codex-core (hits the same unrelated auth_env_telemetry.rs error)
  • just fmt

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 18, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@nicholasclark-openai
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@nicholasclark-openai nicholasclark-openai changed the title Forward tool call task headers to MCP HTTP requests Forward session and task headers to MCP HTTP requests Mar 18, 2026
@nicholasclark-openai nicholasclark-openai changed the title Forward session and task headers to MCP HTTP requests Forward session and turn headers to MCP HTTP requests Mar 18, 2026
@nicholasclark-openai
Copy link
Copy Markdown
Contributor Author

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.

nicholasclark-openai and others added 2 commits March 18, 2026 16:42
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())
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@nicholasclark-openai nicholasclark-openai merged commit b14689d into main Mar 19, 2026
33 checks passed
@nicholasclark-openai nicholasclark-openai deleted the nicholasclark/tool-call-task-headers branch March 19, 2026 04:29
@github-actions github-actions bot locked and limited conversation to collaborators Mar 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants