Skip to content

Bound the write of the response of a streamed request - #722

Merged
koic merged 1 commit into
modelcontextprotocol:mainfrom
koic:bound_the_write_of_the_response_of_a_streamed_request
Nov 27, 2026
Merged

koic merged 1 commit into
modelcontextprotocol:mainfrom
koic:bound_the_write_of_the_response_of_a_streamed_request

Conversation

@koic

@koic koic commented Nov 27, 2026

Copy link
Copy Markdown
Member

Motivation and Context

With stream_request_notifications: true, the notifications and keepalives of a streamed request each wait for the client for at most stream_write_timeout: seconds, but the response that ends the stream was written without any deadline, since it may be large. The stream of a 2026-07-28 request belongs to no session, so nothing else ends it either: a client that stopped reading held the thread serving the request, and the keepalive thread waiting on the stream's write mutex, until it closed the connection.

The response is now written in pieces of 64 KiB, each given stream_write_timeout: seconds. A client that takes each piece in that time receives all of it however long the whole takes, and one that does not is dropped as it is for any other frame. stream_write_timeout: nil still waits without limit.

How Has This Been Tested?

test/mcp/server/transports/streamable_http_stream_request_notifications_test.rb. Against the previous library the request of a client that does not read never ends.

Breaking Changes

None.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

## Motivation and Context

With `stream_request_notifications: true`, the notifications and keepalives of a streamed request each wait for
the client for at most `stream_write_timeout:` seconds, but the response that ends the stream was written without
any deadline, since it may be large. The stream of a 2026-07-28 request belongs to no session, so nothing else ends
it either: a client that stopped reading held the thread serving the request, and the keepalive thread waiting on
the stream's write mutex, until it closed the connection.

The response is now written in pieces of 64 KiB, each given `stream_write_timeout:` seconds. A client that takes
each piece in that time receives all of it however long the whole takes, and one that does not is dropped as it is
for any other frame. `stream_write_timeout: nil` still waits without limit.

## How Has This Been Tested?

`test/mcp/server/transports/streamable_http_stream_request_notifications_test.rb`. Against the previous library
the request of a client that does not read never ends.

## Breaking Changes

None.
@koic
koic merged commit 514db8d into modelcontextprotocol:main Nov 27, 2026
13 checks passed
@koic
koic deleted the bound_the_write_of_the_response_of_a_streamed_request branch November 27, 2026 20:26
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