Skip to content

fix: preserve stdio streams in server transport#2734

Open
pranjalbhatia710 wants to merge 1 commit into
modelcontextprotocol:mainfrom
pranjalbhatia710:fix/stdio-preserve-standard-streams-1933
Open

fix: preserve stdio streams in server transport#2734
pranjalbhatia710 wants to merge 1 commit into
modelcontextprotocol:mainfrom
pranjalbhatia710:fix/stdio-preserve-standard-streams-1933

Conversation

@pranjalbhatia710
Copy link
Copy Markdown

Summary

  • duplicate the process stdin/stdout file descriptors before wrapping them for the stdio server transport
  • close only the duplicated wrapper streams on shutdown, preserving the original process-level streams
  • extend the stdio regression test to assert the original sys.stdin/sys.stdout wrappers remain usable after the server exits

Fixes #1933

Test plan

  • uv run --frozen pytest tests/server/test_stdio.py -q
  • uv run --frozen ruff check src/mcp/server/stdio.py tests/server/test_stdio.py
  • uv run --frozen pyright 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