Skip to content

[BUG] codex exec: MCP tools from tools/list are not injected into the model's tool set #38689

Open

Description

@JCY2023

Environment

  • codex-cli version: codex-cli 0.147.0-alpha.6.6(alpha channel)
  • OS: Windows 11 (native, x64)
  • MCP server type: streamable HTTP (ASP.NET / IIS), responses encoded as SSE (Content-Type: text/event-stream), stateless (no Mcp-Session-Id header returned)
  • Server side verified healthy: direct curl initialize / notifications/initialized / tools/list returns 200/202/200 with the full tool list

config.toml (minimal repro)

[mcp_servers.example-erp]
enabled = true
url = "http://<mcp-host>/mcp"

[mcp_servers.example-erp.http_headers]
Authorization = "Bearer <token>"

Steps to reproduce

  1. Configure a streamable HTTP MCP server as above (server returns tools via tools/list).
  2. Run:
    codex exec --json --skip-git-repo-check --sandbox workspace-write -C <temp-dir> -m <model> -c notify=[] "Call the MCP tool <tool> and return the result."
    
  3. Observe the agent's available tool set.

Expected behavior

Tools returned by tools/list are registered and callable by the model — as in Codex desktop (ChatGPT app) with the same config, where the same tools are visible and usable.

Actual behavior

The model reports the tools do not exist (e.g. "no erp_describe / erp_query tool in this session"). The MCP connection itself works fine:

  • codex sends initialize → notifications/initialized → tools/list and receives 200 with all tools (verified by a local reverse proxy capturing the actual HTTP exchange).
  • list_mcp_resources with server=<id> reaches the server and returns -32601: Method 'resources/list' is not available — proving the connection and authentication are working (a wrong token would have produced 401).
  • The model's tool set only contains built-in tools (shell_command, list_mcp_resources, ...); no tools from tools/list appear.

Config variants tried (none changed the behavior)

  • http_headers static Authorization (original)
  • bearer_token_env_var instead of the static header
  • explicit enabled_tools allowlist listing all server tools
  • -c features.tool_call_mcp_elicitation=false
  • approval_policy = { granular = { sandbox_approval=true, rules=true, mcp_elicitations=true, request_permissions=true, skill_approval=true } }
  • --sandbox read-only vs workspace-write; with/without -C and --skip-git-repo-check; temp dir vs trusted project dir
  • direct connection vs local reverse proxy

Diagnostics already performed

  • codex mcp list / codex mcp get <id> / codex doctor: server shown as enabled, transport streamable_http, auth "Bearer token", doctor reports MCP servers healthy (0 disabled, 0 failed).
  • RUST_LOG=codex_core=trace,reqwest=trace: shows the HTTP connection to the MCP host and the completed handshake, but no tool registration from the tools/list response.
  • Feature flags in this build: tool_call_mcp_elicitation = stable/true, mcp_2026_07_28 = under development/false, non_prefixed_mcp_tool_names = under development/false.

Impact

This blocks headless/non-interactive codex exec usage with streamable HTTP MCP servers (agent cannot use any MCP tool), while interactive clients (desktop) work with the identical configuration.

Version

codex --version → codex-cli 0.147.0-alpha.6.6

