Skip to content

Support per-session MCP server configuration via exec options #9550

Closed as not planned

Description

@0xeb

Problem Statement

When using the Codex SDK programmatically, there's no way to register MCP servers that are scoped to a single session. Currently, MCP servers must be registered globally via codex mcp add, which writes to ~/.codex/config.toml. This creates several issues:

  1. Global state pollution: Programmatically registered servers persist globally and are visible to all Codex sessions, including interactive CLI usage
  2. Cleanup burden: Applications must ensure cleanup via codex mcp remove, which can fail if the process crashes unexpectedly
  3. Concurrency issues: Multiple concurrent sessions require careful coordination of unique server names to avoid collisions
  4. No SDK support: The TypeScript SDK has no API for per-session MCP configuration

Proposed Solution

Add support for session-scoped MCP servers via the exec options:

// TypeScript SDK
const result = await codex.exec({
  prompt: "Use my-calc__add to compute 5+3",
  mcpServers: [
    { name: "my-calc", url: "http://127.0.0.1:8080/mcp" }
  ]
});

Or via CLI flags for the underlying process:

codex exec --mcp-server "name=my-calc,url=http://127.0.0.1:8080/mcp" "..."

Benefits

  • Session-scoped servers automatically cleaned up when session ends
  • No global config pollution
  • Safe for concurrent usage without name coordination
  • Enables cleaner programmatic MCP integration

Use Case

Applications that spin up ephemeral MCP servers (e.g., for tool augmentation) need those servers available only to specific Codex sessions, not registered globally where they affect other sessions or persist after the application exits.

Activity

  1. added
    enhancement
    CLI
    mcp
    on Jan 20, 2026
  2. added
    sdk
    and removed
    CLI
    on Jan 20, 2026
  3. etraut-openai commented on Jan 20, 2026

    @etraut-openai
    Contributor

    Thanks for the detailed writeup. Right now MCP servers are only configured via mcp_servers in config, and the TS SDK doesn’t expose any per‑session MCP API.

    One workaround on the CLI is to use per‑process config overrides, e.g. codex exec -c 'mcp_servers.my_calc.url="http://127.0.0.1:8080/mcp"'.

  4. etraut-openai commented on Feb 23, 2026

    @etraut-openai
    Contributor

    This feature request hasn't received any upvotes, so I'm closing it.

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

    enhancementmcpsdk

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions