Skip to content

Empty [mcp_servers] in agent role files does not clear inherited MCP servers #16686

Open

Description

@Auties00

What version of Codex CLI is running?

codex-cli 0.118.0

What subscription do you have?

Codex Pro

Which model were you using?

gpt-5.4

What platform is your computer?

Microsoft Windows NT 10.0.22631.0 x64

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

Winddows Terminal (Command Line)

What issue are you seeing?

When declaring an agent in .codex/agents, specifying an empty [mcp_servers] table to clear inherited MCP servers has no effect: the servers from the parent context are still inherited.

# .codex/agents/noop_no_mcp.toml

name = "noop_no_mcp"
description = "Agent with no MCP servers"
developer_instructions = "You are a minimal agent."

[mcp_servers]
# Intended to clear inherited MCP servers, but they are still inherited

What steps can reproduce the bug?

  1. Configure one or more MCP servers in your user or project config.toml:
[mcp_servers.my-tool]
command = "python"
args = ["my-script.py"]
  1. Create an agent role file at .codex/agents/noop.toml with an empty [mcp_servers] section (as shown above).
  2. Spawn the agent: the inherited MCP servers are still present despite the empty override.

What is the expected behavior?

An empty [mcp_servers] table in a higher-precedence config layer should clear all inherited MCP servers, giving three clear semantics:

  • [mcp_servers] with no entries -> clears all inherited servers
  • [mcp_servers] with some entries -> overrides parent servers
  • Omitting [mcp_servers] entirely -> inherits from parent (existing behavior)

Additional information

I've already fixed the issue locally, but I noticed PRs cannot be opened without approval. Let me know if I can open one

Activity

  1. added
    bug
    on Apr 3, 2026
  2. added
    CLI
    mcp
    on Apr 3, 2026
  3. github-actions commented on Apr 3, 2026

    @github-actions
    Contributor

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    Powered by Codex Action

  4. added
    agent
    and removed
    CLI
    on Apr 3, 2026
  5. added
    config
    and removed
    agent
    on Apr 11, 2026
  6. ahalekelly commented on Aug 31, 2026

    @ahalekelly

    Confirmed on Codex CLI 0.149.1 on Linux x86_64. This is broader than empty-table clearing: a non-empty agent-local [mcp_servers.playwright] is accepted but silently dropped.

    Reproduction evidence:

    • The custom role loads its name, model, reasoning effort, and developer instructions.
    • The spawned child keeps parent-owned MCP tools but has no mcp__playwright__* tools from the role file.
    • The configured launcher completes a direct MCP initialize + tools/list handshake and returns the full Playwright tool set, so the MCP server is healthy.
    • codex ... mcp list --json resolves the same launcher as an enabled parent-level MCP configuration.

    The current behavior comes from #39299, merged on August 18. AgentRoleOverrides has no mcp_servers field, and apply_role_to_config_inner rebuilds the role layer only from that bounded struct. The test explicitly asserts that the child keeps parent.mcp_servers and that mcp_servers is absent from the projected role layer: role_tests.rs.

    This now conflicts with the official custom-agent documentation, which says custom agent files may include mcp_servers and shows a browser-debugger agent with its own MCP server. The runtime should either support role-local MCP servers within the intended authority model, or reject the field and update the docs. Silently accepting it makes valid-looking custom browser agents fail without an MCP startup error.

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

    bugconfigmcp

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions