Skip to content

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

Open

Description

@LucaCappelletti94

When Codex runs against a non-OpenAI Responses API endpoint such as a local server (Ollama, LM Studio), a gateway (OpenRouter), or AWS Bedrock Mantle, tools provided by MCP servers are never callable by the model. Codex serializes each MCP server's tools inside a proprietary {"type": "namespace", "name": "mcp__<server>", "tools": [...]} wrapper, which is not part of the standard OpenAI Responses API. OpenAI and Azure expand the wrapper and reach the nested tools, but other Responses API backends pass it through unchanged or reject any tool whose type is not function, so the model only ever sees a single non-callable mcp__<server> tool and the MCP tools are unusable.

I have a fix implemented and tested on this branch: https://github.com/LucaCappelletti94/codex/tree/flatten-mcp-tools-for-non-namespace-providers

The fix gives providers a namespace_tools capability. An explicit namespace_tools in [model_providers.<id>] config wins, otherwise it defaults to requires_openai_auth, so OpenAI and Azure keep namespaces while other Responses API providers get flattened tools. When the capability is off, each namespace is flattened into plain function tools named mcp__<server>__<tool> instead of being dropped, and the tool registry resolves a flat call name back to its namespaced runtime so the call dispatches correctly. The resolution side also covers tool names that a proxy flattens on its own. Bedrock keeps namespaces on by default but can opt out for Mantle with namespace_tools = false.

Unit tests cover the capability resolution (auto and explicit override), namespace flattening into canonical function specs rather than dropping them, and flat-name resolution to the namespaced runtime. I also verified the change end to end against Ollama with both gpt-oss:20b and gpt-oss:120b plus a real MCP server: the request now carries the MCP tool as a flat function named mcp__<server>__<tool> with no namespace wrapper, the model calls it, and the tool executes.

Related to #23186, #19871, #20652, and #25034 (Mantle can opt out with namespace_tools = false).

