0.1.3 • Published 7 months ago

@qwe8652591/rules-fetch v0.1.3

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

Git-Fetch MCP 服务器

这是一个基于MCP(Meta Content Protocol)协议的文档获取服务器,支持从Git仓库获取内容并复制到本地目录。

功能

  • 从Git仓库获取指定文件或目录
  • 支持指定分支
  • 将获取的内容复制到本地目标路径

安装

# 安装依赖
npm install

# 构建项目
npm run build

使用方法

本地安装后运行

启动服务器:

npm start

或在开发模式下运行:

npm run dev

通过 npx 直接运行

无需安装,可以直接通过 npx 运行:

# 运行最新版本
npx @qwe8652591/rules-fetch

# 运行特定版本
npx @qwe8652591/rules-fetch@0.1.0

# 使用模拟模式
USE_MOCK_GIT=true npx @qwe8652591/rules-fetch

提供的工具

git_fetch

从Git仓库获取内容并复制到当前工具目录。

参数:

  • repositoryUrl: Git仓库的URL (必需)
  • branch: 分支名称 (可选)
  • sourcePath: 仓库中源文件的路径 (必需)
  • targetPath: 目标文件路径 (必需)

示例:

{
  "repositoryUrl": "https://github.com/username/repo.git",
  "branch": "main",
  "sourcePath": "docs/README.md",
  "targetPath": "docs/fetched-readme.md"
}

MCP服务器配置

要在AI助手中使用此服务器,您需要在助手的配置中添加以下MCP服务器配置:

Windows配置

{
  "mcpServers": {
    "git-fetch": {
      "command": "cmd",
      "args": ["/c", "node", "{ABSOLUTE_PATH}/dist/index.js"],
      "type": "command",
      "env": {
        "FETCH_TIMEOUT": "30000",
        "NODE_ENV": "production"
      },
      "logLevel": "info",
      "autoApprove": ["git_fetch"]
    }
  }
}

macOS/Linux配置

{
  "mcpServers": {
    "git-fetch": {
      "command": "node",
      "args": ["{ABSOLUTE_PATH}/dist/index.js"],
      "type": "command",
      "env": {
        "FETCH_TIMEOUT": "30000",
        "NODE_ENV": "production"
      },
      "logLevel": "info",
      "autoApprove": ["git_fetch"]
    }
  }
}

Docker配置

{
  "mcpServers": {
    "git-fetch": {
      "command": "docker",
      "args": ["run", "-i", "git-fetch-mcp"],
      "type": "command",
      "env": {
        "FETCH_TIMEOUT": "30000"
      },
      "logLevel": "info",
      "autoApprove": ["git_fetch"]
    }
  }
}

配置参数说明

  • command: 启动MCP服务器的命令
  • args: 传递给command的参数列表
    • {ABSOLUTE_PATH} 应替换为实际的绝对路径
  • type: 通信协议类型,这里使用"command"通过标准输入输出与本地进程通信
  • env: 环境变量配置
    • FETCH_TIMEOUT: 请求超时时间(毫秒)
    • NODE_ENV: 运行环境
  • logLevel: 日志级别(debug/info/warn/error)
  • autoApprove: 自动批准的工具列表,无需每次都确认

与AI助手集成

此MCP服务器可以与支持MCP协议的AI助手集成,使它们能够:

  1. 发现服务器提供的git_fetch工具
  2. 调用该工具获取Git仓库中的内容
  3. 使用获取的内容进行进一步处理或向用户提供响应

开发

如果需要添加更多功能,可以在src/目录下创建新的工具类,并在index.ts中注册。

发布到 npm

本项目支持发布到 npm 仓库,详细的发布流程请查看 NPM发布指南

简要步骤:

# 登录 npm
npm login

# 构建项目(也可以跳过,因为 prepublishOnly 会自动构建)
npm run build

# 发布公开包
npm publish --access public

# 更新版本并发布
npm version patch  # 或 minor 或 major
npm publish --access public

许可证

MIT

0.1.3

7 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.1.0

7 months ago