mcpField
A
Azure DevOps Pull Request MCP Server

Azure DevOps Pull Request MCP Server

本地服务
github.com/oshvartz云与基础设施178 周前更新

关于 Azure DevOps Pull Request MCP Server

Azure DevOps Pull Request MCP Server 是面向开发者的未完成项目,用于审查 Azure DevOps 拉取请求。它可读取 PR 详情和评论线程,也能在代码位置创建评论线程。

主要功能

  1. 01获取拉取请求详情
  2. 02读取拉取请求评论线程
  3. 03在代码位置创建评论线程
  4. 04按状态筛选线程

适用场景

  1. 01审查拉取请求背景和状态
  2. 02查看已有审查评论
  3. 03在变更代码位置留下评论

MCP 相关

向 MCP 客户端提供 GetPrDetails、GetPrThreads 和 CreatePrThread 工具,用于操作 Azure DevOps 拉取请求。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

暂未收录安装方式

我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。

代码仓库

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

Azure DevOps 拉取请求 MCP 服务

一个专注于 Azure DevOps 拉取请求交互的 Model Context Protocol(MCP)服务实现。此服务使用 ModelContextProtocol NuGet 包构建,提供用于访问和操作 Azure DevOps 拉取请求的工具。

概述

此 MCP 服务是一个学习项目,旨在演示如何通过 Model Context Protocol 集成 Azure DevOps 拉取请求 API。它提供以下工具:

  • 获取拉取请求详情
  • 获取拉取请求线程/评论
  • 在指定代码位置创建新的评论线程

项目状态

免责声明:此项目仍在开发中(WIP)

即将推出的功能
  • 将服务打包为 dotnet 工具,以便更轻松地安装和使用
  • 增强线程支持:
    • 回复现有线程
    • 向现有线程添加评论
    • 提供更完善的线程管理功能

使用示例

PR 审查工作流

若要审查拉取请求,可以使用以下提示词模板:

I want us to review together PR https://dev.azure.com/org/project/_git/repo/pullrequest/123 
First let's have high level review of the PR context and then let's drill down to changed files 
and what was changed there - please share if you have any suggestions or you notice any issues. 
Please verify you are in the local folder of the repo we are doing PR on and switch to the PR 
branch to be able to look at files.

这将触发以下工作流:

  1. 使用 GetPrDetails 工具获取 PR 详情
  2. 分析 PR 的上下文和范围
  3. 在本地仓库中审查已更改的文件
  4. 使用 CreatePrThread 工具提供建议
创建新线程
var input = new AdoCreateThreadInput 
{
    PrUrl = "https://dev.azure.com/org/project/_git/repo/pullrequest/123",
    Content = "Consider using a more descriptive variable name",
    Context = new ThreadContext 
    {
        FilePath = "src/file.cs",
        StartLine = 10,
        EndLine = 10
    }
};
审查会话示例
Prompts you can use during the review:

1. Get PR Overview:
"Let's review PR https://dev.azure.com/org/project/_git/repo/pullrequest/123"

2. Focus on Specific File:
"Can you analyze the changes in src/file.cs?"

3. Add Comment:
"Please add a comment on line 45 of src/file.cs suggesting to use async/await"

4. Get Existing Comments:
"Show me all the review comments in this PR"

这些提示词将使用相应的 MCP 工具:

  • GetPrDetails,用于获取 PR 信息
  • GetPrThreads,用于获取现有评论
  • CreatePrThread,用于添加新评论

要求

  • .NET 8.0 SDK
  • 以下身份验证方式之一:
    1. 推荐:Azure Identity 身份验证

      • 使用 Azure.Identity 中的 DefaultAzureCredential
      • 更安全,支持托管标识及其他 Azure 身份验证方式
      • 无需 PAT
    2. 旧版:个人访问令牌(PAT)

      • 出于安全原因,不建议使用
      • 如果必须使用 PAT,则需要以下范围:
        • Code (Read & Write)
        • Pull Request Threads (Read & Write)

