github / github/copilot-cli

Copilot CLI executes prompt before MCP servers finish connecting (missing tools on first turn)

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

描述

### Describe the bug

Summary
When running single-command prompts (non-interactive / child sessions), Copilot CLI appears to execute the prompt before MCP servers have finished connecting, causing the tool schema to be empty or incomplete on the first turn.
This results in:

MCP tools not being available to the model
Immediate failures or incorrect behavior
Intermittent reproducibility (timing-dependent)

Observations / Evidence

This behavior correlates with MCP startup latency (~1–2s range observed)

CLI seems to:

Start session
Build tool schema
Send prompt
Only then finish MCP connection asynchronously

Internal observation:

Tool schema is constructed before MCP client connection completes, so the model cannot see tools on first turn [Plugin Prototyping | Teams]

Behavior is significantly more visible in:

non-interactive mode (copilot "...")
child sessions (spawned by skills / eval frameworks)

Impact

Breaks reliability of MCP-based workflows
Makes automation (evals, scripts, CI usage) flaky
Forces workarounds like:

artificial delays
warm-up prompts
re-running commands

Workarounds (temporary)

Run an initial “no-op” prompt before actual command
Add delay before issuing prompt (~2s)
Avoid spawning new sessions; reuse a warmed session
Pre-run MCP setup outside of Copilot CLI process

Additional Context

This appears related to async MCP connection lifecycle + lack of readiness barrier
CLI currently behaves as if tools exist only after MCP fully loads, with no blocking initialization step [[github.com]](https://github.com/github/copilot-cli/issues/679)
Similar instability in MCP connectivity has been reported in recent CLI versions (timing / connection issues) [[github.com]](https://github.com/github/copilot-cli/issues/3257)

Suggested Fix
Introduce a synchronization / readiness barrier before prompt execution:

Block until:

MCP servers are connected, OR
a configurable timeout is reached

Alternatively:

allow "lazy tool schema refresh" after MCP connects
or expose an --await-mcp / --wait-for-tools flag

Environment

Copilot CLI version: GitHub Copilot CLI 1.0.48
OS: Windows 11
MCP server type(s): http
Repro frequency: high frequency as of 5/14/2026

### Affected version

GitHub Copilot CLI 1.0.48

### Steps to reproduce the behavior

Repro Steps

Configure one or more MCP servers (local or remote) in ~/.copilot/mcp-config.json
Run a single-command prompt, for example:
Shellcopilot "run "Show more lines
or trigger via:

evaluation scripts
skills that spawn a child session

Observe behavior on first execution

### Expected behavior

Expected Behavior

Copilot CLI should wait until MCP servers are fully connected and tools are registered before:

building the tool schema
sending the prompt to the model

MCP tools should be consistently available on the first turn

Actual Behavior

CLI begins prompt execution before MCP initialization completes
The LLM receives a tool schema that:

contains no MCP tools or only partial set

### Additional context

Subsequent runs or retries sometimes succeed (after MCP finishes connecting)

貢獻指南

開啟貢獻指南

研究方向

使用 ~/.copilot/mcp-config.json 和一個需要 MCP 工具的單一命令 copilot prompt 重現第一回合失敗,然後檢查工作階段啟動和工具 schema 的建立相對於 MCP 連線完成的情況。完成的條件是 MCP 工具始終存在於第一回合的 schema 中,並且也檢查了子工作階段的行為以及 timeout 或其他就緒結果。

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

評估

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

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

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