Skip to content

feat(subagents): connect mcp.json servers with a profile's mcp: on (#1053) - #1187

Merged
agegr merged 1 commit into
mainfrom
feat/subagent-mcp
Oct 11, 2026
Merged

agegr merged 1 commit into
mainfrom
feat/subagent-mcp

Conversation

@agegr

@agegr agegr commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Closes #1053.

Problem

Built-in subagents never loaded pi-web's mcp built-in or an MCP host, so they could not reach the servers in mcp.json. #1097 added Code mode for subagents, but MCP was still listed as later work in ADR 0006.

Change

A profile can set mcp: on | off (missing means off; true reads as on). The Agents panel has a "Connect MCP servers" switch under Resources.

  • Loading: a child with mcp: on loads builtin:tool-search and builtin:mcp with an McpHost of its own (createSubagentMcpExtensions()). They come in through additionalExtensionPaths, the CLI's -e builtin:<name>, which works under noExtensions and keeps the builtin:mcp path the host only activates for. That path also skips -builtin: settings, so each factory reads its switch on every load, as the child's Code mode does. Normal sessions keep their own wiring; createMcpBuiltins() is now shared by both.
  • Tools: servers connect after the child's allowlist is fixed, so the allowlist admits MCP tools by name (mcp__* and the resource tools). Without Code mode, codemode servers register as deferred and tool_search joins the allowlist; with Code mode, scripts reach them and tool_search stays out of requests.
  • Policy (createSubagentMcpPolicyExtension()): blocks MCP-named tools of extensions the profile's ext: selectors left out (the concern feat(subagents): add opt-in codemode support #1097 fixed for scripts). While the child's built-in tools are read-only (Explore, Plan), it also blocks every MCP tool without readOnlyHint: true, codemode scripts included. A profile of extension tools alone is not read-only.
  • Runs: the runtime prompts the SDK session directly, so it now waits for direct servers through the wrapper's prepareMcpForRun(), as a sent prompt does. abortSubagent, the parent's Stop and Stop in the child's own chat all end that wait, and the run is aborted before it starts. steer_subagent during the wait (at most 10 s) is refused, as for any non-running child.
  • Persistence: the snapshot keeps mcp: true, so reload, resume and RPC reopen load the same; older snapshots load no MCP.
  • Chat only: a chat-only profile rejects mcp: on at spawn, and the panel disables the switch for a chat-only draft (it can still turn an existing on off).
  • Save: a profile that never used MCP gets no mcp key; a request without the field keeps the file's value.
  • Docs: docs/agents/subagents.md, tools.md, mcp-runtime.md, ADR 0006.

Not in this PR: mcp: inherit, and choosing which servers a profile connects. Each child connects its own servers, so stdio servers start once more per child; the wrapper disposes the host when it closes, and idle release applies.

Verification

  • lib/subagent-mcp.integration.test.mjs (11 tests) runs real AgentSessions and the real wrapper against the stdio fixture server: a direct MCP call; the read-only block and a readOnlyHint tool allowed; tool_search loading a codemode server without Code mode; a script calling one with Code mode; another extension's mcp__ tool blocked under ext: selectors; no MCP without the key; chat-only rejection; resume after the child closed (RPC reopen keeps MCP and the read-only scope); and each of the three Stops during the wait against a server that never answers.
  • Unit tests for parsing, saving, snapshots, tool and loader options, the extension scope, and the panel draft.
  • After rebasing on main: tsc --noEmit and the full suite (2616 tests, 0 failures, 1 skipped) pass; eslint passes on the changed files (the full eslint . was not run to completion).
  • Checked the Agents panel by hand on an isolated dev server with a scratch agent dir: the switch reflects mcp: on from the file, is disabled with its hint on a chat-only profile and enabled once a tool is ticked, and saving writes mcp: 'off' / mcp: 'on'.
  • Not tried with a real model and a real third-party MCP server.

🤖 Generated with Claude Code

…1053)

