SonarQube MCP Server
A read-only MCP server that provides AI assistants with structured access to SonarQube projects, issues, metrics, and rules. It enables safe analysis of code quality and security findings through a set of validated, safety-first tools.
README
SonarQube MCP Server
A read-only Model Context Protocol (MCP) server that gives AI assistants structured access to SonarQube — issues, metrics, rules, and projects.
Features
- 6 read-only tools covering the full SonarQube quality workflow
- Safe by design — no mutations, every tool returns a consistent
{"ok": ...}envelope - Input validation before any API call (severities, types, statuses)
- Structured errors with machine-readable
error_codefields - Works with SonarQube Community, Developer, and Enterprise editions
Requirements
- Python 3.10+
- A running SonarQube instance
- A SonarQube user token (
squ_...)
Installation
pip install sonarqube-mcp-server
Or install from source:
git clone <repo>
cd sonarqube-mcp
pip install -e .
Quick Start
SONARQUBE_URL=http://localhost:9000 \
SONARQUBE_TOKEN=squ_xxxxxxxxxxxx \
sonarqube-mcp-server
Or with python -m:
python -m sonarqube_mcp
Configuration
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
SONARQUBE_URL |
No | http://localhost:9000 |
Base URL of your SonarQube instance |
SONARQUBE_TOKEN |
Yes | — | User token for authentication |
SONARQUBE_REQUEST_TIMEOUT_SEC |
No | 30 |
HTTP request timeout in seconds |
Copy .env.example to .env and fill in your values:
cp .env.example .env
Generating a Token
In SonarQube: My Account → Security → Generate Tokens. A user token (squ_...) with Browse permission on the target projects is sufficient for all read-only operations.
MCP Client Integration
Claude Code
Add to your Claude Code MCP settings (~/.claude/claude_code_config.json):
{
"mcpServers": {
"sonarqube": {
"command": "sonarqube-mcp-server",
"env": {
"SONARQUBE_URL": "http://localhost:9000",
"SONARQUBE_TOKEN": "squ_xxxxxxxxxxxx"
}
}
}
}
Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"sonarqube": {
"command": "sonarqube-mcp-server",
"env": {
"SONARQUBE_URL": "http://localhost:9000",
"SONARQUBE_TOKEN": "squ_xxxxxxxxxxxx"
}
}
}
}
Tools
All tools are read-only (readOnlyHint: true, destructiveHint: false).
check_status
Verify connectivity and retrieve server version.
{}
Response:
{
"ok": true,
"server_url": "http://localhost:9000",
"status": "UP",
"version": "10.4.1"
}
list_projects
List or search SonarQube projects with pagination.
| Parameter | Type | Default | Description |
|---|---|---|---|
query |
string |
— | Filter by project name or key |
page |
integer |
1 |
Page number (1-indexed) |
page_size |
integer |
20 |
Results per page (1–500) |
Response:
{
"ok": true,
"total": 42,
"page": 1,
"page_size": 20,
"projects": [
{"key": "my-app", "name": "My Application", "qualifier": "TRK"}
]
}
search_issues
Search issues across all projects or scoped to one project, with rich filtering.
| Parameter | Type | Default | Description |
|---|---|---|---|
project_key |
string |
— | Scope to a specific project |
severities |
string |
— | CSV: INFO, MINOR, MAJOR, CRITICAL, BLOCKER |
types |
string |
— | CSV: CODE_SMELL, BUG, VULNERABILITY, SECURITY_HOTSPOT |
statuses |
string |
— | CSV: OPEN, CONFIRMED, REOPENED, RESOLVED, CLOSED |
tags |
string |
— | CSV of tag names |
assigned |
boolean |
— | true = assigned only, false = unassigned only |
page |
integer |
1 |
Page number |
page_size |
integer |
20 |
Results per page (1–500) |
Example — find all open blockers in a project:
{
"project_key": "my-app",
"severities": "BLOCKER,CRITICAL",
"statuses": "OPEN"
}
get_issue
Get full detail for a single issue by key, including text range, effort, assignee, comments, and data-flow information.
| Parameter | Type | Description |
|---|---|---|
issue_key |
string |
Issue key (e.g. AXy1k2m3n4o5p6q7r8) |
get_project_metrics
Retrieve the quality dashboard for a project. Returns a standard set of metrics by default, or a custom selection.
| Parameter | Type | Default | Description |
|---|---|---|---|
project_key |
string |
— | Required. Project key |
metric_keys |
string |
See below | CSV of metric keys |
Default metrics: bugs, vulnerabilities, code_smells, security_hotspots, coverage, duplicated_lines_density, ncloc, sqale_index, reliability_rating, security_rating, sqale_rating, alert_status, quality_gate_details
Response:
{
"ok": true,
"project_key": "my-app",
"project_name": "My Application",
"metrics": {
"bugs": "3",
"coverage": "78.4",
"alert_status": "OK"
}
}
get_rule
Retrieve the description and metadata for a SonarQube rule.
| Parameter | Type | Description |
|---|---|---|
rule_key |
string |
Rule key (e.g. python:S1192, java:S106) |
Error Handling
All tools return a consistent envelope. On failure:
{
"ok": false,
"error_code": "auth_error",
"message": "Authentication failed. Check SONARQUBE_TOKEN.",
"details": {}
}
error_code |
Cause |
|---|---|
auth_error |
Invalid or missing token (HTTP 401) |
forbidden |
Token lacks permissions (HTTP 403) |
not_found |
Project, issue, or rule does not exist (HTTP 404) |
connection_error |
Cannot reach the SonarQube instance |
timeout |
Request exceeded SONARQUBE_REQUEST_TIMEOUT_SEC |
invalid_input |
Bad parameter value (e.g. unknown severity) |
api_error |
Other non-2xx SonarQube response |
internal_error |
Unexpected server-side error |
Development
Setup
pip install -e ".[dev]"
Running Tests
pytest
Project Layout
src/sonarqube_mcp/
├── server.py # FastMCP server, tool definitions, main()
├── sonarqube_client.py # httpx.Client wrapper for SonarQube REST API
├── settings.py # Frozen dataclass + env var loading
├── errors.py # SonarQubeError + error_response()
├── __main__.py # python -m sonarqube_mcp entrypoint
└── __init__.py
tests/
├── conftest.py
├── test_server.py
├── test_client.py
├── test_settings.py
└── test_errors.py
Architecture Notes
create_server()is a factory that capturessettingsandclientin closure scope — makes unit testing straightforward by injecting a pre-builtSonarQubeSettings.@_safe_toolwraps every tool so it never raises — exceptions are caught and returned as structured error envelopes._clamp()keepspage_sizewithin SonarQube's supported API limits (1–500).- Settings use a
frozen=Truedataclass — immutable after load, safe to share across tool closures.
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。