Activity

  1. added
    bug
    CLI
    mcp
    custom-model
    on Jun 3, 2026
  2. justaddcoffee commented on Jun 3, 2026

    @justaddcoffee

    +1 for this PR!

  3. github-actions commented on Jun 3, 2026

    @github-actions
    Contributor

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    Powered by Codex Action

  4. LucaCappelletti94 commented on Jun 3, 2026

    @LucaCappelletti94
    Author

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    * [amazon-bedrock provider: namespace_tools capability breaks Bedrock Mantle (validation_error) #25034](https://github.com/openai/codex/issues/25034)
    

    Powered by Codex Action

    No, that is not a related solution (and it does not work as commented by some other person). Also, this is primarily related to open models. My solution works with any open model with tooling supporting the Responses API.

  5. MathieuBo commented on Jun 3, 2026

    @MathieuBo

    +1 for this PR

  6. AO33 commented on Jun 3, 2026

    @AO33

    +1 for this PR

  7. GGBondBlueWhale commented on Jun 3, 2026

    @GGBondBlueWhale

    +1 for this PR

  8. SylvainWinning commented on Jun 3, 2026

    @SylvainWinning
  9. blakelai commented on Jun 4, 2026

    @blakelai

    +1

  10. madarkadonk commented on Jun 4, 2026

    @madarkadonk

    +1 - this is happening with my vLLM-hosted Qwen 3.6, spent yesterday trying to diagnose what was happening trying to use an MCP tool and this matches it exactly.

  11. LucaCappelletti94 commented on Jun 4, 2026

    @LucaCappelletti94
    Author

    @madarkadonk feel free to use my fork in the meantime and do let me know whether any issue come out of it. So far it seems to work on my end.

  12. justaddcoffee commented on Jun 4, 2026

    @justaddcoffee

    @madarkadonk also please promote this issue / PR! We feel like this really would improve codex

  13. 11 remaining items

  14. added
    aws-bedrock
    on Jun 29, 2026
  15. xyun1996 commented on Jul 1, 2026

    @xyun1996

    Also experiencing this with the Xunfei (讯飞) custom provider via --profile xunfei.
    Setup:

    • codex-cli 0.142.5 on Windows
    • model_provider = "xunfei" with wire_api = "responses" (OpenAI-compatible endpoint)
    • Figma MCP configured as HTTP with OAuth (works perfectly with default OpenAI model)
    • Tavily MCP same issue
      When using --profile xunfei:
    • All MCP tools return unsupported call
    • codex mcp list shows servers as enabled with correct OAuth status
    • list_mcp_resources and read_mcp_resource still work (resources are accessible)
    • Only tool invocation is broken
      Workaround attempted: using mcp-remote as a stdio proxy — this fails for Figma because Figma's MCP server rejects non-whitelisted
      OAuth clients (403 Forbidden). It works for Tavily since Tavily accepts API keys in the URL.
      Current workaround: switch back to default OpenAI model when Figma access is needed, then back to xunfei for regular coding. Not
      ideal.
      This is the same root cause as MCP tool invocation regressed for custom/local providers (Ollama Responses API) in v0.117.0+ #19871 and MCP servers disappear from session when using a custom provider #19363. Has been open since April — any updates on a fix?
  16. philippgille commented on Jul 11, 2026

    @philippgille

    I messaged OpenRouter and asked them if they could create a plugin to fix these request issues. They already have a "JSON Response Healer" plugin, and it sounds like it should be possible to have a "Codex Request Healer" plugin that rewrites the Codex request JSON to match the Responses API spec.

  17. madarkadonk commented on Jul 12, 2026

    @madarkadonk

    openai preferred PR 28271, then closed that one in favor of 29602, then closed 29602 with no explanation. Seems like supporting third party models isn't their priority, which I guess isn't too surprising, though disappointing.

  18. oddm643 commented on Jul 14, 2026

    @oddm643

    @madarkadonk yes, exactly... this is what I've just seen right now. A bit disappointed honestly...

  19. ajg360 commented on Jul 30, 2026

    @ajg360

    +1

    I am also trying to use Codex (0.146.0) with a local model, and I cannot make MCP tool calls because of this issue either.

    It seems like one of the related PRs fixes this, but it was closed before it was merged in? Is there any explicit reason for this?

    #29602

  20. oddm643 commented on Jul 31, 2026

    @oddm643

    Still waiting for a response to this

  21. metrofun commented on Aug 2, 2026

    @metrofun

    I’m the author of Swobu, a local compatibility gateway.

    I reproduced this namespace failure and shipped an intermediary workaround in Swobu v1.0.0-rc.4. Swobu projects namespaced MCP tools into backend-compatible function names, keeps an attempt-scoped reverse mapping, and restores the original {namespace, name} identity before returning the tool call to Codex.

    I verified the complete path on August 2, 2026 using:

    • Codex CLI 0.132.0
    • Swobu v1.0.0-rc.4
    • OpenRouter with openai/gpt-4.1-mini
    • the public Microsoft Learn MCP server

    Codex successfully executed microsoft_docs/microsoft_docs_search and returned a grounded Microsoft Learn URL.

    Install Swobu:

    curl -fsSL https://swobu.com/install.sh | sh

    Then point a Codex profile at the configured Swobu workspace:

    [model_providers.swobu]
    name = "Swobu"
    base_url = "http://127.0.0.1:7926/c/<workspace>/v1"
    env_key = "SWOBU_CLIENT_API_KEY"
    wire_api = "responses"
    supports_websockets = false
    
    [profiles.swobu]
    model = "<route-or-model>"
    model_provider = "swobu"

    The Codex-facing client key can be a placeholder; backend credentials remain configured in Swobu.

  22. jpvelasco commented on Aug 4, 2026

    @jpvelasco

    Additional sanitized reproduction data:

    • Environment: Codex CLI 0.146.0 on Windows, a custom OpenAI-compatible Responses endpoint, and tool-capable Qwen-family models.
    • The endpoint produces genuine function-call output when the request contains ordinary function tools.
    • With the stock Codex request containing namespace, custom, or hosted tool definitions, the same models instead emit textual tool-like markup and Codex records no command_execution event.
    • A custom provider configuration has no apparent capability setting to advertise or filter unsupported tool types.
    • Workaround: setting web_search = "disabled" and disabling the apps, plugins, multi_agent, image_generation, and tool_suggest feature groups restores genuine shell command_execution events. This was verified from fresh ephemeral processes across six served models; the verifier explicitly rejects textual imitations of tool calls.

    Expected behavior: third-party Responses providers should be able to declare supported tool kinds, or Codex should filter/flatten unsupported tool definitions before sending the request.

  23. lzp401 commented on Aug 4, 2026

    @lzp401

    I reproduced this on the current stable CLI with a GLM custom Responses provider. The failure is not specific to Streamable HTTP or to a private MCP server.

    Environment

    • Codex CLI: 0.146.0
    • Platform: macOS / Darwin arm64
    • Custom provider: Volcengine Ark, GLM-5.2, wire_api = "responses"
    • MCP control: codegraph, configured as an enabled STDIO server

    Controlled reproduction

    To avoid sending private repository data to the provider, I created a temporary synthetic Git repository containing only a marker string, CODEGRAPH_SYNTHETIC_OK.

    I then ran codex --profile <glm-profile> exec with:

    • codegraph enabled and approved for read-only tool use
    • other ordinary MCP servers disabled
    • a prompt that required a real codegraph MCP call to find the marker
    • shell/file reads and generic MCP resource helpers explicitly disallowed as fallbacks

    Before the model run, codex --profile <glm-profile> mcp get codegraph reported the server as enabled with transport: stdio and the expected command/arguments.

    Observed model-facing state:

    • no mcp__codegraph__* tools
    • no tool_search
    • only core tools plus generic list_mcp_resources / read_mcp_resource helpers
    • no mcp_tool_call event was emitted
    • the model reported codegraph as unavailable

    The relevant feature state in 0.146.0 is:

    tool_search                         removed            false
    tool_search_always_defer_mcp_tools   removed            true
    

    This makes the registered STDIO MCP tools unreachable to this custom provider: they are not exposed directly, and the session has no discovery tool with which to load them.

    Transport comparison and control

    I observed the same missing-tool behavior with a healthy Streamable HTTP MCP server whose initialize and tools/list calls succeed, so the failure is not specific to STDIO versus Streamable HTTP.

    As a compatibility control, I ran Codex 0.136.0 with the same GLM provider through a localhost adapter that only:

    1. flattens Responses namespace tools into ordinary functions named mcp__<server>__<tool>, and
    2. restores the namespace/name on returned function calls before Codex dispatch.

    That control produced a real MCP tool call and a successful tool result. This is consistent with the namespace_tools = false / flattened-dispatch direction proposed in this issue.

    Expected behavior

    For a custom Responses provider, Codex should either:

    • provide a functional tool_search path for deferred MCP tools, or
    • fall back to directly exposed, flattened function tools when namespace/deferred discovery is unsupported.

    The synthetic repository was deleted after the test. No private repository content, internal endpoint, or credential is included in this report.

  24. mdunphy commented on Aug 8, 2026

    @mdunphy

    A workaround for this issue is to use a proxy to flatten the request and unflatten the response: https://gist.github.com/mdunphy/6c2cf14aefddeb0d627d79c8e5d366cd

    (The rewrite_roles() part is not needed for fixing MCP, that was to fix something else)

  25. thesobercoder commented on Aug 9, 2026

    @thesobercoder

    Additional Codex Desktop reproduction through CLIProxyAPI:

    • With the same Desktop installation and gateway, GPT/Codex routes receive and successfully call app tools such as list_threads, read_thread, browser tools, and workspace tools.
    • DeepSeek, Claude, Gemini, and other non-OpenAI models behind the same OpenAI-compatible Responses endpoint do not receive those deferred app tools or a functional client-side tool_search path.
    • The MCP servers are registered correctly. The failure is in the model-visible namespace/deferred-tool representation, not MCP registration.
    • Static model catalogs, MCP imitations, and proxy-side discovery translation are not robust substitutes because Codex owns local discovery execution, namespace dispatch, schema handling, attachments, and task state.

    This appears to be the same compatibility boundary addressed by closed PR #29602, whose scope explicitly included flattened namespace tools, deferred tool_search results, standalone extension tools, collision handling, and reverse dispatch. It also manifests in Codex Desktop as described in #30523.

    Is there a replacement for #29602, or can its provider-capability approach be revived? Custom Responses providers need either:

    1. a supported namespace_tools / client-tool-search capability, or
    2. a Codex-side fallback that exposes deferred tools as ordinary flattened functions and restores their logical namespace during dispatch.

    Without this, custom providers are nominally supported but cannot use the complete Codex Desktop tool surface.

  26. dhar174 commented on Aug 11, 2026

    @dhar174
  27. TaylorHawkes commented on Sep 17, 2026

    @TaylorHawkes

    Adding a data point from the provider side, plus a server-side option for people who can't run a patched Codex or a local proxy.

    Confirmed with codex-cli 0.154.0 against an OpenAI-compatible Responses endpoint: each MCP server arrives as one {"type":"namespace","name":"mcp__<server>","tools":[...]} entry, and Codex's own sub-agent tools (multi_agent_v1 / collaboration) come wrapped the same way. If the backend drops the wrapper, the model never sees the MCP tools. In my first capture the model found the MCP server's script on disk and piped JSON-RPC into it by hand; the answer was right and the MCP server logged zero calls, which is a nasty way for this to hide.

    Disclosure: I run inferenceapis.com, so the next part is about my endpoint. I implemented the same translation @mdunphy's proxy does, but in the provider's /v1/responses, so there's nothing to run locally and streaming is preserved:

    • each namespace is expanded into flat function tools named <namespace>__<tool> (names over 64 chars are shortened and mapped back);
    • namespaced function_call items Codex replays in the history are flattened the same way;
    • every call comes back as function_call with namespace + name restored, in response.output_item.added/done events as well as the final response, so Codex's router dispatches it;
    • a call the model makes by the bare tool name is accepted when only one namespace has that tool;
    • the response carries X-Namespace-Tools: N flattened so you can see it happened.

    Tested with a real stdio MCP server whose data the model can't know: the server logged both tool calls and the answer was correct on DeepSeek V4 Flash / V4.1 Flash / V4 Pro, GLM 5.3 / 5.3 Flash, MiniMax M3, Kimi K2.7 Code, GPT-OSS 120B and Qwen3-VL 235B. Sub-agents (spawn_agent → wait_agent) work through the same fix, and Multi-Agent V2 agent_message hand-offs (#33551) are converted to user messages too.

    Config is just the provider block, MCP servers unchanged:

    [model_providers.inferenceapis]
    name = "Inference APIs"
    base_url = "https://api.inferenceapis.com/v1"
    env_key = "INFERENCE_API_KEY"
    wire_api = "responses"

    Write-up with the captured request/response shapes and the per-model table: https://inferenceapis.com/reference/errors/codex-mcp-tools-unsupported-call-custom-provider?src=gh26234

    None of this replaces the fix proposed in this issue: once Codex flattens for non-OpenAI providers itself, flat tools pass straight through unchanged. Happy to share the capture scripts or the MCP test server if useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIaws-bedrockbugcustom-modelmcp

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions