Skip to content

fix(ENG-15479): stop mcp start quietly when the client closes stdout - #583

Open
cloudsmith-iduffy wants to merge 3 commits into
masterfrom
iduffy/fix-mcp-broken-pipe
Open

cloudsmith-iduffy wants to merge 3 commits into
masterfrom
iduffy/fix-mcp-broken-pipe

Conversation

@cloudsmith-iduffy

Copy link
Copy Markdown
Collaborator

Description

Sentry CLOUDSMITH-CLI-20 is a BrokenPipeError from cloudsmith mcp start on 1.30.0 (Homebrew). The MCP client closed its end of stdout while the server was writing a reply.

The mcp library writes stdio replies in an anyio task group. The task group wraps the BrokenPipeError in an ExceptionGroup. The error left DynamicMCPServer.run(), and AliasGroup.main reported it to Sentry and exited with status 1.

run() now catches the closed pipe with except* BrokenPipeError and returns. A client that goes away is a normal end of the session. Any other error in the group is still raised.

Linear: ENG-15479. Fixes CLOUDSMITH-CLI-20

Type of Change

  • Bug fix

Additional Notes

The patch in ENG-15479 does not fix this. It catches a plain BrokenPipeError, but mcp 2.3.0 raises ExceptionGroup(BrokenPipeError), and its test mocked the plain error. To see the real error, run the stdio server with stdout on a closed pipe:

echo '<initialize request>' | python -c '<MCPServer("t").run(transport="stdio")>' | true
# ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception) -> BrokenPipeError

The new test does this in a subprocess with the real library. It fails on master with exit status 1 and the ExceptionGroup traceback.

After the fix, Python still prints Exception ignored while finalizing file <_io.BufferedWriter name=8> to stderr. That writer is a private copy of fd 1 that mcp opens, and the CLI cannot reach it. The message does not change the exit status. Sentry does not see it, because the SDK runs with default_integrations=False.

🤖 Generated with Claude Code

The mcp stdio transport writes in an anyio task group, which raises
the BrokenPipeError inside an ExceptionGroup. The error reached the
top-level handler, which reported it and exited with status 1.

Fixes CLOUDSMITH-CLI-20

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 2, 2026 01:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the change that treats a client closing stdout as a normal MCP session end.

No open issues 🎉

What changed in this PR

Updates cloudsmith mcp start to treat a client closing stdout as a normal session end rather than an error.

Changes:

  • Handles BrokenPipeError inside exception groups while allowing unrelated errors to propagate.
  • Adds a subprocess regression test using the real MCP transport and a closed stdout pipe.
  • Documents the corrected exit behavior in the changelog.
File Description
cloudsmith_cli/​core/​mcp/​server.py Suppresses grouped broken-pipe errors during stdio operation.
cloudsmith_cli/​cli/​tests/​commands/​test_mcp.py Verifies successful exit when the client closes stdout.
CHANGELOG.md Records the MCP disconnect fix.

Review effort: Balanced

* origin/master:
  fix(ENG-15484): accept --color on click versions before 8.2 (#582)
  fix(no-ticket): stop retrying unknown hosts and show backoff retries (#542)
  fix(no-ticket): stop credential helpers from overwriting config files that do not parse (#540)
  fix(no-ticket): remove the pnpm launcher when .npmrc does not exist (#539)
  fix(no-ticket): keep the user's Cargo registry credential provider (#532)

# Conflicts:
#	CHANGELOG.md
@cloudsmith-iduffy
cloudsmith-iduffy marked this pull request as ready for review November 3, 2026 10:22
@cloudsmith-iduffy
cloudsmith-iduffy requested a review from a team as a code owner November 3, 2026 10:22
@cloudsmith-iduffy
cloudsmith-iduffy requested a balanced review from Copilot November 3, 2026 10:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the change treating closed MCP client connections as normal shutdowns.

No open issues 🎉

Review effort: Balanced

…en-pipe

# Conflicts:
#	CHANGELOG.md

Co-authored-by: cloudsmith-iduffy <178375997+cloudsmith-iduffy@users.noreply.github.com>
auto-merge was automatically disabled November 3, 2026 16:04

Head branch was pushed to by a user without write access

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants