Skip to content

fix(stdio): drain responses after stdin EOF#2680

Open
Epochex wants to merge 4 commits into
modelcontextprotocol:mainfrom
Epochex:fix/2678-stdio-drain-writes
Open

fix(stdio): drain responses after stdin EOF#2680
Epochex wants to merge 4 commits into
modelcontextprotocol:mainfrom
Epochex:fix/2678-stdio-drain-writes

Conversation

@Epochex
Copy link
Copy Markdown

@Epochex Epochex commented May 25, 2026

Fixes #2678.

When stdin hits EOF (e.g. python server.py < payload.jsonl > response.jsonl), the client is done sending requests but is still reading stdout for results. On main, BaseSession._receive_loop() closes the write stream as soon as the read stream ends, and Server.run() cancels the handler task group on transport close. That combination can cancel in-flight tool handlers before they respond, dropping the last ools/call responses.

This change lets ServerSession keep the write stream open when the read side closes, so Server.run() can drain already-started handlers and flush their responses before shutdown.

Tests:

  • uv run --frozen pytest tests/server/test_cancel_handling.py tests/server/test_stdio.py

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.

FastMCP/stdio: in-flight tool responses dropped on stdin EOF when input is bash-redirected from a file

1 participant