A profile with `mcp: on` (frontmatter, or the Agents panel's "Connect MCP
servers" switch) gives its children `builtin:tool-search` and `builtin:mcp`
with an MCP host of their own, so they connect the servers in mcp.json
under the same trust rules as a normal session. Missing means off.

- The built-ins load through `additionalExtensionPaths` (the CLI's
  `-e builtin:<name>`), which works under `noExtensions` and keeps the
  `builtin:mcp` path the host only activates for. That path also skips
  `-builtin:` settings, so each factory reads its switch on every load.
- An allowlist admits MCP tools by name (`mcp__*` and the resource tools),
  plus `tool_search` when the child has no Code mode, whose `codemode`
  servers then register as `deferred`.
- `createSubagentMcpPolicyExtension()` blocks MCP-named tools of
  extensions the profile's `ext:` selectors left out, and, while the
  child's built-in tools are read-only (Explore, Plan), every MCP tool
  without `readOnlyHint`, codemode scripts included.
- Runs prompt the SDK session directly, so they wait for `direct`
  servers through the wrapper's new `prepareMcpForRun()`. abortSubagent,
  the parent's Stop and Stop in the child's chat all end the wait and
  abort the run before it starts.
- The snapshot keeps `mcp: true` for reload, resume and RPC reopen. A
  chat-only profile rejects `mcp: on`; the panel disables the switch there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@agegr
agegr merged commit 68f04ef into main Oct 11, 2026
2 checks passed
@agegr
agegr deleted the feat/subagent-mcp branch October 29, 2026 13:01
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 6, 2026
…gegr#1053) (agegr#1187)

A profile with `mcp: on` (frontmatter, or the Agents panel's "Connect MCP
servers" switch) gives its children `builtin:tool-search` and `builtin:mcp`
with an MCP host of their own, so they connect the servers in mcp.json
under the same trust rules as a normal session. Missing means off.

- The built-ins load through `additionalExtensionPaths` (the CLI's
  `-e builtin:<name>`), which works under `noExtensions` and keeps the
  `builtin:mcp` path the host only activates for. That path also skips
  `-builtin:` settings, so each factory reads its switch on every load.
- An allowlist admits MCP tools by name (`mcp__*` and the resource tools),
  plus `tool_search` when the child has no Code mode, whose `codemode`
  servers then register as `deferred`.
- `createSubagentMcpPolicyExtension()` blocks MCP-named tools of
  extensions the profile's `ext:` selectors left out, and, while the
  child's built-in tools are read-only (Explore, Plan), every MCP tool
  without `readOnlyHint`, codemode scripts included.
- Runs prompt the SDK session directly, so they wait for `direct`
  servers through the wrapper's new `prepareMcpForRun()`. abortSubagent,
  the parent's Stop and Stop in the child's chat all end the wait and
  abort the run before it starts.
- The snapshot keeps `mcp: true` for reload, resume and RPC reopen. A
  chat-only profile rejects `mcp: on`; the panel disables the switch there.

Co-authored-by: Claude Opus 5.5 <[email protected]>
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 8, 2026
…gegr#1053) (agegr#1187)

A profile with `mcp: on` (frontmatter, or the Agents panel's "Connect MCP
servers" switch) gives its children `builtin:tool-search` and `builtin:mcp`
with an MCP host of their own, so they connect the servers in mcp.json
under the same trust rules as a normal session. Missing means off.

- The built-ins load through `additionalExtensionPaths` (the CLI's
  `-e builtin:<name>`), which works under `noExtensions` and keeps the
  `builtin:mcp` path the host only activates for. That path also skips
  `-builtin:` settings, so each factory reads its switch on every load.
- An allowlist admits MCP tools by name (`mcp__*` and the resource tools),
  plus `tool_search` when the child has no Code mode, whose `codemode`
  servers then register as `deferred`.
- `createSubagentMcpPolicyExtension()` blocks MCP-named tools of
  extensions the profile's `ext:` selectors left out, and, while the
  child's built-in tools are read-only (Explore, Plan), every MCP tool
  without `readOnlyHint`, codemode scripts included.
- Runs prompt the SDK session directly, so they wait for `direct`
  servers through the wrapper's new `prepareMcpForRun()`. abortSubagent,
  the parent's Stop and Stop in the child's chat all end the wait and
  abort the run before it starts.
- The snapshot keeps `mcp: true` for reload, resume and RPC reopen. A
  chat-only profile rejects `mcp: on`; the panel disables the switch there.

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

MCP does not work in subagents

1 participant