Skip to content

Allow subprocess constants (e.g. DEVNULL) for stdio errlog parameter#2420

Open
SamSi0322 wants to merge 1 commit intomodelcontextprotocol:mainfrom
SamSi0322:fix/stdio-errlog-type
Open

Allow subprocess constants (e.g. DEVNULL) for stdio errlog parameter#2420
SamSi0322 wants to merge 1 commit intomodelcontextprotocol:mainfrom
SamSi0322:fix/stdio-errlog-type

Conversation

@SamSi0322
Copy link
Copy Markdown

Summary

Widens the errlog parameter type on stdio_client() and the platform-specific process helpers to accept int in addition to TextIO. This allows callers to pass subprocess.DEVNULL, subprocess.PIPE, or other integer file descriptor constants that subprocess.Popen and anyio.open_process already support.

Previously, suppressing stderr from a child process required a type: ignore comment or wrapping subprocess.DEVNULL — even though the underlying APIs already accept it.

Changes

  • stdio_client(): errlog: TextIOerrlog: TextIO | int
  • _create_platform_compatible_process(): same
  • create_windows_process(): errlog: TextIO | Noneerrlog: TextIO | int | None
  • _create_windows_fallback_process(): same
  • Added test_stdio_client_devnull_errlog regression test

Test plan

  • New test spawns a process with errlog=subprocess.DEVNULL, verifies it starts and communicates correctly via stdin/stdout
  • Existing tests continue to pass (default sys.stderr behavior unchanged)

Closes #1806

Widen the `errlog` type on `stdio_client()` and the platform process
helpers from `TextIO` to `TextIO | int` so callers can pass
`subprocess.DEVNULL`, `subprocess.PIPE`, or other integer constants
accepted by `subprocess.Popen` and `anyio.open_process`.

Previously, passing `subprocess.DEVNULL` required a type: ignore or a
custom wrapper. The underlying process APIs already support int values
for stderr — this change surfaces that capability in the public
signature.

Github-Issue: modelcontextprotocol#1806
Reported-by: Seyed Sajad Kahani
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.

More control over stderr in stdio client

1 participant