So when using MCP Servers from a Docker command they are spawned per sub agent that is used, naturally. However, those instances are not released nor shutdown until Codex itself is exited (/exit) and so can eat up system resources via Docker. Each sub agent will receive it’s own STDIO (as configured) MCP server SET (let’s say I have 3) every sub agent spawn.
When running long sessions in Codex CLI, this can potentially, and has, led to 10’s if not a 100 instances of MCP servers because they aren’t being released.
Forcing an exit out of Codex isn’t desirable to clean these resources up. I presume this is a bug in the CLI sub agent handling.
An example configuration in this scenario is as follows:
[mcp_servers.github]
command = "docker"
args = ["run","-i","--rm",
"--env-file",
"~/.config/mcp/github.env",
"mcp/github"
]