Skip to content

fix(stdio): drain accepted responses before EOF shutdown - #3421

Closed
ace-trump-tech wants to merge 1 commit into
modelcontextprotocol:mainfrom
ace-trump-tech:fix/stdio-eof-drain
Closed

fix(stdio): drain accepted responses before EOF shutdown#3421
ace-trump-tech wants to merge 1 commit into
modelcontextprotocol:mainfrom
ace-trump-tech:fix/stdio-eof-drain

Conversation

@ace-trump-tech

@ace-trump-tech ace-trump-tech commented Aug 31, 2026

Copy link
Copy Markdown

Fixes #2678

Summary

Ensure that accepted stdio requests complete and their JSON-RPC responses are
written before the server shuts down after stdin reaches EOF.

Motivation and Context

When a stdio server receives JSONL input through shell redirection, stdin may
reach EOF while one or more accepted request handlers are still running. The
current shutdown path can cancel those handlers before their responses are
flushed to stdout.

As a result, the final tool-call responses may disappear silently, even though
the requests were accepted and processed.

This change adds a bounded graceful-shutdown drain for active requests. The
default behavior remains unchanged for transports that do not opt into the
drain window.

How Has This Been Tested?

  • Reproduced the issue with file-redirected stdin.
  • Tested multiple in-flight requests with an artificial delay.
  • Verified that all accepted request IDs are emitted before process exit.
  • Added regression coverage for stdin EOF during active request handling.
  • Verified that the shutdown wait remains bounded if a handler does not finish.

Environment:

  • Python 3.12
  • MCP Python SDK 1.27.x
  • stdio transport
  • Linux/macOS

Breaking Changes

No breaking changes. The graceful-shutdown drain is bounded and opt-in. Existing
behavior for other transports remains unchanged.

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 which would cause existing functionality to change)
  • Documentation update

Checklist

  • I am assigned to the linked issue (or it is labeled help wanted, or I'm a maintainer)
  • I have disclosed any AI assistance and can explain the change in my own words
  • 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

Additional context

The implementation is available in:

https://github.com/ace-trump-tech/python-sdk/tree/fix/stdio-eof-drain

Signed-off-by: ace-trump-tech <ace-trump-tech@users.noreply.github.com>
@github-actions github-actions Bot added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Aug 31, 2026
@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

This PR has been closed automatically. This repo only keeps pull requests open when they come from a maintainer, or from a contributor a maintainer has assigned to the linked issue, and you aren't currently assigned to #2678.

If a maintainer assigns you to #2678, this PR reopens on its own and there's nothing more you need to do here. Assignment is a maintainer call based on capacity; comments that only ask to be assigned don't factor in. What does help is engaging on the issue itself by confirming the repro, explaining why it matters for your use case, or describing the approach you'd take.

You're welcome to keep pushing commits here (just avoid force-pushing, since GitHub can't reopen a rewritten branch), but that on its own won't get the PR reviewed or the issue assigned, and realistically most auto-closed PRs stay closed. There's no need to open a new PR either way.

CONTRIBUTING.md has the full reasoning, but in short:

  • We're a small team with very little capacity to review community PRs right now.
  • Many recent PRs are AI-generated with little human review, and reviewing one carefully still costs a maintainer as much time as it ever did. A well-described issue is usually more useful to us than the code.

Maintainers: reopen, remove missing-issue-link, or add bypass-issue-check to override.

@github-actions github-actions Bot closed this Aug 31, 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.

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

1 participant