Skip to content

fix(stdio): allow configurable memory stream buffer size - #2215

Closed
yaowubarbara wants to merge 3 commits into
modelcontextprotocol:mainfrom
yaowubarbara:fix/stdio-configurable-buffer-size
Closed

yaowubarbara wants to merge 3 commits into
modelcontextprotocol:mainfrom
yaowubarbara:fix/stdio-configurable-buffer-size

Conversation

@yaowubarbara

Copy link
Copy Markdown

Summary

Add and parameters to to decouple the stdin reader from the message processor.

Problem

With the current hardcoded in , the stdin reader blocks on until the message processor calls . When processing is slow (database queries, API calls), the reader cannot accept new messages including pings, causing the server to become unresponsive. See #1333 for details.

Solution

  • Add two optional parameters with default value (preserving current behavior)
  • Pass them through to
  • Users can set to allow the reader to queue messages ahead of the processor

Test plan

  • Added : verifies basic functionality with non-zero buffer
  • Added : verifies buffered mode allows concurrent message reading during slow processing
  • Existing continues to pass (backward compatible)

Closes #1333

Add read_stream_buffer_size and write_stream_buffer_size parameters to stdio_server() to allow decoupling the stdin reader from the message processor. With the default buffer_size=0, the reader blocks on send() until the processor consumes the message, causing the server to become unresponsive during slow operations. A non-zero buffer allows the reader to queue messages ahead, preventing ping timeouts and request starvation.

Closes modelcontextprotocol#1333
The two new buffer tests did not close write_stream, causing
stdout_writer to block indefinitely on write_stream_reader iteration.
This prevented the task group from exiting, hanging the test until
CI timeout.
@maxisbey

maxisbey commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR, and sorry it sat here without a proper review.

We're closing most of the open PR backlog. v2 is out and changed a lot of the SDK, so many older PRs no longer apply as written, and we're a small team that realistically doesn't have the capacity to work through the rest.

If this still matters to you on v2, the most useful thing you can do is open an issue (or comment on the existing one) with your use case and a repro. Hearing why it matters to you is what we use to decide what to prioritise.

AI Disclaimer

@maxisbey maxisbey closed this Oct 5, 2026
@maxisbey maxisbey added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stdio_server uses unbuffered memory streams which can cause server to block and become unresponsive

2 participants