github / github/copilot-cli

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

Đang mở
#3,329 0 bình luận 1 reaction 0 người được giao Xem trên GitHub
area:mcp area:non-interactive
Ngôn ngữ chính
Shell
Star
11.2k
Fork
1.9k
Merge trung bình
14 giờ 16 phút
Pull request đã merge (30 ngày)
6

Mô tả

### 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)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Reproduce the first-turn failure using ~/.copilot/mcp-config.json and a single-command copilot prompt that requires an MCP tool, then inspect session startup and tool-schema creation relative to MCP connection completion. Done means MCP tools are consistently present in the first-turn schema, with behavior also checked for child sessions and a timeout or other readiness outcome.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
shell
Lĩnh vực
cli
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
48/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.