Where does the bug appear (feature/product)?
Cursor CLI
Describe the Bug
This was a written report by AI after long debug sessions:
Cursor CLI: MCP connection fails for slow-starting servers
Summary
The Cursor CLI’s MCP implementation fails with “Connection closed” when connecting to MCP servers that have a slow initialization phase (2+ seconds). The same MCP server works correctly in Cursor GUI.
Environment
- OS: WSL2 Ubuntu on Windows 11
- Cursor CLI: Latest (installed via cursor command)
- MCP Server: Docker MCP Gateway 2.0.1
Configuration
// ~/.cursor/mcp.json
{
"mcpServers": {
"MCP_DOCKER": {
"command": "docker.exe",
"args": ["mcp", "gateway", "run", "--servers", "time"]
}
}
}
Steps to Reproduce
- Configure MCP with Docker gateway in
~/.cursor/mcp.json - Start a Cursor CLI session:
cursor - Attempt to use MCP tools or list resources
- Observe “Connection closed” error
Expected Behavior
- MCP connection should succeed after server initialization
- CLI should have similar retry/timeout logic as GUI
- Clear error message if server takes too long
Actual Behavior
Error listing MCP resources: Failed to list MCP resources: MCP error -32000: Connection closed
Evidence That Server Works
The same Docker MCP gateway:
Works in Cursor GUI (logs show 60 tools loaded)
Responds correctly when given 2-3 seconds to initialize
Fails in Cursor CLI
Manual Test Proving Server Works
# This works - request sent after initialization
(sleep 3 && echo '{"jsonrpc":"2.0","method":"initialize",...}') | docker.exe mcp gateway run
# Returns valid JSON-RPC response
Suggested Fix
- Implement retry logic for MCP initialization (3-5 retries with backoff)
- Increase timeout for initial connection (10+ seconds for slow servers)
- Add configurable timeout in mcp.json:
"initTimeout": 10000 - Better error message: “MCP server did not respond within X seconds”
Workaround
Currently none for CLI - must use Cursor GUI for MCP features.
Additional Notes
- This may affect other slow-starting MCP servers (not just Docker)
- The MCP protocol doesn’t specify timing requirements, so clients should be tolerant
- GUI and CLI should have consistent behavior
Steps to Reproduce
Steps to Reproduce
Configure MCP with Docker gateway in ~/.cursor/mcp.json
Start a Cursor CLI session: cursor
Attempt to use MCP tools or list resources
Observe “Connection closed” error
Expected Behavior
Expected Behavior
MCP connection should succeed after server initialization
CLI should have similar retry/timeout logic as GUI
Clear error message if server takes too long
Operating System
Windows 10/11
Current Cursor Version (Menu → About Cursor → Copy)
2026.01.09-231024f Cursor-Agent
For AI issues: which model did you use?
Claude 4.5 Opus
Does this stop you from using Cursor
No - Cursor works, but with this issue