fix: inherit MCP server IDs from parent chat when spawning subagents (#23571)

Child chats created via `spawn_agent` and `spawn_computer_use_agent`
were not inheriting the parent's `MCPServerIDs`, meaning subagents lost
access to the parent's MCP server tools.

## Changes

- Pass `parent.MCPServerIDs` in the `CreateOptions` for both
`createChildSubagentChat()` and the `spawn_computer_use_agent` tool
handler in `coderd/x/chatd/subagent.go`.

## Tests

Added 3 tests in `subagent_internal_test.go`:
- `TestCreateChildSubagentChat_InheritsMCPServerIDs` — verifies child
chat gets parent's MCP server IDs (multiple servers)
- `TestSpawnComputerUseAgent_InheritsMCPServerIDs` — verifies computer
use subagent gets parent's MCP server IDs via the tool
- `TestCreateChildSubagentChat_NoMCPServersStaysEmpty` — verifies no
regression when parent has no MCP servers
This commit is contained in:
Kyle Carberry
2026-03-25 11:22:18 +00:00
committed by GitHub
parent 3220d1d528
commit 894fcecfdc
2 changed files with 185 additions and 0 deletions
+2
View File
@@ -326,6 +326,7 @@ func (p *Server) subagentTools(ctx context.Context, currentChat func() database.
ChatMode: database.NullChatMode{ChatMode: database.ChatModeComputerUse, Valid: true},
SystemPrompt: computerUseSubagentSystemPrompt + "\n\n" + prompt,
InitialUserContent: []codersdk.ChatMessagePart{codersdk.ChatMessageText(prompt)},
MCPServerIDs: parent.MCPServerIDs,
})
if err != nil {
return fantasy.NewTextErrorResponse(err.Error()), nil
@@ -393,6 +394,7 @@ func (p *Server) createChildSubagentChat(
ModelConfigID: parent.LastModelConfigID,
Title: title,
InitialUserContent: []codersdk.ChatMessagePart{codersdk.ChatMessageText(prompt)},
MCPServerIDs: parent.MCPServerIDs,
})
if err != nil {
return database.Chat{}, xerrors.Errorf("create child chat: %w", err)