Skip to content

Flatten MCP namespace tools for unsupported providers - #28271

Closed
kotakem-openai wants to merge 6 commits into
mainfrom
kotakem/issue-26234-flatten-mcp-tools
Closed

kotakem-openai wants to merge 6 commits into
mainfrom
kotakem/issue-26234-flatten-mcp-tools

Conversation

@kotakem-openai

@kotakem-openai kotakem-openai commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #26234.

Some Responses API-compatible providers do not understand Codex's proprietary type: "namespace" tool wrapper. When MCP tools are only exposed through that wrapper, those providers never see callable MCP functions.

This change adds a provider capability for namespace tool support and flattens namespace tools into plain functions when the active provider does not support the wrapper.

Manual repro is attached on #26234.

What Changed

  • Added namespace_tools to ModelProviderInfo.
  • Kept namespace support enabled by default for built-in OpenAI, Azure, and Amazon Bedrock providers; non-OpenAI configured providers flatten by default unless explicitly overridden.
  • Allowed Amazon Bedrock config to opt out with namespace_tools = false.
  • Flattened namespaced tools to canonical <namespace>__<tool> function names when namespace tools are disabled.
  • Kept deferred MCP discovery available through tool_search when namespaces are flattened, and flattened deferred search results before returning them to the model.
  • Rejected duplicate canonical flat names for app-server dynamic tools before they can become ambiguous after flattening.
  • Added registry fallback so flat <namespace>__<tool> calls resolve back to the namespaced runtime.
  • Preserved namespace_tools through remote thread config serialization.
  • Regenerated config schema.
  • Added unit and RMCP integration coverage for flattened MCP exposure, deferred discovery, collision rejection, and Bedrock opt-out.

Test Plan

  • just test -p codex-app-server validate_dynamic_tools_rejects_duplicate_canonical_flat_name
  • just test -p codex-core handler_resolves_flat_name_to_namespaced_runtime namespace_tools_disabled_flattens_mcp_namespace_into_function mcp_and_tool_search_follow_direct_and_deferred_tool_exposure search_results_flatten_mcp_namespaces_without_namespace_tools
  • just test -p codex-protocol
  • just test -p codex-tools
  • just test -p codex-model-provider-info test_merge_configured_model_providers_applies_amazon_bedrock_namespace_tools_override test_merge_configured_model_providers_applies_amazon_bedrock_allowed_overrides_together test_merge_configured_model_providers_rejects_amazon_bedrock_non_default_fields
  • just test -p codex-core accepts_amazon_bedrock_namespace_tools_override load_config_applies_amazon_bedrock_namespace_tools_override load_config_applies_amazon_bedrock_allowed_overrides_together load_config_rejects_unsupported_amazon_bedrock_overrides

@kotakem-openai
kotakem-openai requested a review from a team as a code owner June 15, 2026 07:38

@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: 6219b01856

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/core/src/tools/spec_plan.rs Resolved
Comment thread codex-rs/model-provider/src/provider.rs Resolved
@kotakem-openai
kotakem-openai marked this pull request as draft June 15, 2026 08:56
@kotakem-openai
kotakem-openai marked this pull request as ready for review June 17, 2026 06:31

