[FEATURE] Agent-scoped MCP server configuration — allow agents to override or isolate MCP configs via frontmatter
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
Agents (both --agent CLI sessions and sub-agents spawned via the Agent tool) cannot define their own MCP server configurations independently from the global/user-level config. The current behavior is:
mcpServersin agent frontmatter is additive — it can spin up new servers, but if a server name collides with one already in~/.claude.json, the global client wins silently. The agent's customcommand/args/envare discarded.
--agentinherits all global MCP servers — there is no way to launch an agent session with only the MCP servers the agent declares. The agent gets every globally-configured server whether it needs them or not.
Known workarounds
These work for some scenarios but none solve the core problem:
- Give each agent's server a unique name so it doesn't collide with global config — it'll connect with the agent's own
command/argsas a separate client. Works but fragile, pollutes the global namespace, and requires users to pre-configure every variant. --strict-mcp-config --mcp-config <path>— skips the~/.claude.jsonmerge and uses only the config you pass. Works for--agentCLI but not for sub-agents, and requires maintaining separate JSON config files outside the agent definition.CLAUDE_CONFIG_DIRper agent — external launcher scripts that set isolated config directories before exec'ingclaude. Heavyweight, requires tooling outside Claude Code, and doesn't help sub-agents within a session.
None of these let an agent definition be self-contained.
Why this matters
Some agent workflows require the same MCP server binary with different arguments per agent. For example:
- A code review agent needs an MCP server configured with
--include-tools lint,reviewwhile a deployment agent needs the same server with--include-tools deploy,rollback - A documentation agent needs an MCP server pointed at
--paths /docswhile a testing agent needs--paths /tests - An orchestrator spawns specialized sub-agents that each need different tool subsets from the same MCP server, filtered via server-side args
Today, if the user has that MCP server configured globally (common for general-purpose servers), every agent silently gets the global config instead of its own. The agent's specialized args are discarded without warning.
Proposed Solution
Option A: isolatedMcp: true — full MCP isolation
A top-level boolean that opts the agent out of global MCP inheritance entirely. Combined with mcpServers, the agent defines its complete MCP environment.
---
name: deploy-agent
description: Deployment specialist
isolatedMcp: true
mcpServers:
my-server:
command: npx
args: ["my-server", "--include-tools", "deploy,rollback"]
monitoring:
command: npx
args: ["monitoring-mcp"]
---
isolatedMcp: truemeans: do NOT inherit global MCP servers — only use what's declared in this agent'smcpServers- Equivalent to the existing
--strict-mcp-configCLI behavior, but declarative within the agent definition - Enables fully self-contained, distributable agent definitions
- Clear mental model: the agent controls its entire MCP environment
Option B: mcpOverride — agent-level overrides for matching server names
A new top-level frontmatter field that explicitly declares "for these server names, use my config instead of global."
---
name: review-agent
description: Code review specialist
mcpOverride:
my-server:
command: npx
args: ["my-server", "--include-tools", "lint,review", "--context", "/reviews"]
---
- Servers listed in
mcpOverridereplace the global config for matching names within this agent's session mcpServersretains its current additive behavior for new servers- Useful when the agent needs most global servers but needs to customize one or two
Option C: Both
isolatedMcp for full isolation, mcpOverride for surgical per-server overrides. They serve different use cases — isolation is for "I want to control my entire MCP environment," override is for "I need this one server configured differently."
Design considerations
Precedence model: The simplest mental model for isolation is: the agent's mcpServers is the MCP config, period. No merging, no surprises. For overrides, it's local-wins for matching names (mirroring how project .env overrides global, .npmrc in project overrides user-level, etc.).
Sub-agent scope: Ideally this extends to sub-agents spawned via the Agent tool within a session. Today, sub-agents inherit the parent's MCP clients. An agent definition that declares MCP isolation or overrides should have those apply when spawned as a sub-agent, not just when launched via --agent.
Distributable agents: Full isolation makes agent definitions portable — the agent specifies everything it needs, independent of the user's global MCP setup. This is important for shared agent definitions (e.g., installed from a registry).
Alternative Solutions
- Just change the precedence — make existing
mcpServersfrontmatter override (not add to) global config for matching names. Zero schema changes, solves the name collision problem, but doesn't address isolation and changes existing behavior.
- Server aliasing — allow agents to reference a global server under a different internal name with custom args. Avoids the override question but adds indirection.
- Extend
--strict-mcp-configto frontmatter — astrictMcpConfig: trueboolean (matching the existing CLI flag name). Simple, but all-or-nothing and doesn't cover the "override one server" case.
Related Issues
- #25200 — Custom agents cannot use deferred MCP tools (ToolSearch not available). Different root cause but compounds this problem.
- #47118 — Parent MCP server registrations leak into sub-agent tool output. The flip side of the isolation problem.
- #34698 / #44183 —
--agentCLI doesn't activate agent'smcpServerson the main thread. - #37785 — MCP tools not available in spawned sub-agents.
- #24054 — Scoped MCP servers for skills and subagents (closed).
Priority
High - Blocks agent specialization patterns where different agents need different tool configurations from the same MCP server.
Feature Category
MCP server integration / Agent system
Use Case Example
- User has
my-serverconfigured globally in~/.claude.jsonwith default args - User creates
~/.claude/agents/review-agent.mdthat needsmy-serverwith--include-tools lint,review --context /reviews - User creates
~/.claude/agents/deploy-agent.mdthat needsmy-serverwith--include-tools deploy,rollback - User runs
claude --agent review-agent— expects review-specific tools - Actual: Agent gets the global
my-serverconfig. Review-specific args are silently discarded. - Expected: Agent's frontmatter overrides global config for
my-server. Agent gets review-specific tools as declared.
The same problem occurs when an orchestrator agent spawns these as sub-agents — each sub-agent should get its own MCP server config, not the parent's global config.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