Skip to content

bug: -c 'mcp_servers={}' silently no-ops instead of clearing MCP servers #16045

Open

Description

@chriscoey

Summary

-c 'mcp_servers={}' is intended to clear all MCP servers for a single invocation, but it silently does nothing. TOML {} creates an empty inline table that merges non-destructively with the existing config, leaving all servers enabled.

Repro

# config.toml has MCP servers defined
codex mcp list
# Shows: context7 (enabled), fetcher (enabled), tavily (enabled), ...

# Attempt to clear all servers
codex mcp list -c 'mcp_servers={}'
# Expected: no servers, or all disabled
# Actual: identical output — all servers still enabled

# Workaround: disable per-server
codex mcp list -c 'mcp_servers.context7.enabled=false'
# This works — context7 shows as disabled

Why this matters

Users running codex exec programmatically (e.g., from Claude Code or CI) want lightweight invocations without MCP server overhead. The intuitive override mcp_servers={} appears to work (no error) but silently loads all servers anyway, adding ~5K tokens of tool schemas and boot latency per call.

The per-server workaround (-c 'mcp_servers.X.enabled=false' repeated for each server) works but doesn't scale — you need to know every server name and add a -c flag for each one.

Suggested fix

Either:

  1. Treat -c 'mcp_servers={}' as "replace the table" rather than "merge empty table" (breaking but correct)
  2. Add a --disable-all-mcp flag or --no-mcp shorthand
  3. Document the limitation in codex exec --help

Environment

  • codex v0.117.0-alpha.24
  • macOS 15.4

Activity

  1. added
    bug
    CLI
    mcp
    on Mar 27, 2026
  2. pacphi commented on Aug 26, 2026

    @pacphi

    Still no-ops on 0.149.1 (macOS arm64), and the per-server form no-ops too: with codex exec --json -c 'mcp_servers={ruflo={command="ak",args=["x","ruflo-mcp"]}}' — and likewise -c mcp_servers.<name>.enabled=false — the session still lists every config- and plugin-provided server when asked to enumerate them (7 servers in my case). Since plugins also mount servers regardless of config.toml, there is currently no per-invocation way to constrain the MCP roster for supervised exec runs. Either honoring the override or erroring loudly would unblock hermetic/CI exec use-cases.

  3. pacphi commented on Sep 27, 2026

    @pacphi

    Follow-up on my earlier note, checked on Codex CLI 0.157.1 (macOS arm64) in a fresh CODEX_HOME
    with one stdio server: codex mcp list --json -c 'mcp_servers={}' still lists the server as
    "enabled": true, so an override cannot clear the table. -c mcp_servers.<name>.enabled=false
    is honored by mcp list (it reports "enabled": false; checked with codex mcp list only, I have
    not re-run the exec roster check from my earlier note), and that is what we now use, one
    server at a time. Is clearing mcp_servers with an override meant to work, or is per-server
    disabling the supported way?

  4. pacphi commented on Sep 28, 2026

    @pacphi

    Re-checked this on the latest Codex CLI in a fresh CODEX_HOME — the behavior is unchanged: -c 'mcp_servers={}' still silently no-ops instead of clearing the MCP server table. This is now confirmed across three releases (0.149.1, 0.157.1, 0.158.0) over about seven months, so it doesn't look like a transient regression — the TOML-merge behavior described in the original report still applies.

    System info

    • macOS 27.0 (BuildVersion 26A428), arm64
    • Node v26.4.0, npm 11.17.0
    • Codex CLI 0.158.0 (npm install -g @openai/codex@latest)

    Steps to reproduce (disposable CODEX_HOME, no real config touched)

    config.toml:

    [mcp_servers.testserver]
    command = "true"
    args = []
    $ codex mcp list --json
    [{"name":"testserver","enabled":true, ...}]
    
    $ codex mcp list --json -c 'mcp_servers={}'
    # expected: no servers, or all disabled
    # actual: identical output, unchanged
    [{"name":"testserver","enabled":true, ...}]

    The per-server workaround still works as documented:

    $ codex mcp list --json -c 'mcp_servers.testserver.enabled=false'
    [{"name":"testserver","enabled":false, ...}]

    I also checked for a dedicated suppression flag in case one had shipped since the last update — codex mcp --help and codex exec --help still only expose -c/--config and the generic --enable/--disable <FEATURE> toggles, nothing MCP-roster-specific.

    Proposed fix approaches (unchanged from the original report, still the live options as far as I can tell)

    1. Make -c 'mcp_servers={}' replace the table instead of merging an empty one into the existing config — this is the behavior most users reaching for this override actually expect, even though it's technically breaking for anyone relying on the current merge semantics.
    2. Add an explicit --no-mcp / --disable-all-mcp flag that's unambiguous regardless of TOML merge semantics.
    3. At minimum, document the merge behavior for table-valued overrides in codex exec --help / codex mcp --help so it fails predictably instead of silently.

    Impact

    For anyone using -c overrides in scripts, CI, or wrapper tooling, this is a silent-failure trap: the command exits 0 and produces no error, so there's nothing to catch in an automated pipeline — the only way to notice is to diff the server roster by hand. For projects like agentic-kit that shell out to codex exec for hermetic/lightweight subprocess runs, it means the per-invocation MCP suppression we'd want for CI has to fall back to enumerating and disabling every server by name, which is brittle against config changes and doesn't scale with plugin-mounted servers.

    Would appreciate a maintainer read on whether "replace" semantics for mcp_servers={} is the intended direction, or whether per-server disabling is meant to remain the supported path going forward (as asked in the thread above) — happy to help verify a fix once there's a POC to test against. Thanks for looking at this!

  5. RandyNorthrup commented on Nov 2, 2026

    @RandyNorthrup

    Still reproduced on codex-cli 0.166.0 (npm @openai/codex latest on 2026-11-02), macOS 15.7.4 (24G517), Darwin 24.6.0 x86_64. Throwaway CODEX_HOME, not signed in, no model selected.

    config.toml had two stdio servers, docs and other, each with command /bin/true.

    codex mcp list --json and codex mcp list --json -c 'mcp_servers={}' both exit 0 and list both servers with "enabled": true. The file's headings are unchanged.

    codex mcp list --json -c 'mcp_servers.docs.enabled=false' lists docs with "enabled": false and other with "enabled": true, so the per-server form works.

    codex mcp --help and codex exec --help still have no all-off flag. codex exec --help documents --ignore-user-config ("Do not load $CODEX_HOME/config.toml"). codex mcp list --ignore-user-config exits 2 with unexpected argument '--ignore-user-config'. I did not run codex exec, so I have not checked whether that flag drops MCP servers. It also skips the whole user config, which is wider than an MCP switch.

    Please make mcp_servers={} clear the table for one invocation, or add a single flag that disables every MCP server for one run.

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

    CLIbugmcp

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions