github / github/copilot-cli

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

Aberta
#3,329 0 comentários 1 reação 0 responsáveis Ver no GitHub
area:mcp area:non-interactive
Linguagem predominante
Shell
Estrelas
11.2k
Forks
1.9k
Merge médio
14h 16min
PRs com merge (30d)
6

Descrição

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

Guia de contribuição

Abrir o guia de contribuição

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
shell
Domínio
cli
Tipo de issue
Bug
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Pouca atividade
Clareza
Razoavelmente clara
Facilidade para iniciantes
48/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.