fix(stdio): allow configurable memory-stream buffer size#2163
Open
giulio-leone wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
fix(stdio): allow configurable memory-stream buffer size#2163giulio-leone wants to merge 1 commit intomodelcontextprotocol:mainfrom
giulio-leone wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
Add read_stream_buffer_size and write_stream_buffer_size parameters to stdio_server() so callers can increase the internal memory-object-stream capacity. The default (0 = synchronous hand-off) is preserved for backward compatibility. With max_buffer_size=0 the stdin reader blocks whenever the message processor is busy, making the server unresponsive to pings and new requests during slow operations. A small buffer (e.g. 8) decouples reading from processing and lets the server remain responsive. Closes modelcontextprotocol#1333 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
stdio_server()hardcodesmax_buffer_size=0for both internal memory object streams, creating synchronous hand-off between the stdin reader and the message processor. When the processor is busy with a slow operation (DB query, API call, file I/O), the stdin reader blocks and the server becomes completely unresponsive to pings and new requests.Reported in #1333 — a server became unresponsive after 67 minutes of operation with requests every 10 seconds.
Solution
Add two optional parameters to
stdio_server():read_stream_buffer_size0write_stream_buffer_size0Defaults preserve current behaviour. Callers who need responsiveness under load can set a small buffer (e.g.
8) to decouple reading from processing.Testing
Existing
test_stdio_serverpasses — the default values keep behaviour identical.Closes #1333