PR详情提取服务

一个通过GitHub CLI从git提交哈希中提取PR详细信息的MCP服务器,适用于AI代理和开发者工具。

  • by vltansky
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 vltansky/commit-to-pr-mcp

使用说明

致力于公关mcp

MCP(模型上下文协议)服务器,使AI代理能够使用GitHub CLI从git提交哈希中提取PR详细信息。

特性

  • 致力于公关解决方案:自动从提交哈希、合并提交和压缩提交中提取PR编号
  • 自动检测:自动从git工作目录中检测GitHub存储库
  • 全面的公关数据:检索完整的PR详细信息,包括标题、描述、作者、状态、标签和评论
  • 灵活输入:接受提交哈希(完整或简短)、分支名称或直接PR编号
  • 类型安全:使用TypeScript和Zod构建,用于运行时验证

先决条件

  • Node.js >= 18.0.0
  • GitHub命令行界面 已安装并验证(gh auth login)
  • MCP兼容客户端(Cursor、Claude Desktop、VS Code等)

安装

入门指南

首先,在客户端安装提交到pr-mcp服务器。

标准配置 适用于大多数工具:

{
  "mcpServers": {
    "commit-to-pr": {
      "command": "npx",
      "args": [
        "commit-to-pr-mcp@latest"
      ]
    }
  }
}
Claude Code

使用Claude Code CLI添加服务器:

claude mcp add commit-to-pr npx commit-to-pr-mcp@latest
Claude Desktop

添加到您的Claude Desktop配置(~/Library/Application Support/Claude/claude_desktop_config.json 在macOS上):

{
  "mcpServers": {
    "commit-to-pr": {
      "command": "npx",
      "args": ["commit-to-pr-mcp@latest"]
    }
  }
}
Cursor

单击按钮安装:

或手动安装:

首选 Cursor Settings → MCP → Add new MCP Server.按你的喜好命名,使用 command 使用命令键入 npx commit-to-pr-mcp@latest。您还可以通过单击来验证配置或添加命令参数 Edit.

项目特定配置

创建 .cursor/mcp.json 在项目根目录中:

{
  "mcpServers": {
    "commit-to-pr": {
      "command": "npx",
      "args": ["commit-to-pr-mcp@latest"]
    }
  }
}
VS Code

跟随 MCP安装指南,使用上面的标准配置。

或者,使用VS Code CLI进行安装:

code --add-mcp '{"name":"commit-to-pr","command":"npx","args":["commit-to-pr-mcp@latest"]}'
Cline

通过Cline VS Code扩展设置或更新您的 cline_mcp_settings.json 文件:

{
  "mcpServers": {
    "commit-to-pr": {
      "command": "npx",
      "args": [
        "commit-to-pr-mcp@latest"
      ]
    }
  }
}
Zed

跟随 MCP服务器文档.使用上面的标准配置。


本地开发

对于本地开发和测试:

{
  "mcpServers": {
    "commit-to-pr": {
      "command": "node",
      "args": ["/absolute/path/to/commit-to-pr-mcp/dist/index.js"],
      "env": {
        "LOG_LEVEL": "debug"
      }
    }
  }
}

验证安装

安装后,验证提交到pr mcp是否正常工作:

  1. 重新启动MCP客户端 完全
  2. 检查连接状态:
    • 光标:在设置中查找绿点→ 工具和集成→ MCP工具
    • 克劳德桌面版:检查可用工具中的“commit_to_pr”
    • VS Code:在GitHub Copilot设置中验证
  3. 使用简单查询进行测试:
    Get PR details for commit abc123
    

如果你看到AI代理使用 get_pr 工具和返回PR信息,一切就绪! 🎉

用法

服务器提供了一个工具: get_pr

基本示例:从提交哈希中获取PR

{
  "commit": "abc123def456",
  "repo": "owner/repo"  // Optional: auto-detected from git working directory
}

示例:从分行名称获取PR

{
  "commit": "feature/new-feature",
  "cwd": "/path/to/repo"  // Optional: specify working directory for auto-detection
}

示例:直接通过数字获取PR

{
  "pr_number": 42,
  "repo": "owner/repo"  // Optional: auto-detected from git working directory
}

示例:自动检测存储库

在git存储库中工作时,可以省略 repo 参数:

{
  "commit": "abc123"
  // Repository is automatically detected from git remote
}

刀具参数

get_pr

通过提交哈希或PR编号获取PR详细信息。从git提交(合并提交、挤压提交)中提取PR编号,并返回完整的PR详细信息。

参数:

  • commit (可选):Git提交哈希(完整或简短)、分支名称或任何Git引用。使用此OR pr_number.
  • pr_number (可选):直接查找PR编号。使用此OR commit.
  • repo (可选):GitHub存储库 owner/repo 格式。如果未提供,则自动检测 cwd 或当前工作目录。
  • cwd (可选):从git remote自动检测GitHub存储库的工作目录路径。

注: 要么 commit 或 pr_number 必须提供。

响应格式

该工具返回结构化响应:

{
  "number": 42,
  "title": "Add new feature",
  "body": "This PR adds a new feature...",
  "state": "MERGED",
  "url": "https://github.com/owner/repo/pull/42",
  "author": "username",
  "createdAt": "2025-01-15T10:30:00Z",
  "mergedAt": "2025-01-16T14:20:00Z",
  "baseRef": "main",
  "headRef": "feature/new-feature",
  "labels": ["enhancement", "ready-for-review"],
  "reviews": [
    {
      "author": "reviewer1",
      "state": "APPROVED",
      "submittedAt": "2025-01-16T12:00:00Z"
    },
    {
      "author": "reviewer2",
      "state": "CHANGES_REQUESTED",
      "submittedAt": "2025-01-16T13:00:00Z"
    }
  ]
}

响应字段

  • number:PR编号
  • title:PR标题
  • body:PR描述/正文
  • state:PR状态(OPEN, CLOSED, MERGED)
  • url:PR的GitHub URL
  • author:PR作者用户名
  • createdAt:创建时间戳(ISO 8601)
  • mergedAt:合并时间戳(ISO 8601), null 如果不合并
  • baseRef:目标分支名称
  • headRef:源分支名称
  • labels:标签名称数组
  • reviews:一系列审查对象 author, state,以及 submittedAt

运作原理

服务器使用GitHub CLI(gh)致:

  1. 从提交中提取PR编号:

    • 搜索包含提交哈希的PR
    • 解析合并提交消息(Merge pull request #123)
    • 解析南瓜提交消息((#123))
  2. 检索PR详细信息:

    • 通过以下方式获取全面的公关信息 gh pr view
    • 包括评论、标签和元数据
  3. 自动检测存储库:

    • 阅读 git remote get-url origin 从工作目录
    • 提取物 owner/repo 从远程URL格式化

发展

设置

npm install
npm run build

测试

对于本地测试:

  1. 构建项目:

    npm run build
    
  2. 配置您的MCP客户端以使用本地构建(请参阅上面的本地开发部分)

  3. 与MCP检查员或客户进行测试

开发脚本

  • npm run build:将TypeScript编译为JavaScript
  • npm run start:运行已编译的服务器
  • npm run dev:以开发模式运行服务器 tsx

建筑

src/
└── index.ts              # Main server implementation
    ├── Tool handlers     # get_pr tool logic
    ├── Git utilities     # Repository detection
    └── GitHub CLI        # PR extraction and details

许可证

ISC

贡献

欢迎投稿!请阅读投稿指南并提交PR。

相关项目