opencode icon indicating copy to clipboard operation
opencode copied to clipboard

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

Open ch-anandka opened this issue 1 day ago • 3 comments

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

ch-anandka avatar Jan 14 '26 08:01 ch-anandka