Skip to content

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

Open
giulio-leone wants to merge 1 commit intomodelcontextprotocol:mainfrom
giulio-leone:fix/stdio-configurable-buffer-size
Open

fix(stdio): allow configurable memory-stream buffer size#2163
giulio-leone wants to merge 1 commit intomodelcontextprotocol:mainfrom
giulio-leone:fix/stdio-configurable-buffer-size

Conversation

@giulio-leone
Copy link

Problem

stdio_server() hardcodes max_buffer_size=0 for 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():

Parameter Default Purpose
read_stream_buffer_size 0 Capacity of the stdin → processor stream
write_stream_buffer_size 0 Capacity of the processor → stdout stream

Defaults 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_server passes — the default values keep behaviour identical.

Closes #1333

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>
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.

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

1 participant