github / github/copilot-cli

Custom agents in `.claude/agents/` don't receive MCP tools when spawned as sub-agents via `task` tool

未關閉
#2,716 0 則留言 2 個 reaction 已指派 0 人 在 GitHub 檢視
area:agents area:mcp
主要語言
Shell
星號
11.2k
分支
1.9k
平均合併
14 小時 16 分鐘
30 天內合併 PR
6

描述

### Describe the bug

Custom agents defined in `.claude/agents/` with `mcps:` declared in their YAML frontmatter do **not** receive MCP tool connections when spawned as sub-agents via the `task` tool. The agent loads and runs, but MCP tools are absent from its tool inventory.

**Workaround:** Moving agent files to `.copilot/agents/` (with symlinks in `.claude/agents/`) resolves the issue — sub-agents then receive all MCP tools correctly.

This may be related to #2630, but is a distinct issue: #2630 covers MCP propagation failing entirely for sub-agents. This bug is specifically about agent **file location** affecting MCP resolution.

### Affected version

1.0.26

### Steps to reproduce the behavior

1. Create a custom agent in `.claude/agents/my-agent.md` with `mcps:` frontmatter:
```markdown
---
name: my-agent
description: Agent that uses MCP tools
mcps:
my-mcp:
type: local
command: some-mcp-command
args: [mcp, my-server]
---
Agent instructions here.
```

2. Configure `.mcp.json` at repo root with the same MCP servers (they work in the main interactive session).

3. Spawn the agent as a sub-agent via the `task` tool:
```
task(agent_type="my-agent", prompt="List all your available tools")
```

4. **Result:** Agent loads but reports **no MCP tools** — only basic tools (view, edit, grep, powershell, etc.)

5. Move agent to `.copilot/agents/my-agent.md`, symlink `.claude/agents/my-agent.md` → `.copilot/agents/my-agent.md`.

6. Reload session and repeat step 3.

7. **Result:** Agent now reports all MCP tools correctly.

### Expected behavior

Agents in `.claude/agents/` should receive MCP tools from their `mcps:` frontmatter when spawned as sub-agents, the same as agents in `.copilot/agents/`.

### Additional context

- **OS:** Windows 11
- **Shell:** PowerShell 7
- **Copilot CLI version:** 1.0.26
- The main interactive session always has MCP tools regardless of agent location
- Session reload was required after moving files (mid-session moves hit a stale file path cache)

貢獻指南

開啟貢獻指南

研究方向

先追蹤 task tool 如何從 `.claude/agents/` 和 `.copilot/agents/` 載入自訂 agent,然後比較每個位置如何解析 `mcps:` frontmatter 和儲存庫根目錄中的 `.mcp.json`。使用 Copilot CLI 1.0.26 中提供的 `my-agent` 設定重現。當從 `.claude/agents/` 載入的 agent 回報的 MCP 工具與從 `.copilot/agents/` 載入的 agent 相同時,即表示完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
powershell
領域
cli, tooling
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
冷清
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。