Skip to content

fix: avoid closing stdio server streams#2528

Open
HenryLee789 wants to merge 2 commits intomodelcontextprotocol:mainfrom
HenryLee789:codex/keep-stdio-open
Open

fix: avoid closing stdio server streams#2528
HenryLee789 wants to merge 2 commits intomodelcontextprotocol: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

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

1 participant