u/ItsDeadWeight

made a small supervisor for stdio MCP server processes, no dependencies
▲ 3 r/node+1 crossposts

made a small supervisor for stdio MCP server processes, no dependencies

I've seen a bunch of people talking about the same problem with MCP: orphaned child processes that don't die when they're supposed to. it's not just one person's issue either, the TypeScript SDK has an open issue where closing the transport doesn't kill the process tree, Codex CLI has one about orphaned npx-spawned MCP servers piling up over time, context7-mcp has one where the process just doesn't exit when its parent dies. all different projects, same root cause: something like npx forks the real server as its own child, and killing the wrapper's PID doesn't touch it.

I looked for a small library that just handled this and couldn't find one. I pulled this out of a bigger project I'm working on because it felt like something worth having on its own: https://github.com/ImDeadWeight/stdio-supervisor

what it does:

  • restarts a crashed process with capped backoff
  • kills the whole process tree on stop, not just the direct child (taskkill /T on windows, process group signaling on posix)
  • handles the .cmd shim and argv quoting for npx/npm on windows
  • frames stdout into whole lines
  • onSpawn fires on start and on every crash-restart, so you get a clean signal to redo a handshake against the new process
  • optional timeout watchdog on send() for when a process goes quiet

no protocol opinion, no daemonizing, no CLI. just the part where you spawn and keep a handful of stdio children alive without it silently breaking on you.

MIT. let me know if you find anything wrong with it.

Edit: a word

Edit: Now imports execFile, fs, path, and StringDecoder from Node. Also imports crossSpawn.

u/ItsDeadWeight — 1 day ago