fix(mcp): connection hangs with non-standard SSE/HTTP servers which causes opencode to hang #5684

Open
opened 2026-02-16 17:55:35 -05:00 by yindo · 0 comments
Owner

Originally created by @ch-anandka on GitHub (Jan 14, 2026).

Originally assigned to: @thdxr on GitHub.

Description

When connecting to non-standard MCP servers over SSE or StreamableHTTP, OpenCode can hang indefinitely if the server:

  • Returns HTTP 200 but sends malformed SSE stream
  • Accepts connection but never completes MCP initialize handshake
  • Stalls during message exchange

The existing withTimeout wrapper only times out the promise but doesn't cancel the underlying HTTP/SSE connection, leaving resources
hanging.

Expected Behavior

Connection attempts should timeout gracefully and clean up resources, even if the server doesn't respond properly.

Current Behavior

OpenCode hangs waiting for server response, blocking startup or reconnection attempts.

Proposed Solution

Add AbortController support to remote MCP transports:

  • Pass AbortSignal to transport requestInit (native fetch API)
  • Call abort() on timeout to forcefully close connections
  • Ensure cleanup in all error paths

Environment

  • OpenCode version: latest (dev branch)
  • MCP server: Custom/non-standard SSE server
Originally created by @ch-anandka on GitHub (Jan 14, 2026). Originally assigned to: @thdxr on GitHub. ## Description When connecting to non-standard MCP servers over SSE or StreamableHTTP, OpenCode can hang indefinitely if the server: - Returns HTTP 200 but sends malformed SSE stream - Accepts connection but never completes MCP initialize handshake - Stalls during message exchange The existing `withTimeout` wrapper only times out the promise but doesn't cancel the underlying HTTP/SSE connection, leaving resources hanging. ## Expected Behavior Connection attempts should timeout gracefully and clean up resources, even if the server doesn't respond properly. ## Current Behavior OpenCode hangs waiting for server response, blocking startup or reconnection attempts. ## Proposed Solution Add `AbortController` support to remote MCP transports: - Pass `AbortSignal` to transport `requestInit` (native fetch API) - Call `abort()` on timeout to forcefully close connections - Ensure cleanup in all error paths ## Environment - OpenCode version: latest (dev branch) - MCP server: Custom/non-standard SSE server
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#5684