Skip to content

bug(codex): mocked MCP servers are written into the user's global ~/.codex/config.toml and left there #360

Done

Description

@karanb192

Description

On environment.type: none, the Codex engine installs MCP servers with codex mcp add (codex.go#L149), which writes to the user's global ~/.codex/config.toml. Before adding, it runs codex mcp remove for the same name (codex.go#L146), so a user's own server with that name, say a real github server, is replaced by the mock. Nothing removes the entry after the run, so every later Codex session on that machine, outside skill-up too, starts the mocked server. Claude Code installs with --scope project, so this only affects Codex.

Steps to reproduce

  1. Copy ~/.codex/config.toml aside.
  2. Run any Codex case with a mocked server on environment.type: none. Mine:
# SKILL.md body: call get_order on the shop MCP server and report the status it returns.

# evals/fixtures/mcp/shop.yaml
tool_responses:
  get_order:
    default:
      order_id: "{{params.order_id}}"
      status: SHIPPED-7F3Q

# evals/cases/lookup.yaml
id: lookup
input:
  prompt: What is the status of order 42? Use the shop tools.
judge:
  type: rule_based
  success:
    - tool_called:
        name: mcp__shop__get_order
    - output_contains:
        all: ["SHIPPED-7F3Q"]

# evals/eval.yaml
schema_version: v1alpha1
environment:
  type: none
skills:
  - source: local_path
    path: .
mcp:
  servers:
    - name: shop
      mode: mocked
      config_ref: evals/fixtures/mcp/shop.yaml
engine:
  name: codex
  model: {}
cases:
  files: [evals/cases/lookup.yaml]
  1. Diff the config against the copy.

Expected behavior

The user's Codex config is unchanged after the run, or skill-up uses a Codex home of its own.

Actual behavior

  • A new [mcp_servers.shop] table holds the whole generated Node script (136 added lines) and stays after the run.
  • Codex rewrites the file while adding it. Empty http_headers = {} tables and an empty args = [] disappear from unrelated servers, and a trust entry for the temporary workspace is added under [projects].
  • The eval session also loads every MCP server and the global instructions from the user's own Codex setup, so results depend on the machine.

Environment

  • skill-up 0.14.0-14-g99894b3 (main, built from source)
  • Codex CLI 0.166.0, preinstalled and logged in, account default model (gpt-6-astra in every run) (skill-up's default pin is 0.80.0, codex.go#L35)
  • Go 1.26.0, macOS arm64, environment.type: none

Additional context

Setting environment.env.CODEX_HOME to a separate folder keeps the global file untouched, but the session lookup hard-codes $HOME/.codex/sessions (codex.go#L1130), so it then misses the session file. A CODEX_HOME per case runtime, used by both install and lookup, with the user's auth.json copied in, would isolate local runs. Per case rather than per run, since two cases can mock the same server name with different fixtures.

Activity

  1. karanb192 commented on Nov 1, 2026

    @karanb192
    ContributorAuthor

    A proposal for the fix, before I write it. Your view on the open questions would help.

    Idea: stop running codex mcp add. Define each MCP server skill-up installs on the codex exec command itself, with -c mcp_servers.<name>.command=..., -c mcp_servers.<name>.args=[...], and the same flags on codex exec resume.

    What I checked with Codex CLI 0.166.0:

    What it would fix:

    1. No writes to the user's global config, and no leftover servers after a run.
    2. Each case's command carries its own servers, so parallel cases with same-named mocks no longer overwrite each other (the race raised on PR fix(codex): approve installed MCP servers under the local sandbox #362).
    3. Secrets: today --env KEY="$KEY" writes the value into config.toml. With env_vars = ["KEY"] Codex passes the variable from its own environment to the server, so the value never lands on disk. The variables would need to be set on the codex exec environment. One limit: two servers that need different values under the same variable name cannot both get them from one process environment, while today each server is installed with its own values.

    Open questions:

    1. Name collisions. A -c server merges with a same-named server already in the user's config. Over a stdio server, the command and args are replaced but fields such as env carry over. Over a URL server, Codex fails to load its config. Today skill-up removes the user's server instead. I'd fail fast with a clear message when the name exists (codex mcp get <name>). Falling back to remove and add would bring back the global writes and the cross-case overwrites.
    2. Environment values per server. For the secrets limit above: reject two servers that need different values under one variable name, or pass those values with -c mcp_servers.<name>.env={...}, which puts them on the command line where other local processes can read them. Which do you prefer?
    3. Command length. A mocked server's Node script, with the fixture's responses, would go on the command line. Large fixtures could exceed the argument size limit, so writing each script to a file in the case workspace and passing its path is the safer default.
    4. Machine dependence. Codex still loads the user's other MCP servers and global instructions. Setting environment.env.CODEX_HOME avoids that today; PR fix(codex): look up session files under CODEX_HOME #364 makes the session lookup follow it. A built-in per-case CODEX_HOME would need a local login copied in (API-key credentials already come through the environment), so I'd leave that out.

    If this direction works for you, I'll send it as one PR for the Codex engine.

  2. zpzjzj commented on Nov 27, 2026

    @zpzjzj
    Collaborator

    Fixed in #398. Both codex exec and codex exec resume now receive mocked MCP server definitions as command-line overrides. This keeps the definitions scoped to the case and leaves the user's global config.toml untouched by mock registration. Thanks for the report and the proposed fix. Closing as completed.

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

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions