Skip to content

mcp: detach SSE client event stream from the Connect context - #1403

Open
beiryu wants to merge 1 commit into
modelcontextprotocol:mainfrom
beiryu:fix-1331-mcp-sseclienttransport-ties-the-event-st
Open

beiryu wants to merge 1 commit into
modelcontextprotocol:mainfrom
beiryu:fix-1331-mcp-sseclienttransport-ties-the-event-st

Conversation

@beiryu

@beiryu beiryu commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #1331

SSEClientTransport.Connect used the context passed to it for the long-lived event stream. If the caller bounded the handshake with a timeout or cancelled it afterwards, the stream closed and later calls failed. StreamableClientTransport does not behave this way.

This change makes the stream independent of the Connect context. The context now only bounds the handshake: if it is cancelled before the handshake completes, Connect returns the error and cleans up the request. After Connect returns, the stream is cancelled only by Close.

Testing: added TestSSEClientConnectContextCanceled in mcp/sse_test.go. It cancels the Connect context after connecting and checks that a later Ping succeeds. The test and the project's checks pass.

I use the usual pattern of a timeout context for Connect, and it broke the SSE session without any warning. The streamable transport works with the same code, so I wanted both to behave the same.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mcp: SSEClientTransport ties the event stream to the context passed to Connect

1 participant