Skip to content

fix(server): close stdio transport on stdin close#2473

Open
harshmathurx wants to merge 3 commits into
modelcontextprotocol:mainfrom
harshmathurx:fix/stdio-server-stdin-close
Open

fix(server): close stdio transport on stdin close#2473
harshmathurx wants to merge 3 commits into
modelcontextprotocol:mainfrom
harshmathurx:fix/stdio-server-stdin-close

Conversation

@harshmathurx

Copy link
Copy Markdown

Summary

  • close StdioServerTransport when stdin emits close or end
  • remove stdin lifecycle listeners during transport close
  • add regression coverage for both stdin close paths

Fixes #2002.

Test Plan

  • npx -y pnpm@10.26.1 --filter @modelcontextprotocol/server test -- packages/server/test/server/stdio.test.ts
  • npx -y pnpm@10.26.1 --filter @modelcontextprotocol/server lint

@harshmathurx harshmathurx requested a review from a team as a code owner July 9, 2026 15:55
@changeset-bot

changeset-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 98f7d00

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@modelcontextprotocol/server Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 9, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@2473

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/@modelcontextprotocol/codemod@2473

@modelcontextprotocol/core

npm i https://pkg.pr.new/@modelcontextprotocol/core@2473

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@2473

@modelcontextprotocol/server-legacy

npm i https://pkg.pr.new/@modelcontextprotocol/server-legacy@2473

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@2473

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@2473

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@2473

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@2473

commit: 98f7d00

@harshmathurx

Copy link
Copy Markdown
Author

Pushed a small test-fixture follow-up after the Node 22 CI failure.

The failing job crashed because serverThatHangs.ts can receive SIGTERM after the stdio transport has already closed, then its late sendLoggingMessage() rejection escapes the signal handler. The fixture now ignores that expected late logging failure so the test keeps exercising process cleanup instead of crashing during teardown.

Local verification:

  • corepack pnpm --dir test/integration test -- processCleanup.test.ts (ran the integration suite; 18 files / 353 tests passed)
  • git diff --check

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.

Bug: StdioServerTransport doesn't handle stdin close/end — causes zombie process accumulation

1 participant