microsoft / microsoft/foundry-dev-tools
Race condition in MCP scaffolding tasks.json causes ECONNREFUSED when pressing F5
@swatDong is already working on this.
Since Jun 30, 2026.
- Dominant language
- JavaScript
- Stars
- 2.1k
- Forks
- 260
- Avg merge
- 42m
- Merged PRs (30d)
- 29
Description
When scaffolding a Python/FastMCP (HTTP transport) MCP server project with the
toolkit and pressing F5 ("Debug in Agent Builder"), the client tries to connect to
http://localhost:/mcp before the Python server has finished starting, resulting in:
Error when calling MCP Server <name>: SSE error: TypeError: fetch failed:
connect ECONNREFUSED 127.0.0.1:3001
Root cause:
In the generated .vscode/tasks.json, the "Open Agent Builder" and "Start MCP Inspector"
tasks use "dependsOn": ["Start MCP Server"] WITHOUT "dependsOrder": "sequence".
By default VS Code runs dependent tasks in parallel, so the client task fires at the
same time as the server task instead of waiting for it to finish starting — it loses
the race almost every time.
Steps to reproduce:
- Scaffold a new MCP server project (Python, HTTP transport) with the toolkit.
- Open the generated .vscode/tasks.json and note that "Open Agent Builder" depends
on "Start MCP Server" with no dependsOrder set. - Open Run and Debug, select "Debug in Agent Builder", press F5.
- Observe ECONNREFUSED in the toolkit's output log, even though the Python server
actually starts successfully a couple seconds later.
Expected behavior:
The client should only attempt to connect once the MCP server is actually listening.
Suggested fix:
Add "dependsOrder": "sequence" to both tasks in the generated template. Note that
even with this alone, the background problemMatcher (matching "Application startup
complete") doesn't always get detected in time due to output buffering, so a more
robust fix is to insert an intermediate task with a short fixed delay (e.g.
timeout /t 5 /nobreak on Windows) between the server task and the client task.
Environment:
- OS: Windows 11
- VS Code version:
- Extension version:
Si usás la Opción A (Help: Report Issue), te deja editar el cuerpo del issue antes de enviarlo — pegá este texto en la
descripción y dejá que VS Code complete el resto.
Sources:
- GitHub - microsoft/foundry-toolkit (https://github.com/microsoft/vscode-ai-toolkit)
- Issues · microsoft/vscode-ai-toolkit (https://github.com/microsoft/vscode-ai-toolkit/issues)
- Foundry Toolkit for VS Code - Visual Studio Marketplace
(https://marketplace.visualstudio.com/items?itemName=ms-windows-ai-studio.windows-ai-studio)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.