npm-run-mcp-server 0.2.6 → 0.2.8

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 +39 -3
  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';
@@ -160,7 +160,7 @@ async function main() {
160
160
  }
161
161
  const __filename = fileURLToPath(import.meta.url);
162
162
  const __dirname = dirname(__filename);
163
- const selfPkgPath = resolve(__dirname, '..', 'package.json');
163
+ const selfPkgPath = resolve(__dirname, 'package.json');
164
164
  let serverName = 'npm-run-mcp-server';
165
165
  let serverVersion = '0.0.0';
166
166
  try {
@@ -170,9 +170,21 @@ async function main() {
170
170
  serverName = selfPkg.name;
171
171
  if (selfPkg.version)
172
172
  serverVersion = selfPkg.version;
173
+ if (verbose) {
174
+ console.error(`[mcp] loaded server info: ${serverName}@${serverVersion}`);
175
+ }
176
+ }
177
+ else {
178
+ if (verbose) {
179
+ console.error(`[mcp] package.json not found at: ${selfPkgPath}`);
180
+ }
181
+ }
182
+ }
183
+ catch (error) {
184
+ if (verbose) {
185
+ console.error(`[mcp] error reading package.json:`, error);
173
186
  }
174
187
  }
175
- catch { }
176
188
  const server = new McpServer({ name: serverName, version: serverVersion });
177
189
  // Handle case where no package.json was found
178
190
  if (!projectDir || !projectPkg) {
@@ -267,6 +279,30 @@ async function main() {
267
279
  if (verbose) {
268
280
  console.error(`[mcp] stdio transport connected (waiting for initialize)`);
269
281
  }
282
+ // Set up file watcher for package.json changes
283
+ if (pkgJsonPath) {
284
+ if (verbose) {
285
+ console.error(`[mcp] setting up file watcher for: ${pkgJsonPath}`);
286
+ }
287
+ const watcher = watch(pkgJsonPath, (eventType) => {
288
+ if (eventType === 'change') {
289
+ if (verbose) {
290
+ console.error(`[mcp] package.json changed, restarting server...`);
291
+ }
292
+ // Gracefully exit to allow the MCP client to restart the server
293
+ process.exit(0);
294
+ }
295
+ });
296
+ // Handle cleanup on process exit
297
+ process.on('SIGINT', () => {
298
+ watcher.close();
299
+ process.exit(0);
300
+ });
301
+ process.on('SIGTERM', () => {
302
+ watcher.close();
303
+ process.exit(0);
304
+ });
305
+ }
270
306
  }
271
307
  // Run
272
308
  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.8",
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"