Activity

  1. added
    bug
    CLI
    exec
    mcp
    windows-os
    on Aug 15, 2026
  2. github-actions commented on Aug 15, 2026

    @github-actions
    Contributor

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

    Powered by Codex Action

  3. Ben-Home commented on Aug 15, 2026

    @Ben-Home

    The server-side curl checks are the right starting point, and the "SSE responses from a stateless server" detail is probably the crux. On streamable HTTP, the spec allows a server to answer a POST with either plain JSON or an SSE stream, and a stateless ASP.NET/IIS endpoint that always emits Content-Type: text/event-stream for tools/list will break clients that parse the POST response body as JSON. They read the event envelope (or an empty JSON body) and register zero tools, so the model never sees mcp__ tools even though /mcp-level connectivity and the server itself are healthy.

    Things to verify in order:

    1. Response shape per request. Run curl against tools/list specifically (not just initialize) and check Content-Type. If it returns text/event-stream with data: lines, try the same endpoint and confirm whether the client tolerates SSE framing on POST. The spec's GET stream and POST responses have different framing expectations; servers that conflate them produce exactly this "server verified healthy, client injects nothing" symptom.

    2. Session-id handling. Stateless (no Mcp-Session-Id) is legal, but some clients treat a missing session header as a protocol error and tear down the initialized session before tools/list. Confirm the server does not emit a session id on initialize but require it on later requests, which would also silently drop the tool list.

    3. Client-side visibility. Run codex with MCP logging enabled and look for the tools/list response as parsed by the client — if the log shows the raw SSE envelope or a parse error, the framing mismatch is confirmed and the fix belongs on the server (return application/json for POST tools/list; reserve SSE for the GET stream).

    This mirrors what we hit wiring streamable-HTTP servers into the gateway at corpusiq.io: framing consistency between POST-JSON and GET-SSE was the single highest-yield fix for "server says connected, client sees no tools" reports across different client implementations.

  4. TarjinderSingh commented on Aug 15, 2026

    @TarjinderSingh

    I have a possibly related macOS A/B reproduction, with one important difference: the MCP tool is injected and the call starts, but execution then fails with an empty error.

    • ChatGPT Desktop: 26.810.50856
    • Bundled Codex CLI 0.148.0-alpha.9: tool starts, then fails with Error calling tool '<tool>': and no error text
    • Standalone Codex CLI 0.147.0: the identical tool call completes
    • Transport: authenticated Streamable HTTP on localhost
    • Both tests used the same shell, inherited token, configuration, server, sandbox, model, and prompt

    An authenticated MCP initialize also succeeds independently. This suggests a version-specific failure after tool registration rather than the tool-injection failure described in this issue.

    I filed the complete sanitized reproduction at: #38794

  5. jdcodes1 commented on Aug 17, 2026

    @jdcodes1

    Traced this on main @ 1f41cc5, and there's a mechanism that fits every one of your observations — including why your RUST_LOG capture showed a healthy handshake but no registration.

    Optional MCP servers get a 1-second startup grace before being silently omitted from the model's tool set. When the turn builds its tool binding, any non-required server whose startup hasn't completed is given OPTIONAL_MCP_STARTUP_GRACE — hardcoded to 1s — and then dropped from the catalog with only a trace-level log:

    required_servers: &[String],
    ) -> McpBinding {
    let revision = self.tool_catalog_revision.read().await;
    let mut listed_tools = Vec::new();
    let mut clients = std::collections::HashMap::new();
    join_all(self.servers.iter().map(|(server_name, view)| async move {
    if !view
    .connection
    .client
    .startup_complete
    .load(Ordering::Acquire)
    {
    let required = self.required_servers.binary_search(server_name).is_ok();
    let has_cached_tools = view.connection.client.has_cached_tools();
    let must_wait_for_startup = (required
    && (!view.connection.startup_is_dormant() || !has_cached_tools))
    || self.is_selected_plugin_mcp_server(server_name)
    || required_servers
    .iter()
    .any(|required| required == server_name)
    || (server_name == CODEX_APPS_MCP_SERVER_NAME && !has_cached_tools);
    if !must_wait_for_startup && has_cached_tools {
    return;
    }
    if !must_wait_for_startup {
    let optional_startup_deadline = if view.connection.startup_is_dormant() {
    tokio::time::Instant::now() + OPTIONAL_MCP_STARTUP_GRACE
    } else {
    *self.optional_startup_deadline.get_or_init(|| {
    tokio::time::Instant::now() + OPTIONAL_MCP_STARTUP_GRACE
    })
    };
    let startup_deadline = view
    .connection
    .client
    .tool_catalog_cache_context
    .as_ref()
    .map(|cache| cache.optional_startup_deadline(optional_startup_deadline))
    .unwrap_or(optional_startup_deadline);
    if tokio::time::timeout_at(startup_deadline, view.connection.client())
    .await
    .is_err()
    {
    trace!(server_name = %server_name, "omitting pending optional MCP server");
    }
    return;
    }
    let _ = view.connection.client().await;
    }
    }))
    .await;

    (const OPTIONAL_MCP_STARTUP_GRACE: Duration = Duration::from_secs(1) at #L35; the omission logs "omitting pending optional MCP server".) User-configured servers are "optional" here — required_servers is a separate turn-level concept — so nothing forces the wait.

    Why codex exec fails while Desktop works with identical config: exec is one-shot — its only sampling request snapshots the binding immediately at session start, so a streamable-HTTP server doing initialize → initialized → tools/list over a real network on a cold start loses the 1-second race essentially every time. The wire exchange still completes (your reverse-proxy capture) — just after the binding was already taken, and exec never builds another one. Desktop sessions are long-lived: by the second turn (or the next MCP refresh) startup is complete and the tools appear. list_mcp_resources working is also consistent: that goes through the live connection rather than the pre-snapshotted tool catalog.

    Why your trace didn't show it: the omission message is logged under the codex_mcp target at TRACE level; your filter RUST_LOG=codex_core=trace,reqwest=trace doesn't include it. A directly actionable next step that would confirm this end-to-end on your setup:

    RUST_LOG=codex_mcp=trace codex exec ... 2> mcp-trace.log
    # then look for: "omitting pending optional MCP server"
    

    If the line appears, this is confirmed. (One alternative worth ruling out while you're in there: with a stateless server that returns no Mcp-Session-Id, if startup_complete never flips — e.g. the client blocks establishing the follow-up SSE stream — you'd see the same omission on every snapshot; the trace will show whether startup eventually completes or hangs.)

    Fix outline:

    1. For codex exec (single-turn, cold cache), treat configured MCP servers as required for the first binding — or scale the grace with an explicit flag/config (--wait-for-mcp / mcp_startup_timeout) instead of a hardcoded 1s that no headless network server can reliably meet.
    2. Surface the omission as a user-visible warning ("MCP server example-erp was still starting and was excluded from this turn") rather than a trace line — your report documents several hours of elimination work that a single warning would have prevented.
    3. The tool-catalog cache already softens this for warm starts; exec runs with fresh -C temp dirs defeat it, which is exactly the headless CI/automation profile this issue is about.
  6. aldi949 commented on Sep 23, 2026

    @aldi949

    @JCY2023 hey — I'm looking into cases where MCP appears correctly configured but the actual tool set reaching the model is different.

    Did you eventually find a workaround for this, and is it still reproducible?

    Also, was figuring out where the tools disappeared actually time-consuming? I'm trying to understand whether there's a broader observability/debugging problem here rather than just individual MCP bugs.

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

    CLIbugexecmcpwindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions