Skip to content

fix: widen errlog type to accept subprocess.DEVNULL#2318

Closed
Bortlesboat wants to merge 1 commit intomodelcontextprotocol:mainfrom
Bortlesboat:widen-errlog-type
Closed

fix: widen errlog type to accept subprocess.DEVNULL#2318
Bortlesboat wants to merge 1 commit intomodelcontextprotocol:mainfrom
Bortlesboat:widen-errlog-type

Conversation

@Bortlesboat
Copy link

Closes #1806

Summary

Widens the errlog parameter type in stdio_client and the internal process creation helpers from TextIO to TextIO | int. This allows passing subprocess.DEVNULL (which is int value -3) to suppress stderr output from MCP server subprocesses.

Motivation

Users who want to suppress stderr output from their MCP server subprocesses currently can't pass subprocess.DEVNULL because the type hint restricts to TextIO. Both subprocess.Popen and anyio.open_process already accept int values for their stderr parameter, so widening the type is safe and aligns with the underlying APIs.

Changes

  • stdio_client(): errlog: TextIOerrlog: TextIO | int
  • _create_platform_compatible_process(): errlog: TextIOerrlog: TextIO | int
  • create_windows_process(): errlog: TextIO | Noneerrlog: TextIO | int | None
  • _create_windows_fallback_process(): errlog: TextIO | Noneerrlog: TextIO | int | None

Test plan

  • Pyright passes with 0 errors on src/mcp/client/stdio.py
  • Ruff passes with no issues
  • subprocess.DEVNULL is now accepted without type errors

The errlog parameter in stdio_client and related functions was typed
as TextIO, which prevented passing subprocess.DEVNULL (an int) to
suppress stderr output from MCP server subprocesses. Both
subprocess.Popen and anyio.open_process already accept int values
for stderr, so widening the type to TextIO | int is safe.

Github-Issue: #1806
Reported-by: sesajad
@maxisbey maxisbey closed this Mar 20, 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.

More control over stderr in stdio client

2 participants