Skip to content

fix: exit MCP server when the client closes stdin#30

Open
den-indance wants to merge 1 commit into
er77:masterfrom
den-indance:fix/exit-on-stdin-close
Open

fix: exit MCP server when the client closes stdin#30
den-indance wants to merge 1 commit into
er77:masterfrom
den-indance:fix/exit-on-stdin-close

Conversation

@den-indance

Copy link
Copy Markdown

Fixes #29

Problem

The stdio transport keeps the Node event loop alive after the MCP client
disconnects, so the server process never exits on its own — leaking one
node process per session. Especially acute under docker exec -i, which
does not propagate the client disconnect to the in-container process.

Fix

Register end/close handlers on process.stdin in main() that log a
system event and process.exit(0).

Testing

  • npm run typecheck — pass
  • npm run build (tsup) — pass
  • npm test — 33/33 pass
  • Confirmed the handlers are present in the built dist/index.js.

The stdio transport keeps the Node event loop alive after the MCP client
disconnects, so the process never exits on its own. This leaks one node
process per session, and is especially acute when the server is launched
via `docker exec -i`, which does not propagate the client disconnect to
the in-container process.

Exit cleanly when stdin emits `end`/`close`.
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.

MCP server process never exits when client closes stdin (leaks one node process per session)

1 participant