Skip to content

Race condition in MCP scaffolding tasks.json causes ECONNREFUSED when pressing F5 #486

Description

@RaskovskyDavid

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:

  1. Scaffold a new MCP server project (Python, HTTP transport) with the toolkit.
  2. Open the generated .vscode/tasks.json and note that "Open Agent Builder" depends
    on "Start MCP Server" with no dependsOrder set.
  3. Open Run and Debug, select "Debug in Agent Builder", press F5.
  4. 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:

Metadata

Metadata

Assignees

Labels

needs attentionThe issue needs contributor's attention

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions