Skip to content

Conversation

@richard-rance
Copy link

Problem

When connecting to some MCP servers that supports making SSE GET requests, client.Connect gets hung up waiting for the first notification from the server.

More details in issue #633

Solution

This change modifies the tests to simulate a server that keeps the stand alone SSE connection open. It then adjusts the connection setup to run the standalone SSE connection in the background.

Open question

Work was done 2 weeks ago in #604 / #583 to make some errors from starting the stand alone SSE connection be returned as part of client.Connect. I'm not clear on why that is necessary. Clients are not required to accept SSE messages from servers. Stateless clients will want to opt out of even attempting to create the standalone SSE connection.
This PR undoes some of it so may not be the correct solution.

I'll clean up the tests once I know more.

When connecting to an MCP server that supports making SSE GET requests client.Connect gets hung up waiting for the first notification from the server.

This change modifies the tests to simulate a server that keeps the stand alone SSE connection open.
It then adjusts the connection setup to run the standalone SSE connection in the background.
jba pushed a commit that referenced this pull request Jan 11, 2026
mcp: add DisableStandaloneSSE option to control standalone SSE stream

Currently, StreamableClientTransport always establishes a standalone SSE
connection after initialization to receive server-initiated messages.
While this is useful for receiving notifications like
ToolListChangedNotification, it causes problems in several real-world
scenarios:

1. **Unnecessary resource usage**: Many use cases (for me), especially
in scientific computing scenarios, only require simple request-response
communication. Clients don't need server-initiated notifications, making
the persistent SSE connection wasteful.

2. **Server compatibility issues**: Some third-party MCP servers don't
properly handle GET requests for SSE streams. When the client
automatically tries to establish the SSE connection, it fails or hangs,
blocking the entire connection process. This is particularly problematic
when using third-party servers that cannot be modified. This issue is
similar to what was discussed in issue #634.

3. **Lack of user control**: The MCP specification states that the
standalone SSE stream is optional ("The client MAY issue an HTTP GET"),
but the current SDK implementation doesn't provide a way to opt out.
This implementation is also inconsistent with other MCP SDKs like
github.com/mark3labs/mcp-go, which provides getListeningEnabled control
(defaults to false, requires explicit enablement).

Fixes #728

Co-authored-by: zhaoxin <zhaoxin@pjlab.org.cn>
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.

1 participant