chore(mcp-server): restart the dev server only on real source changes

Merged
VI
3mo ago
+278-19

On Windows libuv subscribes fs.watch to FILE_NOTIFY_CHANGE_LAST_ACCESS, so merely reading a file emits a change event once NTFS flushes a new last-access time. node --watch restarts on any event for a file in its module graph without checking whether the contents moved, so the MCP server restarted once or twice during boot, on the first lazy better-sqlite3 import (the first connect() of every launch), and whenever another tool walked the tree.

Add scripts/dev-watch.cjs: it spawns the child, watches the source trees with the same recursive fs.watch, and compares mtime + size against a cache primed at startup before restarting, so last-access-only events are dropped. Bursts are debounced, the file that triggered the restart is logged, and generated folders (node_modules, dist, target, tests, test, bench, .turbo, coverage) are skipped.

Measured on this repo: boot goes from 1-2 restarts to none, the first connect() no longer restarts, and real content edits still reload in about 1.5s.

Summary by CodeRabbit

  • New Features

    • Added a more reliable development file watcher that automatically restarts the application when relevant source files change.
    • Development output now identifies triggering files and restart activity for easier troubleshooting.
    • Improved graceful shutdown, restart handling, and cross-platform behavior during development.
  • Documentation

    • Updated development guidance with setup details, watched paths, platform considerations, and watcher limitations.