Skip to content

Per-agent MCP server scoping: allow subagents to opt out of inherited MCP servers #20135

Open

Description

@GlebGlebovAKAJJ

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.

Activity

  1. added
    bug
    on Apr 29, 2026
  2. added
    enhancement
    CLI
    mcp
    subagent
    config
    on Apr 29, 2026
  3. removed
    bug
    CLI
    config
    on Apr 29, 2026
  4. rirze commented on Apr 30, 2026

    @rirze

    This would be a great feature, speeding up subagent speed by a magnitude.

  5. garyfpga commented on May 2, 2026

    @garyfpga

    yes please add this feature

  6. soundslikeinfo commented on May 10, 2026

    @soundslikeinfo

    I need this.

  7. insilications commented on Jun 15, 2026

    @insilications

    Need this as well...

  8. Necmttn commented on Jun 21, 2026

    @Necmttn

    The clean contract is a real three-state distinction:

    • omitted mcp_servers means inherit parent;
    • mcp_servers.inherit = false means inherit none;
    • an explicit allowlist means inherit only those named servers.

    I would also record a per-child capability manifest at spawn: inherited servers, enabled servers, suppressed servers, and startup latency. That gives users an audit trail for why a subagent had access to a tool and shows the time saved by not starting servers that the child cannot use.


    Generated with ax.

  9. AndrewDongminYoo commented on Sep 7, 2026

    @AndrewDongminYoo

    Reproduced on Codex CLI 0.153.4, macOS arm64, with an explicitly enabled multi-agent v2 session on 2026-09-07.
    This includes a successful call to the supposedly disabled tool, not just its appearance in the tool catalog.

    Reproduction and observed result

    1. Keep node_repl enabled in the parent configuration.
    2. Add this override to an existing custom explorer role:
    [mcp_servers.node_repl]
    enabled = false
    command = "/Applications/ChatGPT.app/Contents/Resources/cua_node/bin/node_repl"
    1. Start a fresh CLI process with codex exec --enable multi_agent_v2.
    2. First call node_repl.js in the parent with nodeRepl.write("PARENT_MCP_SCOPE_PROBE") to establish that the parent transport works.
    3. Spawn agent_type = "explorer" with fork_turns = "none" and have the child make one ordinary node_repl.js call with nodeRepl.write("CHILD_MCP_SCOPE_PROBE").

    Both calls returned their markers with isError: false.
    The native child rollout identifies the role as explorer and the multi-agent version as v2, and records the completed MCP call.
    Neither call interacted with browser or device UI.
    The role override was removed after verification because it did not enforce the intended restriction.

    Source-level explanation

    At the official rust-v0.153.4 commit, 3d2ee51ca2d5db578f328aa75e20aa22c0197c9a:

    The authority safeguard is valuable, but this path also excludes restrictions that only reduce the parent's grant.
    Loading the same TOML as top-level CLI overrides does not test this role-application path.

    Focused code proposal

    I support the three-state semantics in the earlier comment.
    A dedicated optional field such as mcp_allow could express them without treating policy keys as server definitions:

    • Omitted: snapshot the parent's currently granted server IDs.
    • Empty list: grant no MCP servers.
    • Non-empty list: grant only those exact IDs; reject IDs outside the parent's grant.

    The field name is illustrative and is not supported configuration today.
    This also aligns with the allowlist discussion in #38353 and its existing fork draft.

    For example, the set-resolution step can stay small:

    use std::collections::BTreeSet;
    
    fn resolve_mcp_grant(
        parent: &BTreeSet<String>,
        requested: Option<&BTreeSet<String>>,
    ) -> Result<BTreeSet<String>, BTreeSet<String>> {
        let Some(requested) = requested else {
            return Ok(parent.clone());
        };
        let unknown: BTreeSet<_> = requested.difference(parent).cloned().collect();
        if unknown.is_empty() {
            Ok(requested.clone())
        } else {
            Err(unknown)
        }
    }

    This is a standalone resolver sketch, not an integrated Codex patch.
    Its five standalone Rust tests passed for omitted, empty, subset, unknown-ID, and role-cannot-expand-spawn-grant cases.
    A negative control that treated an empty list as inheritance made the empty-policy test fail.

    Integration would need to:

    • Carry a subtractive policy through the role and spawn configuration; do not reapply the complete role config or permit new transports or credentials.
    • Resolve the parent's effective config, plugin, and client-extension contributions, then filter before child catalog exposure and connection creation.
    • Apply the same grant to tools, resources, prompts, and deferred discovery, and persist the resolved IDs across follow-up and cold resume.
    • Verify zero disallowed child PID creation with warm and cold catalogs, denial of direct tool calls, preservation of native shell tools, and unchanged parent MCP access.

    A per-child manifest could record the requested policy, inherited/enabled/suppressed server IDs, cache status, and observed startup latency, without credentials.
    Startup time saved should be reported only when a comparison baseline was measured.

    This proposal leaves connection pooling and automatic process teardown as separate work.
    It is submitted here as reproduction evidence and a code-design suggestion under the current contribution policy.

  10. aldi949 commented on Sep 23, 2026

    @aldi949

    @GlebGlebovAKAJJ hey — I've found several independent reports around the same underlying problem: controlling what MCP capabilities actually reach each subagent.

    Do you still have to work around this today?

    And one thing I'm really curious about: would you actually use external tooling to inspect/control agent MCP scope, or is this only useful to you if Codex implements it natively?

  11. amitp-cerebras commented on Oct 15, 2026

    @amitp-cerebras

    Joining the crowd - this is a needed feature.

  12. QuentinBisson commented on Oct 27, 2026

    @QuentinBisson

    A proposal that stays inside the rule #39299 set: a role may only reduce what it inherits.

    Today apply_role_to_config_inner (core/src/agent/role.rs) already keeps two kinds of reduction from a role file: disabling features (shell, apps, plugins, memory, request permissions) and disabling skills (skills.config.retain(|skill| !skill.enabled)). Everything under mcp_servers is dropped. MCP could follow the same filter:

    • [mcp_servers.<name>] enabled = false turns off an inherited server for that role.
    • enabled_tools / disabled_tools on an inherited server narrow it further; they only intersect with the parent's setting, never widen it.
    • A server the parent doesn't have is still ignored, so a role still can't add authority or endpoints.

    This also covers #40130's "readonly agent" case for MCP, without bringing back role-defined servers.

    Our use case: we compile agent definitions into Codex roles. A parent holds the union of its subagents' MCP servers, and each role should see only its own. Without a reduction, every role sees every server.

    Happy to send a PR along these lines if the approach is acceptable.

  13. ntsanderc commented on Nov 11, 2026

    @ntsanderc

    Another data point, from Codex Desktop on macOS arm64 (app-server codex-cli 0.167.0-alpha.3.2, multi_agent = true, v2 subagents). It extends the source-level explanation above to the plugin-scoped keys.

    Setup

    • One local plugin supplies 13 stdio MCP servers (Node.js). Each full set costs about 650 MB.
    • Custom roles in ~/.codex/agents/*.toml that need no MCP access carry:
    [plugins."<plugin-id>"]
    enabled = false
    • One role keeps 3 of the plugin's servers and disables the rest per server:
    [plugins."<plugin-id>".mcp_servers.<name>]
    enabled = false

    Observed

    • Two subagents with the plugin-level disable (one reviewer role, one fixer role) each had a full live 13-server set under the app-server. The processes' start times matched the subagents' start times, and ps confirmed the sets were running.
    • The app-server trace log (logs_2.sqlite) shows the child's session_init.mcp_manager_init -> mcp.runtime.refresh:new{server_name=...} completing MCP handshakes for those servers under the parent's spawn_agent span.
    • The role with per-server disables still attempted handshakes for 3 of the servers it disables.
    • So neither [plugins."<id>"] enabled = false nor [plugins."<id>".mcp_servers.<name>] enabled = false is applied to a spawned child's MCP runtime. This matches AgentRoleOverrides having no MCP or per-plugin server field.
    • [mcp_servers.<name>] enabled = false with no transport makes the whole role fail to load: failed to deserialize agent role file ...: invalid transport, then unknown agent_type. Roles therefore cannot express a pure "disable this inherited server" entry.

    Why it is hard to reproduce

    In a fresh private codex app-server (same binary and same flags as Desktop, fork_turns all or none, resumed parent, Full Access or read-only), the child reused the parent's healthy servers. It restarted only the servers that had failed. The full per-child set appeared only on some spawns in a long-lived Desktop app-server. Two spawns under the same parent in the same second got different outcomes. A short repro can therefore look clean even though the role keys are ignored.

    Impact

    One Desktop app-server running for about 28 hours held 311 child processes (about 11.2 GB) across 17 MCP sets. All of the subagents that caused it used roles intended to need no MCP access, or only 3 servers. Combined with completed subagents keeping their runtimes (#38247), memory use grows with each subagent spawned.

    +1 for a subtractive, role-applied MCP grant. The mcp_allow semantics proposed above would cover this case. Plugin-scoped server IDs should be in scope for that grant.

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

    enhancementmcpsubagent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions