npm运行mcp服务器
*赋予您的AI Agent使用现有的package.json脚本构建、测试和部署项目的能力。*
  ](https://www.npmjs.com/package/npm-run-mcp-server)    
npm运行mcp服务器 是一个 模型上下文协议(MCP) 自动桥接项目的服务器 npm 将脚本发送到您的AI助手。
- 🔍 自动检测 你的项目
package.json(没有硬编码路径)。 - 📦 适用于所有情况:npm、pnpm、yarn和bun。
- 🔒 安全且可配置:将特定脚本列入白名单,以防止意外执行。
- ⚡ 零配置:开箱即用,但可根据详细配置进行扩展。
______________________________________________________________________
⚡ 快速开始
在几秒钟内将代理连接到脚本。无需全局安装,只需让 npx 处理它。
克劳德桌面版
将此添加到您的 claude_desktop_config.json:
{
"mcpServers": {
"npm-scripts": {
"command": "npx",
"args": ["-y", "npm-run-mcp-server"]
}
}
}光标

- 首选 设置 > 特性 > MCP服务器.
- 点击 +添加新的MCP服务器.
- 输入详细信息:
- 类型: command - 名字: npm-scripts - 命令: npx - 参数: -y npm-run-mcp-server
VS代码(GitHub副本)

将此添加到您的工作区 .vscode/settings.json:
{
"github.copilot.chat.mcpServers": {
"npm-scripts": {
"command": "npx",
"args": ["-y", "npm-run-mcp-server"]
}
}
}______________________________________________________________________
🛠️ 配置
当 npm-run-mcp-server 立即工作,您可能不希望您的AI访问 *每* 脚本(如 eject 或 publish).您可以通过创建 npm-run-mcp.config.json 项目根目录中的文件。
配置示例
创建 npm-run-mcp.config.json 在您的旁边 package.json:
{
"include": ["test", "lint", "build", "start"],
"scripts": {
"test": {
"description": "Run the test suite. Use --watch for interactive mode.",
"inputSchema": {
"properties": {
"watch": { "type": "boolean", "description": "Watch files for changes" }
}
}
}
}
}配置选项
| 字段 | 类型 | 描述 |
|---|---|---|
include | string[] | 要公开的脚本名称白名单。如果省略, *全部* 脚本已公开。 |
exclude | string[] | 要隐藏的脚本名称黑名单。 |
scripts | object | 特定脚本的详细配置。 |
每个脚本选项
里面 scripts 对象,您可以将脚本名称映射到:
toolName:覆盖AI看到的工具名称(例如重命名test:unit到run_unit_tests).description:提供自定义描述,以帮助AI了解何时使用此脚本。inputSchema:定义AI可以传递的严格类型参数(映射到CLI标志)。
______________________________________________________________________
📖 运作原理
- 自动检测:服务器启动时,它会查找
package.json在您当前的工作空间中。它支持标准格式以及npm,pnpm,yarn,以及bun习俗。 - 工具创建:它将您的脚本转换为MCP工具。
- 脚本如 test:unit 成为像这样的工具 test_unit. - 工具描述包括实际命令(例如。, vitest run)所以AI知道它在运行什么。
- 执行:当AI调用工具时,服务器使用检测到的包管理器执行项目根目录中的脚本。
______________________________________________________________________
🔧 高级/CLI用法
您可以手动运行服务器进行调试,或者需要传递特定标志。
# Run directly
npx npm-run-mcp-server --list-scripts
# Run in a specific directory
npx npm-run-mcp-server --cwd /path/to/project
# Force a specific package manager
npx npm-run-mcp-server --pm pnpmCLI标志
- `--cwd
`:手动设置工作目录。
--pm:强制使用特定的包管理器。- `--config
`:特定JSON配置文件的路径。
--verbose:将调试日志打印到stderr。
______________________________________________________________________
🤝 贡献
欢迎投稿!请随时提交拉取请求。
- 分叉回购。
- 创建功能分支(
git checkout -b feature/amazing-feature). - 提交您的更改(
git commit -m 'Add some amazing feature'). - 推到分支(
git push origin feature/amazing-feature). - 打开拉取请求。
许可证
MIT© 费利克斯·斯图布纳
