diff --git a/src/mcp/server/stdio.py b/src/mcp/server/stdio.py index de8bbae5f1..b7ac9db98a 100644 --- a/src/mcp/server/stdio.py +++ b/src/mcp/server/stdio.py @@ -212,6 +212,8 @@ async def stdout_writer(): yield read_stream, write_stream finally: if restore_stdout is not None: + with suppress(OSError, ValueError): + sys.stdout.flush() restore_stdout() if restore_stdin is not None: restore_stdin()