Turn every npm script in your project's package.json into an MCP tool your AI assistant can invoke.
Status: Functional but bare-bones (pre-1.0). Behavior & tool naming may still evolve—feedback welcome.
- Install (or skip and rely on npx each run)
npm i -D mcp-npm-scripts- Add to your .vscode/mcp.json (or create it if it doesn't exist)
{
"servers": {
"npm-scripts": {
"command": "npx",
"args": ["mcp-npm-scripts"],
"cwd": "${workspaceFolder}"
}
}
}- Reload your MCP-enabled client (VS Code / other)
- Ask the AI to run one of your scripts, e.g. "Run the test tool".
That's it—your npm scripts are now callable as tools! Depending on your IDE settings, you may still be prompted to allow the AI to call them the first time.
mcp-npm-scripts is a lightweight Model Context Protocol server. Point it at (or let it auto-detect) a package.json and it registers one MCP tool per npm script. Calling a tool runs npm run <original-script-name> and returns the combined stdout + stderr as a text response to the client (e.g. VS Code / Claude Desktop / other MCP-enabled IDEs).
Use cases / benefits:
- Let an AI run lint, build, test, format, type-check tasks.
- Provide project-specific helper scripts (scaffolding, codegen) as safe, explicit tools instead of arbitrary shell access.
- Avoid granting blanket terminal command execution or dealing with a confirmation prompt for every arbitrary command: you approve the curated set of npm scripts once.
- Quickly expose repeatable workflows while keeping control in versioned scripts.
- Startup: The CLI locates a
package.json(via explicit path argument or by walking upward from the current working directory, skipping its own dev package). - Discovery: Every entry under the
scriptsfield is read - Tool naming: Each script name is sanitized to a valid MCP tool ID:
- Lowercase
- Replace any run of disallowed chars (
[^a-z0-9_-]) with a single underscore - Trim leading/trailing underscores
- If that yields a duplicate, append
_2,_3, ...
- Registration: A tool is registered with description
npm script: <command>(or indicating original name if sanitizing changed it). The input schema accepts an optionalargsarray. - Execution: When invoked, the server spawns
npm run <originalScriptName> [-- <args...>]in the script's package directory, streaming stdout/stderr into one consolidated text result once the process exits. - Controlled surface (with caveat): Only declared npm scripts become tools—no arbitrary shell access is exposed directly. However, if the AI (or another user) can edit
package.json, it could modify scripts to run arbitrary commands. Treat write access topackage.jsonwith the same trust level as giving broader shell execution.
No file watching yet—restart the server to pick up added/removed scripts (live refresh may come later).
Tool responses contain a single text part with merged stdout & stderr. If the script exits silently you still see npm's prelude lines (useful success signal). Exit codes are not yet surfaced separately—future versions may add a structured result.
Basic setup is covered in Quickstart. For monorepos or explicit targeting you can supply a path arg (either the full path to a package.json or the path to a dir containing package.json):
Similar steps should work in other MCP-enabled IDEs.
Right now only one package.json (the first found walking upward from the specified/working directory) is used. Point the server at a specific package's directory (or file) for per-package tools. Future enhancements may allow aggregating multiple packages.
- Tools execute whatever the underlying npm scripts do—treat them with the same trust you already place in your scripts.
- Granting access to these tools is usually safer than granting a blanket "run arbitrary shell commands" permission and avoids repeated confirmations for each unrelated command.
- Environment variables from the parent process are inherited. Redact or sandbox as needed.
- Output may contain secrets your scripts print—avoid echoing sensitive data.
- If the AI can modify
package.json, it can add a new script that runs arbitrary commands. Mitigations: code review / PR gating, read-only workspace mode, pre-commit hooks, or monitoring changes topackage.json.
- No live re-scan of scripts (restart to refresh).
- Exit code not yet exposed separately from text output.
Pull requests are very welcome—especially for items in the roadmap! If unsure, please open a brief issue or draft PR outlining your idea first.
npm install
npm run dev # watch rebuildRun the dev server against some other project while iterating:
node dist/cli.js ../some-other-projectPlanned / open:
- Descriptions for each tool loaded from package.json
- Optional live script refresh (file watch & listChanged updates)
- Structured result including exit code & timing
- Multi-package (monorepo) aggregation mode
MIT
{ "servers": { "npm-scripts": { "command": "npx", "args": ["mcp-npm-scripts", "packages/app"], "cwd": "${workspaceFolder}", }, }, }