Skip to content

Conversation

@findleyr
Copy link
Contributor

Add a timeout option for the streamable HTTP handler that automatically cleans up idle sessions.

Also, fix a bug in the streamable client, where we hang on a request even though the client can never get a response (because the HTTP request terminated without a response or Last-Event-Id).

Fixes #499

@findleyr findleyr force-pushed the streamablefixes branch 2 times, most recently from a8a2ec8 to 753347d Compare October 20, 2025 18:59
@findleyr findleyr requested review from jba and neild October 20, 2025 19:03
handler := NewStreamableHTTPHandler(
func(req *http.Request) *Server { return server },
&StreamableHTTPOptions{
SessionTimeout: 50 * time.Millisecond,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be a good use for testing/synctest, but it would require limiting the test to only running on Go 1.25+.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it doesn't work because the test uses httptest.NewServer, which does (real) I/O. Therefore, synctest.Wait never terminates.

@findleyr
Copy link
Contributor Author

Staticcheck failures are being addressed in #599.

jba
jba previously approved these changes Oct 22, 2025
Add a timeout option for the streamable HTTP handler that automatically
cleans up idle sessions.

Also, fix a bug in the streamable client, where we hang on a
request even though the client can never get a response (because the
HTTP request terminated without a response or Last-Event-Id).

Fixes modelcontextprotocol#499
Copy link
Contributor Author

@findleyr findleyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL, the only substantive change was updating the test to have multiple goroutines keeping the session alive (as suggested), but I also had to rebase to pick up the fixes to CI.

@findleyr findleyr merged commit f01e7fa into modelcontextprotocol:main Oct 23, 2025
5 checks passed
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.

Proposal: Add StreamableHTTPOptions.SessionTimeout (Ungraceful client disconnects leads to zombie sessions)

3 participants