Skip to content

MCP streamable-HTTP transport: 'Session not found' from server permanently breaks tool calls (no auto-reconnect) #25137

@iggerask

Description

@iggerask

Description

When a remote MCP server invalidates a streamable-HTTP session (server restart, idle timeout, periodic rotation, etc.), opencode keeps sending the same stale mcp-session-id. The server returns:

Streamable HTTP error: Error POSTing to endpoint: {"error":"Session not found"}

Once this happens, every subsequent tool call against that MCP server fails with the same error for the rest of the opencode session. The only fix is opencode mcp logout && opencode mcp auth and a process restart. There's no retry, no reconnect, no onclose handler.

This is in the same family as #17099 (no retry / reconnect for listTools() failures) but on a different code path: client.callTool() in convertMcpTool (packages/opencode/src/mcp/index.ts). #15209 reported essentially the same bug back in February but was auto-closed for not following the issue template — reopening here properly.

Steps to reproduce

  1. Configure a remote streamable-HTTP MCP server.
  2. Use it normally — agent calls a few tools successfully.
  3. Restart that MCP server (or wait for any server-side session invalidation).
  4. Have the agent call any tool on that server again.
  5. Streamable HTTP error: Error POSTing to endpoint: {"error":"Session not found"}. All subsequent calls to that server fail until opencode is restarted.

OpenCode version

1.14.30

Operating System

macOS 14 (Sequoia)

Expected

When the server reports the session is gone, opencode rebuilds the transport and replays the call once. If the retry also fails, surface the error normally.

Metadata

Metadata

Assignees

Labels

No labels
No labels

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