@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: 785a5a6fae

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/tools/src/responses_api.rs Resolved
Comment on lines +770 to +771
let exposure = if search_tool_enabled(turn_context) {
ToolExposure::Deferred

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.

P2 Badge Preserve spawn-agent hook names after flattening

When search_tool_enabled is true for a provider with namespace_tools = false, v1 multi-agent tools now load through tool_search as flat functions like multi_agent_v1__spawn_agent. The registry fallback executes the namespaced SpawnAgentHandler, but the invocation name remains the flat plain name, so function_hook_tool_name no longer maps the call to HookToolName::spawn_agent() with the Agent alias. Existing pre/post hook policies that match spawn_agent or Agent therefore stop applying in exactly this flattened v1 path; either dispatch with the matched runtime's canonical ToolName or recognize the flattened v1 names in the hook-name special case.

Useful? React with 👍 / 👎.


fn capabilities(&self) -> ProviderCapabilities {
ProviderCapabilities {
namespace_tools: resolve_namespace_tools(&self.info),

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.

P2 Badge Keep standalone tools available for Responses Lite

For a configured non-OpenAI provider whose model uses Responses Lite, this new default makes namespace_tools false, but hosted_model_tool_specs returns no hosted web/image tools for Responses Lite and standalone_web_search_enabled / standalone_image_generation_model_visible still require namespace support before extension tools are even registered. That means providers that need flattened tools lose web.run and image_gen.imagegen entirely instead of exposing them as flat functions, so Responses Lite sessions cannot use those features unless they opt back into the wrapper they may reject.

AGENTS.md reference: AGENTS.md:L103-L110

Useful? React with 👍 / 👎.

@willfish

Copy link
Copy Markdown

Tested this locally against a real OpenRouter + MCP setup and this PR fixes the failure mode for me.

Environment:

  • NixOS/Linux x86_64
  • baseline: installed Codex 0.141.0
  • PR build: 0b7b2436bb2b from this branch, built with Rust 1.95.0
  • custom provider: openrouter, wire_api = "responses", model x-ai/grok-4.3
  • provider override for the PR run: namespace_tools = false
  • MCP server: stdio Jira server exposing jira_search

Baseline result with Codex 0.141.0, same profile/config/prompt:

I cannot call jira_search because no tool with that name (or any Jira-related MCP tool) is present in the available tools for this session.

PR result with the same profile/config/prompt:

{"type":"item.started","item":{"type":"mcp_tool_call","server":"jira","tool":"jira_search","arguments":{"jql":"issuetype = Story AND creator = currentUser() ORDER BY created DESC","fields":"key,summary,status,created","limit":1}}}

The call completed successfully and returned the expected Jira issue:

AI-890 - Expose hybrid classification search and tariff note evidence to MCP
status: In Progress
created: 2026-06-19T14:47:00.539+0100

One local note: running the probe with --sandbox read-only caused the model to report network access was restricted, so I used --sandbox danger-full-access for the MCP verification run. The prompt explicitly told the model not to edit files or use shell commands; the JSONL trace showed only the Jira MCP tool call.

So from my side this validates the flattened-tool path for OpenRouter/Grok and restores MCP tool use that is absent in 0.141.0.

@kotakem-openai
kotakem-openai marked this pull request as draft June 23, 2026 06:31
@kotakem-openai
kotakem-openai force-pushed the kotakem/issue-26234-flatten-mcp-tools branch 2 times, most recently from 5c6d729 to 42961ed Compare June 23, 2026 09:21
@kotakem-openai kotakem-openai changed the title Flatten MCP namespace tools for unsupported providers Flatten namespace tools for providers without wrappers Jun 23, 2026
@kotakem-openai
kotakem-openai force-pushed the kotakem/issue-26234-flatten-mcp-tools branch from 42961ed to 18fecc6 Compare June 23, 2026 09:25
@kotakem-openai kotakem-openai changed the title Flatten namespace tools for providers without wrappers Flatten MCP namespace tools for unsupported providers Jun 23, 2026
@kotakem-openai

Copy link
Copy Markdown
Contributor Author

Closing this PR in favor of #29602.

After working through the review feedback, I realized this approach was conflating two separate concerns: whether a provider accepts Codex's type: "namespace" wire wrapper, and whether namespaced tools should be registered or discoverable at all. That led to follow-up issues around deferred MCP discovery, Responses Lite standalone tools, and other paths that should remain available even when namespace wrappers are unsupported.

#29602 takes a narrower approach: it treats namespace_tools only as a provider wire-serialization capability. Codex keeps the logical namespaced tool registry and discovery behavior intact, then flattens model-visible namespace specs into canonical plain function names only when the active provider cannot accept namespace wrappers.

This supersedes the implementation in this PR, so I am closing this one to keep review focused on the revised approach.

EmilLindfors added a commit to Fraktal-Norge-AS/fraktal-codex that referenced this pull request Aug 3, 2026
Checked before filing: the namespace_tools defect is already reported
upstream as openai#26234 (open since 2026-06-03, `bug`, 29 comments, reference
branch attached) and openai#33263. Two fix PRs, openai#28271 and openai#29602, were
authored by an OpenAI engineer and both closed unmerged without
explanation.

So this is not a transitional patch awaiting an upstream fix — plan to
carry it. Records the evidence, and notes that openai#26234's per-provider
`namespace_tools` config (defaulting to `requires_openai_auth`) is a
better shape than our global feature flag if we revisit it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flatten MCP namespace tools for non-OpenAI Responses API providers (Ollama, LM Studio, OpenRouter)

2 participants