[BUG] Named teammates (Agent name:) get the turn-start tool pool and miss MCP servers that connect later in the turn
Version: 2.1.287 (macOS, native build)
Bug
When the Agent tool is called with name (an in-process teammate), the teammate's tools come from toolUseContext.rootToolSurface.tools. That pool is captured once, when the main session starts processing the current turn (_buildToolUseContextWith → rootToolSurface:{tools: computeToolPoolFresh().tools, …}). The main loop's mid-turn MCP refresh (tengu_mcp_tools_refreshed_mid_turn) only replaces options.tools, never rootToolSurface. The teammate gets no refreshTools either, so the stale pool lasts for the teammate's whole life.
At startup the first turn begins while MCP servers are still pending. So any named teammate spawned in that turn gets no tools from servers that connect later, even minutes later:
- Its deferred-tools list lacks them.
ToolSearch select:mcp__<server>__<tool>returns "No matching deferred tools found".- Its MCP instructions block, which is built from the live
mcpClients, still describes those servers. The agent is told about servers it cannot reach.
Unnamed subagents are not affected. They build their pool from live appState.mcp.tools at spawn (assembleToolPool(…getAppState().mcp.tools…)). requiredMcpServers does not help either, because its wait and check run after the spawnTeammate branch.
Repro
- Configure a few stdio/http MCP servers.
- Run
claude "In one message spawn two Agents: one with no name, one with name 'probe' and run_in_background true. Each runs ToolSearch select:mcp__<server>__<tool> and reports found or not found." - The unnamed agent finds the tool. The named one does not. The named one still misses it when spawned minutes later in the same turn, after
/mcpshows every server connected. - Spawn the named agent from a second turn instead: it finds the tool.
Expected
Named teammates resolve tools from live MCP state at spawn, as unnamed subagents do, and ideally wait for pending servers.
Suggested fix
- Smallest: in the in-process teammate runner, derive
availableToolsfrom live state, as the subagent path does viaassembleToolPool, instead ofu.rootToolSurface.tools. - Alternative: refresh
rootToolSurfacealongsideoptions.toolsin the mid-turn refresh. This is wider, because other readers use it.