Skip to content

Simplify MCP tool handler plumbing#21595

Merged
pakrym-oai merged 6 commits into
mainfrom
pakrym/simplify-mcp-handler-plumbing
May 12, 2026
Merged

Simplify MCP tool handler plumbing#21595
pakrym-oai merged 6 commits into
mainfrom
pakrym/simplify-mcp-handler-plumbing

Conversation

@pakrym-oai

Copy link
Copy Markdown
Collaborator

Why

The MCP tool path had accumulated a few core-owned special cases: a dedicated payload variant, resolver plumbing, a legacy AfterToolUse translation path, and a side channel for parallel-call metadata. That made ToolRegistry and the spec builder know more about MCP than they needed to.

This change moves MCP-specific execution details back onto ToolInfo and McpHandler so codex-core can treat MCP calls like normal function calls while still preserving MCP-specific dispatch and telemetry behavior where it belongs.

What changed

  • removed resolve_mcp_tool_info, ToolPayload::Mcp, ToolKind, and the remaining registry-side MCP resolver path
  • stored MCP routing metadata directly on McpHandler and ToolInfo, including supports_parallel_tool_calls
  • deleted the legacy AfterToolUse consumer in core, which removes the need for handler-specific after_tool_use_payload implementations
  • switched tool-result telemetry to handler-provided tags and kept MCP-specific dispatch payload construction inside the handler
  • simplified tool spec planning/building by passing ToolInfo directly and dropping the direct/deferred MCP wrapper structs and the parallel-server side table

Testing

  • cargo check -p codex-core -p codex-mcp -p codex-otel
  • cargo test -p codex-core mcp_parallel_support_uses_exact_payload_server
  • cargo test -p codex-core direct_mcp_tools_register_namespaced_handlers
  • cargo test -p codex-core search_tool_description_lists_each_mcp_source_once
  • cargo test -p codex-mcp list_all_tools_uses_startup_snapshot_while_client_is_pending
  • just fix -p codex-core -p codex-mcp -p codex-otel

@pakrym-oai pakrym-oai force-pushed the pakrym/simplify-mcp-handler-plumbing branch 3 times, most recently from 3360003 to 7d1a603 Compare May 8, 2026 20:42
@pakrym-oai pakrym-oai force-pushed the pakrym/simplify-mcp-handler-plumbing branch from 7d1a603 to c22ab62 Compare May 8, 2026 20:46
@pakrym-oai pakrym-oai marked this pull request as ready for review May 8, 2026 21:23
@pakrym-oai pakrym-oai requested a review from a team as a code owner May 8, 2026 21:23

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 775d4cbd40

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread codex-rs/rollout-trace/src/tool_dispatch.rs
Comment thread codex-rs/core/src/tools/registry.rs Outdated

@sayan-oai sayan-oai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

very satisfying to review

@jif-oai jif-oai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I like the direction. I feel like it erases the semantic distinction, then recover it later through a generic path (the scan on the generic tags is the good example). Ideally we don't need this last step anymore in the future as it makes the flow not very smooth

(I still think we should solve the metrics cardinality issue)

Comment thread codex-rs/core/src/tools/router.rs
Comment thread codex-rs/core/src/tools/registry.rs Outdated
execution: "client".to_string(),
tools: Vec::new(),
},
ToolPayload::Mcp { .. } => ResponseInputItem::McpToolCallOutput {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This means a cancelled nested MCP call (through code-mode) will change it's output type. Good for me but to be checked with research

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'm actually not sure that user-cancellation works for code mode at all. Will followup.

…andler-plumbing

# Conflicts:
#	codex-rs/codex-mcp/src/connection_manager_tests.rs
#	codex-rs/core/src/tools/router_tests.rs
@pakrym-oai pakrym-oai enabled auto-merge (squash) May 11, 2026 23:59
@pakrym-oai pakrym-oai merged commit ed5944b into main May 12, 2026
38 of 39 checks passed
@pakrym-oai pakrym-oai deleted the pakrym/simplify-mcp-handler-plumbing branch May 12, 2026 00:11
@github-actions github-actions Bot locked and limited conversation to collaborators May 12, 2026
@pakrym-oai

pakrym-oai commented May 12, 2026

Copy link
Copy Markdown
Collaborator Author

Ideally we don't need this last step anymore in the future as it makes the flow not very smooth

Agreed but unfortunately we already publish those metrics and I don't want to break them. Fixed cardinality.

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