Skip to content

Drain stdio responses after redirected stdin EOF - #2682

Closed
Asti1982 wants to merge 1 commit into
modelcontextprotocol:mainfrom
Asti1982:codex/mcp-stdio-eof-drain
Closed

Asti1982 wants to merge 1 commit into
modelcontextprotocol:mainfrom
Asti1982:codex/mcp-stdio-eof-drain

Conversation

@Asti1982

Copy link
Copy Markdown

Fixes #2678.

Summary

  • keep the stdio write side open after redirected stdin EOF so already accepted request handlers can finish and flush responses
  • bound stdio EOF draining with a 5s timeout while preserving the existing immediate-cancel behavior for other transport closes
  • add a regression test that drives an MCPServer through redirected stdin and asserts response ids 0, 1, and 2 are all written before process exit

Tests

  • python -m ruff check src/mcp/shared/session.py src/mcp/server/session.py src/mcp/server/lowlevel/server.py src/mcp/server/mcpserver/server.py tests/issues/test_2678_stdio_eof_drain.py
  • python -m ruff format --check src/mcp/shared/session.py src/mcp/server/session.py src/mcp/server/lowlevel/server.py src/mcp/server/mcpserver/server.py tests/issues/test_2678_stdio_eof_drain.py
  • python -m pyright src/mcp/shared/session.py src/mcp/server/session.py src/mcp/server/lowlevel/server.py src/mcp/server/mcpserver/server.py tests/issues/test_2678_stdio_eof_drain.py
  • python -m pytest tests/issues/test_2678_stdio_eof_drain.py tests/server/test_cancel_handling.py tests/server/test_session.py -q

@Asti1982
Asti1982 force-pushed the codex/mcp-stdio-eof-drain branch from 4dd758d to f1c0e22 Compare May 26, 2026 04:16
@Kludex

Kludex commented Jun 25, 2026

Copy link
Copy Markdown
Member

You've opened a duplicated pull request, please search opened PRs before creating new ones. Duplicated from #2680.

@Kludex Kludex closed this Jun 25, 2026
@modelcontextprotocol modelcontextprotocol locked as resolved and limited conversation to collaborators Jun 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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

2 participants