Skip to content

feat(core): add spawn-time MCP allowlists for subagents - #1

Draft
NgoQuocViet2001 wants to merge 1 commit into
review/subagent-mcp-allowlist-basefrom
feat/subagent-mcp-allowlist
Draft

NgoQuocViet2001 wants to merge 1 commit into
review/subagent-mcp-allowlist-basefrom
feat/subagent-mcp-allowlist

Conversation

@NgoQuocViet2001

Copy link
Copy Markdown
Owner

Review artifact for openai#38353

@openai/codex-core-agent-team — this is a tested implementation of the spawn-time MCP scoping proposed in openai/codex#38353.

I am intentionally opening this as a draft inside my fork, not as an unsolicited upstream PR: Codex's contribution policy says external code contributions are invitation-only. If the direction is acceptable, this branch is ready to retarget after a maintainer invitation.

Problem

A spawned subagent currently inherits the parent's complete MCP configuration. For stdio servers, each child can start another process for every configured MCP server. The resulting growth is roughly subagents × MCP servers, even when most children never use those tools.

On Windows this reproduced as dozens of idle Python MCP process pairs, memory pressure, and app-server/control-plane starvation: the parent task remained "running", but new user messages could no longer be processed.

Proposed contract

Both V1 and V2 spawn_agent gain an optional mcp_allow field:

Input Child grant
omitted Snapshot the parent's currently effective, enabled MCP server names
[] No MCP servers
["server_a"] Exactly that validated subset

Names are trimmed and deduplicated. Unknown or disabled names fail the spawn closed and report the currently available names.

Omission intentionally snapshots an exact grant instead of leaving an inherit-all sentinel. That prevents later config/plugin changes or a cold resume from silently broadening a child's MCP capabilities.

Implementation

  • Resolve the grant against the parent's post-merge, auth-gated, enabled MCP catalog.
  • Apply the allowlist centrally after config, plugin, and extension contributions are merged, but before the MCP runtime starts connections.
  • Filter every related surface: materialized server catalog, non-prefixed server names, and the Codex Apps connector snapshot.
  • Persist the exact grant in SessionMeta and thread-store creation/revert paths.
  • Restore it on cold resume before starting the thread.
  • Preserve legacy rollouts: a missing metadata field keeps the previous inherit-all behavior.

Validation

  • Spawn schema tests cover V1 and V2.
  • Resolver tests cover omitted inheritance, trim/deduplication, explicit deny-all, and unknown/disabled fail-closed behavior.
  • Spawn-handler coverage proves mcp_allow: [] reaches the child runtime catalog.
  • A PID-level Windows integration test proves a deny-all child does not launch a second stdio MCP process.
  • A cold-resume test proves a persisted deny-all grant cannot be broadened by current config.
  • just test -p codex-protocol: 271/271 passed.
  • just test -p codex-history: 14/14 passed.
  • just test -p codex-thread-store: 213/213 passed.
  • just test -p codex-rollout: 119/119 passed.
  • cargo check -p codex-app-server --tests: passed.
  • Existing MCP code-mode exposure test passed in isolation (39.99s); it only timed out during a saturated 3,025-test Windows run.

Related implementation discussion and reproduction evidence: issue comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant