Skip to content

CLI: forward thread-scoped mcp_servers.<name>.env to the managed app-server (per-pane MCP identity) #50877

Open

Description

@p-poppe

What variant of Codex are you using?

CLI (0.160.0, managed app-server daemon), Windows 11. The same gap exists on macOS and Linux.

What feature would you like to see?

Let the CLI/TUI set thread-scoped MCP server environment when it starts or resumes a thread, the same way any other app-server client already can.

Use case. We run several Codex sessions side by side in a terminal multiplexer, wmux, one per pane, alongside Claude Code sessions. Agents talk to each other through the multiplexer's MCP server (mcp_servers.wmux, agent-to-agent messages). That server must know which pane the calling session lives in, so it can tell sender from recipient. The multiplexer identifies a pane through per-pane variables (WMUX_PTY_ID, WMUX_WORKSPACE_ID), like TMUX_PANE for tmux.

With the managed daemon, a typed codex cannot pass that identity to its thread's MCP servers:

  • The MCP server is spawned by the daemon. Its environment comes from the daemon process, filtered by create_env_for_mcp_server (rmcp-client/src/utils.rs), so the pane variables are missing, or belong to whichever client started the daemon.
  • The app-server protocol already supports the right thing: a thread/start / thread/resume / thread/fork request may carry config overrides, including mcp_servers.<name>.env. That config is scoped to the thread. wmux relies on this on macOS and Linux. It proxies the TUI connection (codex --remote unix://…) and adds mcp_servers.wmux.env to each thread request, which works well.
  • The TUI itself cannot send it: config_request_overrides_from_config (tui/src/app_server_session.rs) forwards only allow_login_shell, default_permissions, features, network, permissions, personality, sandbox_workspace_write, shell_environment_policy and suppress_unstable_features_warning. So codex -c 'mcp_servers.wmux.env.WMUX_PTY_ID="…"' is dropped before it reaches the daemon.

So users must either run codex --no-daemon, losing the daemon, or put a proxy between the TUI and the daemon. On Windows that proxy is not practical for a Node-based tool, because the daemon socket is AF_UNIX.

Proposal (smallest first):

  1. Forward mcp_servers.<name>.env (or all of mcp_servers) from the TUI's session flags in config_request_overrides_from_config. This is the same thread-scoped override the protocol already accepts from other clients. A multiplexer can then launch codex -c mcp_servers.wmux.env.WMUX_PTY_ID=… per pane.
  2. Optionally, as sugar on top: env_vars entries with source = "client" (next to the existing local / remote). The CLI would resolve them from its own environment when it starts or resumes a thread and send them as that thread's MCP env. Then a plain codex typed in a pane works with no wrapper.

Both keep your model: the values belong to the thread, set by the client that started or resumed it, and are never inferred from whichever client is attached later. They are only read from the user's own config or command line.

Minimal repro (0.160.0). The behaviour below is traced from the code paths named above. I have not run this exact envdump script:

  1. Configure a stdio MCP server that logs its environment, e.g. [mcp_servers.envdump] command = "node", args = ["-e", "require('fs').writeFileSync(require('os').tmpdir()+'/envdump-'+process.pid+'.json', JSON.stringify(process.env)); setInterval(()=>{},1e6)"].
  2. With the managed daemon running, start codex -c 'mcp_servers.envdump.env.PANE_ID="A"' in one terminal and codex -c 'mcp_servers.envdump.env.PANE_ID="B"' in another.
  3. Expected: two envdump processes with PANE_ID=A and PANE_ID=B. Actual: PANE_ID is absent from both, because the override is not forwarded. The same flags with --no-daemon produce A and B.

Additional information

Related, but about hooks rather than MCP servers: #48500 (stale client terminal identity in daemon hooks) and #44902 (hook-scoped client env allowlist). Also related: #37209 (MCP subprocess omits TMUX/TMUX_PANE). This request is narrower. It asks only that the TUI can send a thread-scoped MCP config override the protocol already supports.

wmux tracking: openwong2kim/wmux#1778, openwong2kim/wmux#1780.

Activity

  1. added
    enhancement
    CLI
    windows-os
    mcp
    app-server
    on Oct 4, 2026
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

    CLIapp-serverenhancementmcpwindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions