Token导航 LogoToken导航TokenDH.com
MCP Sonarqube logo
开发工具未说明官方级别未说明来源级核验

MCP Sonarqube

MCP Server

一个基于模型上下文协议(MCP)的服务,允许AI助手与SonarQube交互,查询项目、检查问题、审核拉取请求、定位重复代码并检查质量门禁,所有操作通过单一HTTP传输完成。

工具数

12

提示词数

0

GitHub Stars

1

资源数

0
代码审查C#ClaudeClaude DesktopClaude

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

viamus

提供方

viamus

最后核验

2026/5/17 20:20

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

MCP SonarQube服务器

![.NET](https://dotnet.microsoft.com/) ![License](LICENSE) ![MCP](https://modelcontextprotocol.io/) ![Tools](#available-tools) ![Tests](#development)

A. 模型上下文协议(MCP) 该服务器允许人工智能助手与SonarQube通信——查询项目、深入问题、审计拉取请求、定位重复和检查质量门——所有这些都是通过一个HTTP传输完成的。

亮点

  • 一次通话中的公关分析analyze_pull_request 并行聚合质量门、新代码度量、问题和安全热点
  • 找到有问题的文件get_component_tree_measures 按文件/目录分解聚合指标,以便代理知道在哪里修复
  • 精确复制块get_duplications 返回行范围和配对文件
  • 清除错误 --声纳误差体(errors[].msg)通过每个包装器传播

______________________________________________________________________

快速开始

# 1. Clone the repository
git clone https://github.com/viamus/mcp-sonarqube.git
cd mcp-sonarqube

# 2. Configure credentials
cp .env.example .env
# Edit .env with your SonarQube URL and token

# 3. Run the server
docker compose up -d

______________________________________________________________________

先决条件

要求版本目的
.NET SDK10.0+构建并运行
Docker最新容器部署(可选)
SonarQube实例9.x+API访问

必修的:

  • SonarQube基本URL(例如。, https://sonarqube.example.com)
  • SonarQube用户令牌(生成位置:您的SonarQube>我的账户>安全>令牌)

______________________________________________________________________

可用工具

13个MCP工具,按领域分组:

领域工具目的
拉取请求analyze_pull_request聚合PR视图——质量门、新代码度量、问题、安全热点(4个并行调用)
项目search_projects按名称或关键字搜索项目
get_project_status质量门状态+项目关键措施
问题search_issues使用过滤器搜索问题;支持 pullRequest 范围界定
措施get_measures获取组件的指标
get_component_tree_measures按文件/目录分解度量值——查找违规文件
重复get_duplications精确的复制块(行范围+成对文件)
质量门list_quality_gates列出所有闸门及其状态
热点search_hotspots搜索安全热点
get_hotspot热点详细信息
规则search_rules按语言/严重性/标签搜索编码规则
系统get_healthSonarQube实例的运行状况

对于每个工具包装的底层SonarQube端点,请参阅 API 参考 在......下面

______________________________________________________________________

运行选项

选项1:Docker Compose(推荐)

docker compose up -d

服务器将在以下时间可用 http://localhost:8082.

选项2:。NET-CLI

dotnet run --project src/Viamus.Sonarqube.Mcp.Server

服务器将在以下时间可用 http://localhost:5100.

选项3:独立可执行文件

dotnet publish src/Viamus.Sonarqube.Mcp.Server -c Release -o ./publish
./publish/Viamus.Sonarqube.Mcp.Server

______________________________________________________________________

客户端配置

克劳德桌面版

添加到您的Claude Desktop配置(claude_desktop_config.json):

{
  "mcpServers": {
    "sonarqube": {
      "url": "http://localhost:8082"
    }
  }
}

克劳德代码

claude mcp add sonarqube --scope user --transport http http://localhost:8082

______________________________________________________________________

使用示例

端到端审核拉取请求

Analyze pull request 1234 on the "my-app" project. Did it break the gate?
If yes, find which files concentrate the new duplicated lines and show me
the exact duplication blocks.
在引擎盖下,代理通常会连锁 analyze_pull_requestget_component_tree_measures (按排序 new_duplicated_lines) → get_duplications 最糟糕的文件。

搜索项目

Search for all projects containing "backend" in my SonarQube instance.

检查工程质量

What is the quality gate status for the "my-app" project? Show me the coverage and bug count.

查找关键问题

Search for all CRITICAL and BLOCKER severity issues in the "my-app" project.

查看安全热点

Show me all security hotspots that need review in the "my-app" project.

搜索编码规则

Find all MAJOR severity rules for C# language.

检查系统健康状况

Is my SonarQube instance healthy?

______________________________________________________________________

配置

环境变量

变量必填描述
SONARQUBE_BASE_URLSonarQube实例URL
SONARQUBE_TOKENSonarQube用户令牌
SERVER_REQUIRE_API_KEY启用API密钥身份验证(默认值: false)
SERVER_API_KEY没有用于服务器访问的neneneba API密钥

应用程序参数

{
  "SonarQube": {
    "BaseUrl": "https://your-sonarqube-instance.com",
    "Token": "your-token-here"
  },
  "ServerSecurity": {
    "RequireApiKey": false,
    "ApiKey": ""
  }
}

用户秘密(开发)

cd src/Viamus.Sonarqube.Mcp.Server
dotnet user-secrets set "SonarQube:BaseUrl" "https://your-sonarqube-instance.com"
dotnet user-secrets set "SonarQube:Token" "your-token-here"

______________________________________________________________________

故障排除

常见问题

连接被拒绝

  • 验证SonarQube基本URL是否正确且可访问
  • 检查服务器是否正在运行: curl http://localhost:8082/health

401未经SonarQube授权

  • 验证您的令牌是否有效且未过期
  • 在以下位置生成新代币:您的SonarQube>我的账户>安全>代币

未找到项目

  • 确保您的令牌具有足够的权限
  • 验证SonarQube实例中是否存在该项目

Docker容器未启动

  • 检查日志: docker compose logs mcp-sonarqube
  • 验证 .env 文件存在并且包含有效凭据

______________________________________________________________________

项目结构

mcp-sonarqube/
├── src/Viamus.Sonarqube.Mcp.Server/
│   ├── Configuration/          # Settings classes
│   ├── Middleware/              # API key authentication
│   ├── Models/                  # SonarQube API DTOs
│   ├── Services/                # HTTP client for SonarQube API
│   ├── Tools/                   # MCP tool implementations (13 tools)
│   └── Program.cs               # Entry point
├── tests/Viamus.Sonarqube.Mcp.Server.Tests/
│   ├── Configuration/           # Settings and middleware tests
│   ├── Models/                  # Serialization tests
│   └── Tools/                   # Tool behavior tests
├── docker-compose.yml
└── Solution.slnx

______________________________________________________________________

API 参考

使用的SonarQube API端点

端点工具
/api/projects/searchsearch_projects
/api/qualitygates/project_statusget_project_status, analyze_pull_request
/api/qualitygates/listlist_quality_gates
/api/measures/componentget_project_status, get_measures, analyze_pull_request
/api/measures/component_treeget_component_tree_measures
/api/duplications/showget_duplications
/api/issues/searchsearch_issues, analyze_pull_request
/api/hotspots/searchsearch_hotspots, analyze_pull_request
/api/hotspots/showget_hotspot
/api/rules/searchsearch_rules
/api/system/healthget_health

______________________________________________________________________

发展

建筑

dotnet build Solution.slnx

测试

dotnet test Solution.slnx

添加新工具

贡献.md 详细说明。

______________________________________________________________________

许可证

此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。

目录标签

目录标签

代码审查C#Claude代码质量分析本地部署静态代码分析代码重复检测质量门禁检查

支持客户端

Claude DesktopClaude

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

api-key

工具数量(toolCount,工具数)

12

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明api-key部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP