npm-run-mcp-server 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +11 -0
  2. package/dist/index.js +25 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -51,6 +51,7 @@ Add this server to your MCP host configuration. It uses stdio and automatically
51
51
  - **Rich Descriptions**: Each tool includes the actual script command in its description
52
52
  - **Package Manager Detection**: Automatically detects npm, pnpm, yarn, or bun
53
53
  - **Optional Arguments**: Each tool accepts an optional `args` string that is appended after `--` when running the script
54
+ - **Auto-Restart on Changes**: Automatically restarts when `package.json` scripts are modified, ensuring tools are always up-to-date
54
55
 
55
56
  ### As a CLI Tool
56
57
 
@@ -116,6 +117,16 @@ The MCP server is designed to work seamlessly across multiple projects without c
116
117
 
117
118
  This means you can use the same MCP configuration across all your projects, and the server will automatically target the correct project based on your current workspace.
118
119
 
120
+ ### Auto-Restart on Script Changes
121
+
122
+ The MCP server automatically monitors your `package.json` file for changes. When you add, remove, or modify scripts, the server will:
123
+
124
+ 1. **Detect the change** and log it (with `--verbose` flag)
125
+ 2. **Gracefully exit** to allow the MCP client to restart the server
126
+ 3. **Reload with new tools** based on the updated scripts
127
+
128
+ This ensures your MCP tools are always synchronized with your current `package.json` scripts without manual intervention.
129
+
119
130
  ### Install in Claude Code (VS Code extension)
120
131
 
121
132
  Add to VS Code user/workspace settings (`settings.json`):
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { readFileSync, existsSync } from 'fs';
2
+ import { readFileSync, existsSync, watch } from 'fs';
3
3
  import { promises as fsp } from 'fs';
4
4
  import { dirname, resolve } from 'path';
5
5
  import { fileURLToPath } from 'url';
@@ -267,6 +267,30 @@ async function main() {
267
267
  if (verbose) {
268
268
  console.error(`[mcp] stdio transport connected (waiting for initialize)`);
269
269
  }
270
+ // Set up file watcher for package.json changes
271
+ if (pkgJsonPath) {
272
+ if (verbose) {
273
+ console.error(`[mcp] setting up file watcher for: ${pkgJsonPath}`);
274
+ }
275
+ const watcher = watch(pkgJsonPath, (eventType) => {
276
+ if (eventType === 'change') {
277
+ if (verbose) {
278
+ console.error(`[mcp] package.json changed, restarting server...`);
279
+ }
280
+ // Gracefully exit to allow the MCP client to restart the server
281
+ process.exit(0);
282
+ }
283
+ });
284
+ // Handle cleanup on process exit
285
+ process.on('SIGINT', () => {
286
+ watcher.close();
287
+ process.exit(0);
288
+ });
289
+ process.on('SIGTERM', () => {
290
+ watcher.close();
291
+ process.exit(0);
292
+ });
293
+ }
270
294
  }
271
295
  // Run
272
296
  main().catch((err) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-run-mcp-server",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "An MCP server that exposes package.json scripts as tools for agents.",
5
5
  "bin": {
6
6
  "npm-run-mcp-server": "dist/index.js"