codex - 💡(How to fix) Fix Per-agent MCP server scoping: allow subagents to opt out of inherited MCP servers [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#20135Fetched 2026-04-30 06:33:20
View on GitHub
Comments
1
Participants
2
Timeline
10
Reactions
1
Timeline (top)
labeled ×6unlabeled ×3commented ×1

Fix Action

Fix / Workaround

Workaround attempted: setting approval_mode = "approve" on dangerous tools at the parent level, but this is defense-in-depth, not proper scoping.

RAW_BUFFERClick to expand / collapse

What version of Codex CLI is running?

codex-cli 0.125.0

What subscription do you have?

Plus

Which model were you using?

gpt-5.5

What platform is your computer?

Linux 6.17.0-22-generic x86_64 x86_64

What terminal emulator and version are you using (if applicable)?

WezTerm 20260331-040028-577474d8

What issue are you seeing?

When a parent session has MCP servers configured (either globally in ~/.codex/config.toml or at project level), all spawned subagents inherit them. There is currently no documented way for a custom subagent to disable or override this inheritance.

Our environment has 6 subagents, but only 1-2 of them actually need MCP access. The remaining agents (report generation, environment maintenance, diagram building, read-only audit) work exclusively with local files. Despite this, every subagent spawn waits for all MCP servers to start — including built-in ones like codex_apps — adding ~20-30 seconds of overhead per spawn with no benefit.

What we tried:

  • Setting mcp_servers = {} in the agent TOML → inherited servers still load
  • The subagents documentation states that mcp_servers "inherit from the parent session when you omit them" but provides no syntax for explicitly clearing or restricting inheritance

Requested feature:

  1. Allow mcp_servers = {} (or similar) in agent TOML to explicitly disable all inherited MCP servers for that agent
  2. Alternatively, support an allowlist/blocklist model: mcp_servers.inherit = false or mcp_servers.exclude = ["codex_apps", "proceset"]
  3. Document the inheritance override behavior either way

Impact:

  • Faster subagent startup (skip unnecessary MCP connections)
  • Better security posture (read-only audit agent shouldn't have write MCP tools)
  • Reduced resource consumption for agents that don't need external tool access

Environment: Codex CLI, 6 custom subagents, 1 stdio MCP server (69 tools), codex_apps built-in

What steps can reproduce the bug?

  1. Create ~/.codex/config.toml with a global MCP server (or have codex_apps built-in)
  2. Create a custom subagent in .codex/agents/sesrep.toml that does NOT need MCP access
  3. Add mcp_servers = {} to the agent TOML, expecting it to disable inherited servers
  4. Spawn the subagent: "Use sesrep. Generate a report."
  5. Observe: the subagent still shows "starting mcp servers: (1/2): codex_apps" and waits for all inherited MCP servers to initialize, despite the explicit empty override
  6. The inherited MCP tools are also visible to the subagent, even though its contract does not require them

What is the expected behavior?

When a custom subagent explicitly sets mcp_servers = {} in its TOML config, it should spawn without loading any MCP servers — neither inherited from the parent session nor built-in ones like codex_apps.

Expected startup output: no "starting mcp servers" step. Expected tool access: only Codex built-in tools (file read/write, shell), no MCP tools. Expected startup time: near-instant, without 20-30 sec MCP initialization overhead.

Additional information

Documentation reference: https://developers.openai.com/codex/subagents states that mcp_servers "inherit from the parent session when you omit them" but provides no syntax or guidance for explicitly clearing or restricting this inheritance.

This is not just a performance issue — it also affects security posture. Our read-only audit agent (sandbox_mode = "read-only") still inherits write-capable MCP tools like execute_graphql and create_script, which contradicts the principle of least privilege.

Workaround attempted: setting approval_mode = "approve" on dangerous tools at the parent level, but this is defense-in-depth, not proper scoping.

extent analysis

TL;DR

To fix the issue, consider setting mcp_servers = {} in the agent TOML and also setting sandbox_mode = "read-only" to restrict MCP tool access, although the current implementation may not fully support this.

Guidance

  • Review the subagent configuration to ensure that mcp_servers = {} is correctly set to disable inherited MCP servers.
  • Verify that the sandbox_mode is set to "read-only" for subagents that do not require MCP access to restrict tool access.
  • Check the Codex CLI documentation for any updates on MCP server inheritance and override behavior.
  • Consider reaching out to the Codex CLI support team for further guidance on implementing the requested feature.

Example

No code snippet is provided as the issue is related to configuration and documentation.

Notes

The current implementation of Codex CLI may not fully support disabling inherited MCP servers or restricting tool access. The requested feature may require updates to the Codex CLI or documentation.

Recommendation

Apply workaround: Set mcp_servers = {} and sandbox_mode = "read-only" in the subagent TOML configuration, and consider reaching out to the Codex CLI support team for further guidance. This is because the current implementation may not fully support the requested feature, and a workaround is necessary to achieve the desired behavior.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix Per-agent MCP server scoping: allow subagents to opt out of inherited MCP servers [1 comments, 2 participants]