项目简介

'npm-helper-mcp' 是一个基于 Model Context Protocol (MCP) 构建的服务器,旨在让大型语言模型(LLM)能够与npm包生态系统进行交互。它提供了一系列工具,用于搜索npm注册表、获取包详情、检查并更新项目依赖,以及解决依赖冲突等。这使得LLM能够协助开发者进行自动化的npm项目维护和管理。

主要功能点

  • NPM 包搜索: 根据关键词快速搜索npm注册表中的包。
  • 包内容与详情获取: 抓取npm包的详细页面内容(如README)和元数据(版本、作者、下载量等)。
  • 依赖更新检查: 扫描'package.json'文件,找出项目中过时的依赖项及其最新版本。
  • 依赖升级: 自动将项目依赖项更新到指定的目标版本。
  • 依赖冲突解决: 利用“peer”策略帮助识别并解决潜在的依赖冲突。
  • 版本约束配置: 设置或调整依赖项的版本升级规则。
  • 依赖健康检查 (Doctor模式): 迭代安装升级并运行测试,以识别可能导致项目中断的升级。

安装步骤

  1. 克隆仓库:
    git clone https://github.com/Sametcanj/npm-helper-mcp.git
  2. 进入项目目录:
    cd npm-helper-mcp
  3. 安装依赖:
    npm install
  4. 构建项目:
    npm run build
  5. 启动服务器:
    npm start
    注意: 服务器启动后,它将通过标准输入/输出 (stdio) 与MCP客户端通信,不会在命令行显示传统的HTTP接口。

服务器配置

此MCP服务器通过标准输入输出(stdio)协议与MCP客户端通信。LLM客户端需要提供以下配置来启动并连接到此服务器:

{
  "name": "npm-helper-mcp",
  "command": "node",
  "args": ["<path_to_npm-helper-mcp_repo>/dist/index.js"],
  "description": "一个用于NPM包管理和依赖更新的MCP服务器,与大型语言模型交互。",
  "tools": [
    {
      "name": "search_npm",
      "description": "搜索npm包",
      "inputSchema": { "type": "object", "properties": { "query": { "type": "string" }, "maxResults": { "type": "number", "default": 10 } }, "required": ["query"] }
    },
    {
      "name": "fetch_package_content",
      "description": "从npm包页面URL获取详细内容",
      "inputSchema": { "type": "object", "properties": { "url": { "type": "string" } }, "required": ["url"] }
    },
    {
      "name": "get_package_versions",
      "description": "获取npm包的可用版本",
      "inputSchema": { "type": "object", "properties": { "packageName": { "type": "string" } }, "required": ["packageName"] }
    },
    {
      "name": "get_package_details",
      "description": "获取npm包的详细信息",
      "inputSchema": { "type": "object", "properties": { "packageName": { "type": "string" } }, "required": ["packageName"] }
    },
    {
      "name": "check_updates",
      "description": "扫描package.json以查找过时的依赖项",
      "inputSchema": { "type": "object", "properties": { "packagePath": { "type": "string" }, "filter": { "type": "array", "items": { "type": "string" }}, "reject": { "type": "array", "items": { "type": "string" }}, "target": { "type": "string", "enum": ["latest", "newest", "greatest", "minor", "patch", "semver"] }, "peer": { "type": "boolean" }, "minimal": { "type": "boolean" }, "packageManager": { "type": "string", "enum": ["npm", "yarn", "pnpm", "deno", "bun", "staticRegistry"] } }}
    },
    {
      "name": "upgrade_packages",
      "description": "升级package.json中的依赖项",
      "inputSchema": { "type": "object", "properties": { "packagePath": { "type": "string" }, "upgradeType": { "type": "string", "enum": ["latest", "newest", "greatest", "minor", "patch", "semver"] }, "peer": { "type": "boolean" }, "minimal": { "type": "boolean" }, "packageManager": { "type": "string", "enum": ["npm", "yarn", "pnpm", "deno", "bun", "staticRegistry"] } }}
    },
    {
      "name": "filter_updates",
      "description": "检查/升级特定包的更新",
      "inputSchema": { "type": "object", "properties": { "packagePath": { "type": "string" }, "filter": { "type": "array", "items": { "type": "string" }}, "upgrade": { "type": "boolean" }, "minimal": { "type": "boolean" }, "packageManager": { "type": "string", "enum": ["npm", "yarn", "pnpm", "deno", "bun", "staticRegistry"] } }, "required": ["filter"] }
    },
    {
      "name": "resolve_conflicts",
      "description": "处理依赖冲突(使用'peer'策略)",
      "inputSchema": { "type": "object", "properties": { "packagePath": { "type": "string" }, "upgrade": { "type": "boolean" }, "minimal": { "type": "boolean" }, "packageManager": { "type": "string", "enum": ["npm", "yarn", "pnpm", "deno", "bun", "staticRegistry"] } }}
    },
    {
      "name": "set_version_constraints",
      "description": "配置依赖项的版本升级规则",
      "inputSchema": { "type": "object", "properties": { "packagePath": { "type": "string" }, "target": { "type": "string", "enum": ["latest", "newest", "greatest", "minor", "patch", "semver"] }, "removeRange": { "type": "boolean" }, "upgrade": { "type": "boolean" }, "minimal": { "type": "boolean" }, "packageManager": { "type": "string", "enum": ["npm", "yarn", "pnpm", "deno", "bun", "staticRegistry"] } }, "required": ["target"] }
    },
    {
      "name": "run_doctor",
      "description": "迭代安装升级并运行测试",
      "inputSchema": { "type": "object", "properties": { "packagePath": { "type": "string" }, "doctorInstall": { "type": "string" }, "doctorTest": { "type": "string" }, "packageManager": { "type": "string", "enum": ["npm", "yarn", "pnpm", "deno", "bun", "staticRegistry"] } }}
    }
  ]
}
  • 'command':启动Node.js解释器。
  • 'args':指向编译后的服务器入口文件。您需要将'<path_to_npm-helper-mcp_repo>'替换为实际的项目根目录路径。
  • 'tools':声明了该服务器提供的所有工具,包括其名称、描述和输入参数(遵循JSON Schema)。LLM客户端将根据这些信息来理解和调用服务器提供的功能。

基本使用方法

  1. 确保已按照安装步骤启动了 'npm-helper-mcp' 服务器。
  2. 在您的MCP客户端(如与LLM集成的开发环境)中,配置上述服务器信息。
  3. LLM客户端将能够通过JSON-RPC请求调用此服务器提供的工具。例如,LLM可以调用'search_npm'工具来查找npm包,调用'check_updates'来检查项目依赖更新,或调用'upgrade_packages'来执行升级操作。所有工具的输入参数都将由LLM根据其内部逻辑和用户指令生成。

信息

分类

开发者工具