This MCP server enables AI agents to execute npm package.json scripts as tools, providing seamless integration with development workflows.
Core Capabilities:
Execute npm scripts: Run any script defined in your project's
package.json(e.g.,build,start,test,prepublishOnly) through an AI interfacePass script arguments: Provide optional command-line arguments to scripts via an
argsparameterAutomatic detection: Dynamically finds the closest
package.jsonand detects your package manager (npm, pnpm, yarn, or bun)Multi-project support: Works across different projects without configuration changes by automatically targeting the current project context
AI Integration:
Compatible with GitHub Copilot Chat, Claude Code (VS Code and desktop), and Cursor
Functions as a Model Context Protocol (MCP) server for AI-assisted development
Additional Features:
CLI functionality to list available scripts and run with verbose output
Override automatic detection with custom working directory and package manager options
Detailed logging for debugging purposes
Exposes package.json scripts as MCP tools, allowing AI agents to execute Bun scripts with optional arguments
Exposes package.json scripts as MCP tools, allowing AI agents to execute npm scripts with optional arguments
Exposes package.json scripts as MCP tools, allowing AI agents to execute pnpm scripts with optional arguments
Exposes package.json scripts as MCP tools, allowing AI agents to execute Yarn scripts with optional arguments
npm-run-mcp-server
A Model Context Protocol (MCP) server that exposes your project's
Table of Contents
Related MCP server: SuperiorAPIs MCP Server Tool
Install
Installation options.
Usage
MCP server and CLI tool usage.
As an MCP Server
Add this server to your MCP host configuration. It uses stdio and automatically detects your project's package.json using workspace environment variables or by walking up from the current working directory.
Key Features:
Automatic Workspace Detection: Works seamlessly across different projects without configuration changes
Smart Tool Names: Script names with colons (like
test:unit) are automatically converted to valid tool names (test_unit)Rich Descriptions: Each tool includes the actual script command in its description
Package Manager Detection: Automatically detects npm, pnpm, yarn, or bun
Optional Arguments: Each tool accepts optional
args(stringorstring[]) appended after--when running the scriptAuto-Restart on Changes: Automatically restarts when
package.jsonor config changes, ensuring tools are always up-to-date
Note: scripts run inside the target project. If they rely on local dependencies (eslint, vitest, tsc), install them first (for example, npm install).
As a CLI Tool
You can also use this package directly from the command line:
Configuration
Setup instructions for AI agents.
GitHub Copilot (VS Code)
Via UI
Open VS Code settings
Search for "MCP"
Add server configuration in settings.json
Via Config File
Option A — per-workspace via .vscode/mcp.json (recommended for multi-project use):
Option B — user settings (settings.json):
Then open Copilot Chat, switch to Agent mode, and start the npm-scripts server from the tools panel.
Cursor
Via UI
Open Settings -> MCP Servers -> Add MCP Server
Type: NPX Package
Command:
npxArguments:
-y npm-run-mcp-serverSave and start the server from the tools list
Via Config File
Add to Cursor's MCP configuration:
Claude Code
Via Terminal
Via Config File
Add to Claude Code's config file:
Windows:
%APPDATA%/Claude/claude_desktop_config.jsonmacOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonLinux:
~/.config/Claude/claude_desktop_config.json
Restart Claude Code after editing the config.
Multi-Project Workflow
The MCP server automatically detects your project's package.json using workspace environment variables or by walking up from the current working directory. No hardcoded paths needed - it works seamlessly across all your projects.
Auto-Restart on Script Changes
The server automatically monitors your package.json file (and npm-run-mcp.config.json if present) for changes. When you modify scripts or config, the server gracefully exits to allow the MCP client to restart with updated tools.
Script Exposure Config
You can make the tool surface more deterministic by explicitly choosing which scripts are exposed and by defining per-script tool metadata.
Create npm-run-mcp.config.json (or .npm-run-mcp.json) next to your project's package.json:
Notes:
includeandexcludeare exact script names.toolNamelets you resolve naming collisions after sanitization.inputSchemaextends the default input model (andargsis always available).Tool input fields (other than
args) are converted to CLI flags, e.g.{ "watch": true }becomes--watchand{ "port": 3000 }becomes--port 3000.If filters result in zero tools, the server logs a warning so misconfigurations are easy to spot.
Config files support JSONC (comments + trailing commas). A JSON Schema is published as
npm-run-mcp.config.schema.json.
Install from source (for testing in another project)
Clone, build, and link globally:
In your other project, either reference the global binary or the built file directly:
Using the linked binary:
Using an explicit Node command (no global link needed):
Optional CLI flags you can pass in args:
--cwd /path/to/projectto choose which project to readpackage.jsonfrom (rarely needed - server auto-detects by default)--pm npm|pnpm|yarn|bunto override package manager detection
Testing with MCP Inspector
Test the server locally.
You should see your package.json scripts listed as available tools. Try running one - it executes the script and returns the output.
CLI Options
Command-line flags.
--cwd <path>- Specify working directory (defaults to current directory)--config <path>- Use an explicit config file path (relative to the project directory, or absolute)--pm <manager>- Override package manager detection (npm|pnpm|yarn|bun)--verbose- Enable detailed logging to stderr--list-scripts- List available scripts and exit
Contributing
Contributions welcome! How to help with development, reporting issues, and submitting changes.
Reporting Issues
Use the issue tracker to report bugs
Include your Node.js version, package manager, and operating system
Provide a minimal reproduction case when possible
Submitting Changes
Fork the repository
Create a feature branch:
git checkout -b feature/amazing-featureMake your changes and add tests if applicable
Test your changes:
npm run build && npm run testCommit your changes:
git commit -m 'Add amazing feature'Push to the branch:
git push origin feature/amazing-featureSubmit a pull request
Development Setup
The project uses a custom build script located in scripts/build.cjs that handles TypeScript compilation and shebang injection for the executable.
License
MIT License.