From 720932ca3d1a347a8c069ab8602dc201ef337e22 Mon Sep 17 00:00:00 2001 From: Francis Chalissery Date: Sun, 12 Apr 2026 13:19:36 -0700 Subject: [PATCH] [codex] Support flattened deferred MCP tool calls (#17556) ## Summary - register flattened handler aliases for deferred MCP tools - cover the node_repl-shaped deferred MCP call path in tool registry tests ## Root Cause Deferred MCP tools were registered only under their namespaced handler key, e.g. `mcp__node_repl__:js`. If the model/bridge emitted the flattened qualified name `mcp__node_repl__js`, core parsed it as an MCP payload but dispatch looked up the flattened handler key and returned `unsupported call` before reaching the MCP handler. ## Validation - `just fmt` - `cargo test -p codex-tools search_tool_registers_deferred_mcp_flattened_handlers` - `cargo test -p codex-core search_tool_registers_namespaced_mcp_tool_aliases` - `git diff --check` --- codex-rs/core/src/tools/spec.rs | 9 +++++++++ codex-rs/core/src/tools/spec_tests.rs | 2 ++ 2 files changed, 11 insertions(+) diff --git a/codex-rs/core/src/tools/spec.rs b/codex-rs/core/src/tools/spec.rs index bfad3cdb3..188be42ba 100644 --- a/codex-rs/core/src/tools/spec.rs +++ b/codex-rs/core/src/tools/spec.rs @@ -263,6 +263,15 @@ pub(crate) fn build_specs_with_discoverable_tools( } } } + if let Some(deferred_mcp_tools) = deferred_mcp_tools.as_ref() { + for (name, _) in deferred_mcp_tools.iter().filter(|(name, _)| { + !mcp_tools + .as_ref() + .is_some_and(|tools| tools.contains_key(*name)) + }) { + builder.register_handler(name.clone(), mcp_handler.clone()); + } + } builder } diff --git a/codex-rs/core/src/tools/spec_tests.rs b/codex-rs/core/src/tools/spec_tests.rs index da76a1bb2..b0195e456 100644 --- a/codex-rs/core/src/tools/spec_tests.rs +++ b/codex-rs/core/src/tools/spec_tests.rs @@ -909,6 +909,8 @@ fn search_tool_registers_namespaced_mcp_tool_aliases() { assert!(registry.has_handler(&ToolName::plain(TOOL_SEARCH_TOOL_NAME))); assert!(registry.has_handler(&app_alias)); assert!(registry.has_handler(&mcp_alias)); + assert!(registry.has_handler(&ToolName::plain("mcp__codex_apps__calendar_create_event"))); + assert!(registry.has_handler(&ToolName::plain("mcp__rmcp__echo"))); } #[test]