-
Notifications
You must be signed in to change notification settings - Fork 56
Delay SSE GET connection until after session ID is established #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add a signaling mechanism to ensure the SSE streaming task waits for the initial session ID to be set before attempting the GET connection. - Use a TaskGroup to race between session ID signal and a 10-second timeout, logging the outcome. - Trigger the signal when a session ID is received for the first time from any response. - Add detailed logging for all code paths to aid debugging and clarify connection timing. - Clean up signal resources on disconnect to prevent leaks. This addresses the initialization timing issue where the SSE GET could be attempted before the session was established, as discussed in MCP PR #91.
@mattt it looks like it should. Using the flow sequence here https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#sequence-diagram its not completely clear if all we need is to wait for an Mcp-Session-Id to exist (which is how you have it) or if it should wait until after the client has sent the InitializedNotification. The latter would obviously require the transport to have a bit more knowledge of the state of the client, which is not cool, so yeah i think we roll with what you have until we learn otherwise. The one thing i would like to mention that is a tad wonk is the Transport requires the app to call client.initialize() within timeout seconds after calling client.connect(). That sorta imposes an implicit but unclear timing dependency. I am not exactly sure the best solution. Could be argued that there shouldn't be two explicit steps for the client, but not sure i love calling initialize within connect. hmmmm |
@stallent Thanks for weighing in!
I'm with you. Snooping on the data flowing through the transport feels wrong, and seems to go against the notion of an agnostic transport layer (although ironically, that creates the conditions by which we must snoop to know when an initialized notification comes through). For now, I think a configurable timeout (spelled In the future, I think we can solve the coordination problem in a less janky way with a higher-level abstraction, like we're discussing in #27. |
Oh i DEF like renaming it to sseInitializationTimeout for clarity. good call. |
@mattt one last thing, just as a point of reference... I looked at the official TS client and it DOES call initialize from within the connect() method, so there is at least precedent for it.
|
Follow-up to #96
This addresses the initialization timing issue where the SSE GET could be attempted before the session was established, as discussed in MCP PR #91.
sseInitializationTimeout
, 10 seconds by default), logging the outcome.This PR also adds documentation comments for
HTTPClientTransport
.