Skip to content

feat(server): add host process watchdog to StdioServerTransport#1572

Closed
aptsalt wants to merge 1 commit intomodelcontextprotocol:mainfrom
aptsalt:feat/stdio-host-watchdog
Closed

feat(server): add host process watchdog to StdioServerTransport#1572
aptsalt wants to merge 1 commit intomodelcontextprotocol:mainfrom
aptsalt:feat/stdio-host-watchdog

Conversation

@aptsalt
Copy link

@aptsalt aptsalt commented Feb 22, 2026

Summary

  • Adds clientProcessId option to StdioServerTransport that enables a watchdog timer
  • Watchdog periodically checks if the host process is alive using signal 0 (process.kill(pid, 0))
  • Self-terminates the transport when the host is gone, preventing orphaned server processes
  • Configurable check interval via watchdogIntervalMs (default: 3s)
  • New StdioServerTransportOptions interface with backwards-compatible constructor overloads
  • Timer uses unref() so it doesn't prevent clean process exit

Follows the same pattern used in vscode-languageserver-node as suggested in the issue.

Closes #208

Test plan

  • should close transport when host process is gone — watchdog detects dead PID and closes
  • should not close when host process is alive — no false positives with own PID
  • should stop watchdog on close — cleanup on transport close
  • should accept options object constructor — new constructor form works
  • All 7 stdio tests pass
  • Build succeeds

🤖 Generated with Claude Code

When clientProcessId is provided, the transport periodically checks
if the host process is alive using signal 0 and self-terminates if
the host is gone. This prevents orphaned server processes when the
host crashes without cleanly shutting down.

Closes #208

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@aptsalt aptsalt requested a review from a team as a code owner February 22, 2026 09:59
@changeset-bot
Copy link

changeset-bot bot commented Feb 22, 2026

🦋 Changeset detected

Latest commit: 25c2a3f

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

This PR includes changesets to release 4 packages
Name Type
@modelcontextprotocol/server Minor
@modelcontextprotocol/express Major
@modelcontextprotocol/hono Major
@modelcontextprotocol/node Major

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
Copy link

pkg-pr-new bot commented Feb 22, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1572

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1572

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1572

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1572

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1572

commit: 25c2a3f

@aptsalt aptsalt closed this by deleting the head repository Feb 23, 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.

Add ways for server processes to self-terminate when host is gone

1 participant