构建和安装 MCP 服务

  1. 克隆此仓库
  2. 构建项目:
dotnet build -c Release
  1. 修改 MCP 设置 JSON 文件,将 MCP 服务添加到 VSCode 设置中。

在配置文件的 mcpServers 对象中添加以下配置:

{
  "mcpServers": {
    "azure-devops-pr": {
      "autoApprove": [],
      "disabled": false,
      "timeout": 60,
      "command": "dotnet",
      "args": ["path/to/bin/Release/net8.0/AzureDevopsPullrequestMcpServer.dll"],
      "env": {
        // Optional: Only needed if using PAT authentication (not recommended)
        // "AZURE_DEVOPS_PAT": "your-pat-token"
        // If AZURE_DEVOPS_PAT is not set, DefaultAzureCredential will be used
      },
      "transportType": "stdio"
    }
  }
}

替换:

  • 将 path/to 替换为已构建 DLL 的实际路径
  • 将 your-pat-token 替换为 Azure DevOps 个人访问令牌(仅在使用 PAT 身份验证时)

注意:如果配置中未提供 AZURE_DEVOPS_PAT,服务将自动使用 DefaultAzureCredential 进行身份验证,这是推荐的方式。

配置选项:

  • timeout:操作超时时间,单位为秒(默认值:60)
  • transportType:通信协议(使用 "stdio")
  • disabled:是否禁用服务
  • autoApprove:无需明确批准的操作列表

服务将显示在“已连接的 MCP 服务”部分,名称为:

azure-devops-pr (dotnet path/to/AzureDevopsPullrequestMcpServer.dll)

可用工具如下:

  • GetPrDetails
  • GetPrThreads
  • CreatePrThread

使用

此应用支持两种身份验证方式:

  1. 使用 Azure Identity(推荐)
# DefaultAzureCredential will be used automatically if PAT is not provided
dotnet run -- --pr-url <azure-devops-pr-url>
  1. 使用个人访问令牌(旧版)
# Not recommended for security reasons
dotnet run -- --pat <your-pat-token> --pr-url <azure-devops-pr-url>

示例:

# Using Azure Identity (Recommended)
dotnet run -- --pr-url https://dev.azure.com/org/project/_git/repo/pullrequest/123

# Using PAT (Not Recommended)
dotnet run -- --pat abc123... --pr-url https://dev.azure.com/org/project/_git/repo/pullrequest/123

可用工具

GetPrDetails

获取特定拉取请求的详情。

输入架构:

{
  "prUrl": "string",
  "includeStatuses": ["string"] | null,
  "excludeStatuses": ["string"] | null
}
GetPrThreads

获取拉取请求中的评论线程。

输入架构:

{
  "prUrl": "string",
  "includeStatuses": ["string"] | null,
  "excludeStatuses": ["string"] | null
}
CreatePrThread

在代码中的指定位置创建新的评论线程。

输入架构:

{
  "prUrl": "string",
  "content": "string",
  "context": {
    "filePath": "string",
    "startLine": number | null,
    "startOffset": number | null,
    "endLine": number | null,
    "endOffset": number | null
  }
}

开发

使用以下技术构建:

  • C#/.NET
  • ModelContextProtocol NuGet 包
  • Azure DevOps REST API

项目结构

  • src/Models/ - 拉取请求和讨论串的数据模型
    • PullRequestDetails.cs - PR 数据结构
    • PullRequestThread.cs - 讨论串和评论模型
    • AdoCreateThreadInput.cs - 讨论串创建输入模型
  • src/Services/
    • AdoPullRequestTool.cs - 核心 API 通信服务
  • src/Utils/
    • IUrlParser.cs - URL 处理工具

贡献

这是一个用于展示 MCP 服务实现的学习项目。欢迎将其用作构建自己的 MCP 服务或扩展其功能的参考。

许可证

MIT License

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。