openai / openai/codex

Lazy/on-demand startup for MCP servers

Open
#42,242 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

CLI enhancement mcp
Dominant language
Rust
Stars
125k
Forks
19.4k
PR merge metrics
PR metrics pending

Description

What variant of Codex are you using?

CLI

What feature would you like to see?
Problem

Codex initializes and starts every enabled MCP server when a local session
is opened, even if none of that server's tools are used.

With multiple MCP servers configured, this can:

  • Increase session startup time
  • Start unnecessary local processes
  • Consume CPU and memory unnecessarily
  • Produce startup errors for servers unrelated to the current task

Environment:

  • Component: Codex local client / MCP
  • Codex CLI version: 0.152.0
  • MCP transport: STDIO
Proposed solution

Add an optional lazy startup mode for MCP servers:

[mcp_servers.example]
startup_mode = "lazy"

Expected behavior:

1. Do not start the MCP process when a session opens.
2. Load cached or declarative tool metadata so the tools remain discoverable.
3. Start and initialize the server on the first tool invocation.
4. Reuse the initialized server for the remainder of the session.
5. Keep "eager" as the default mode for backward compatibility.

If automatic lazy startup is difficult because tool discovery requires MCP
initialization, an in-session command would also help:

/mcp start <server-name>
/mcp stop <server-name>

This would avoid requiring users to edit config.toml and restart Codex just
to use an MCP server temporarily.

### Additional information

_No response_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing MCP server initialization in the Codex CLI and how config.toml handles the proposed startup_mode setting. Check how STDIO tool discovery and first invocation currently work. Done means supporting lazy startup without launching unused servers, reusing the initialized server, preserving eager as the default, and covering the behavior with tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.