使用说明
mcp声纳
MCP服务器,用于包装SonarQube Web API以进行问题检索。连接到任何SonarQube实例并公开 sonar_issues, sonar_rules,以及 sonar_list_microservices 基于模型上下文协议(stdio传输)的工具。
服务器是为monorepos设计的:您可以通过微服务的人性化名称来引用它(例如。 "integration gateway"),服务器将其解析为monorepo中匹配的顶级文件夹。然后,通过在文件夹名称前加前缀来构建SonarQube项目密钥,例如folder ms_antifraud 默认前缀变为 NU0188001_Biometria_Facial_MR_ms_antifraud.
先决条件
- Node.js 18+
- 具有访问令牌的SonarQube实例
- 顶级文件夹名称与SonarQube项目密钥匹配的monorepo
设置
npm install
npm run build
环境变量
| 变量 | 必填 | 描述 |
|---|---|---|
SONAR_URL |
是 | SonarQube实例的基本URL(例如。 https://sonar.example.com) |
SONAR_TOKEN |
是 | SonarQube身份验证令牌 |
MONOREPO_ROOT |
否 | 用于发现微服务的monorepo根路径。默认为 process.cwd() (启动服务器的目录)。 |
SONAR_PROJECT_KEY_PREFIX |
否 | 在解析的文件夹名称前添加前缀(带下划线)以形成SonarQube项目密钥。默认为 NU0188001_Biometria_Facial_MR。设置为空字符串以按原样使用文件夹名称 |
跑步
SONAR_URL=https://sonar.example.com SONAR_TOKEN=squ_xxx npm start
MCP客户端配置
添加到MCP客户端配置(例如Claude Desktop claude_desktop_config.json):
{
"mcpServers": {
"sonar": {
"command": "node",
"args": ["/absolute/path/to/mcp-sonar/build/index.js"],
"env": {
"SONAR_URL": "https://sonar.example.com",
"SONAR_TOKEN": "squ_xxx",
"MONOREPO_ROOT": "/absolute/path/to/monorepo"
}
}
}
}
可用工具
sonar_issues
在SonarQube issues中搜索monorepo中的微服务。这 microservice 参数与顶级文件夹名称进行模糊匹配;解析后的文件夹名称前缀为 SONAR_PROJECT_KEY_PREFIX 形成SonarQube项目密钥。
参数:
| 参数 | 类型 | 说明 |
|---|---|---|
microservice |
string | 人性化的微服务名称(例如。 "integration gateway" 解析到文件夹 ms_integration_gateway) |
branch |
string | 分支名称筛选器 |
severities |
string | 逗号分隔: BLOCKER,CRITICAL,MAJOR,MINOR,INFO |
types |
string | 逗号分隔: BUG,VULNERABILITY,CODE_SMELL |
statuses |
string | 逗号分隔: OPEN,CONFIRMED,REOPENED |
page |
number | 页码(默认1) |
pageSize |
number | 每页最多500个结果(默认100个) |
sonar_list_microservices
列出在下发现的微服务(顶级文件夹) MONOREPO_ROOT。当模糊匹配不明确或失败时有用。
sonar_rules
搜索SonarQube规则(编码标准)。看 src/tools/rules.ts 查看完整的参数列表。
