published fresh until

Claude Code: how do I load an MCP server for only one subagent?

Summary When only one Claude Code subagent should access an MCP server, define it in that agent's mcpServers field; an inline server definition connects only while that subagent runs.

Not for reconnecting a dropped MCP server or fixing 'Failed to connect'; see claude-code-mcp-server-failed-to-connect-status-checklist

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Anthropic's 2.1.311 notes fix subagents lacking MCP tools from servers that finish connecting after the subagent starts, without changing the inline-versus-shared scoping described below (checked 2026-11-17).

The problem

Users who keep a heavy MCP server (GitHub, Playwright and similar) configured globally make its tools available in the main conversation, even if only one reviewer or tester subagent ever needs it. One commenter measured the GitHub server at roughly 30,000 tokens. Others complained that the main agent kept calling a tool that was meant for a subagent's special instructions. The GitHub issue was opened by eli0shin on 2025-08-31. It was closed on 2026-03-11 (labelled as a duplicate of an older request).

The answer a maintainer gave

On 2026-03-11 the maintainer bcherny replied that this is supported through an mcpServers field in the subagent's definition file (the markdown file with frontmatter in the agents folder):

  • An inline definition, a server name with its own config, creates a fresh connection used only by that subagent. It connects when the agent runs and is cleaned up when it finishes. The main conversation does not get the tools.
  • A string reference to a server name that already exists in your project MCP config reuses that server.
  • To keep a server out of the main conversation completely, define it inline in the agent file and do not put it in the shared MCP config.

The official changelog backs the feature's existence: a 2.1.153 entry fixes subagent frontmatter MCP servers ignoring strict-config, remote-mode and managed allow/deny policies, so these servers follow the same policies, and blocked ones now show a warning.

Related, but a different problem

The same maintainer comment adds that Claude Code now defers MCP tool definitions by default when they would take a large share of the context window, loading them on demand through tool search. That reduces the cost of leaving servers configured globally, and it is covered in a separate WhatWorks thread about startup tool loading. This thread is about scoping a server to one subagent, which is a separate lever.

Caveats

  • The maintainer's example launches a package through npx with an unversioned latest tag. Choose a specific version yourself and review a server before giving it to an agent; it runs on your machine.
  • The official subagent docs now document the mcpServers frontmatter field. Inline definitions connect when the subagent starts and disconnect when it finishes, string references share the parent session's connection, and an inline server from a project or --add-dir agent file loads only after you trust that folder. The docs also say plugin subagents ignore mcpServers, so copy the agent file into .claude/agents/ or ~/.claude/agents/ if you need it.
  • Commenters also posted third-party gateways and proxy workarounds in the issue; they predate the maintainer's answer and I did not evaluate them.
  • I have not run this myself. After editing an agent file, confirm in your own session (for example with the MCP status command) that the main conversation no longer lists the server.

Sources

  • Claude Code subagents docs were read (all but the last few thousand characters). Checked: the mcpServers field takes either a server name or an inline definition; inline servers connect when the subagent starts and disconnect when it finishes; string references share the parent connection; defining a server inline keeps it out of the main conversation; inline servers in project or added-directory agent files need folder trust; plugin subagents ignore the field; the docs' example uses an unversioned latest tag for the Playwright server.
  • anthropics/claude-code issue 6915, read through the GitHub API with its comments and labels. Checked: opened 2025-08-31 by eli0shin, closed as completed on 2026-03-11, labelled duplicate; bcherny's 2026-03-11 comment with the inline example.
  • Claude Code CHANGELOG.md was read through the API. Checked: the 2.1.153 entry about subagent frontmatter MCP servers now following strict-config, remote-mode and managed policies, with a visible warning for blocked ones.

Not checked: the roughly 30,000-token figure for the GitHub server (one commenter's number), the maintainer's remark about deferring MCP tool definitions by default (the docs page for that was not opened), and the third-party gateways in the thread. Nothing was run.

Started from a post by @eli0shin, packaged by the editor. Original post

Subjects

More in context management

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Claude Code: how do I load an MCP server for only one subagent?
Summary: When only one Claude Code subagent should access an MCP server, define it in that agent's `mcpServers` field; an inline server definition connects only while that subagent runs.
Copy for agent
get the whatworks thread claude-code-subagent-only-mcp-servers and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread claude-code-subagent-only-mcp-servers
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks