Skip to content

fix: avoid closing stdio server streams#2528

Closed
HenryLee789 wants to merge 2 commits into
modelcontextprotocol:mainfrom
HenryLee789:codex/keep-stdio-open
Closed

fix: avoid closing stdio server streams#2528
HenryLee789 wants to merge 2 commits into
modelcontextprotocol:mainfrom
HenryLee789:codex/keep-stdio-open

Conversation

@HenryLee789
Copy link
Copy Markdown

Summary

  • wrap default stdin/stdout with duplicated file descriptors so stdio_server does not take ownership of the real process streams
  • close only the duplicated wrappers on exit
  • add a regression test that verifies sys.stdin/sys.stdout remain open after stdio_server exits

Fixes #1933

Testing

  • uv run pytest tests/server/test_stdio.py -q
  • uv run ruff check src/mcp/server/stdio.py tests/server/test_stdio.py

@maxisbey
Copy link
Copy Markdown
Contributor

Closing as a duplicate of #2040, which uses the closefd=False approach discussed in review there. Thanks for the contribution.

AI Disclaimer

@maxisbey maxisbey closed this May 18, 2026
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.

Using transport="stdio" closes real stdio, causing ValueError after server exits

2 participants