sonarqube-mcp
MCP server that exposes SonarQube data as AI agent tools, enabling project discovery, quality gates, measures, issues, hotspots, rule explanations, source code, and raw API access.
README
sonarqube-mcp
An MCP server that exposes SonarQube data as AI agent tools.
Dogfooding: this project is checked via its own sonar_analysis_status tool.
Recommended to wire per-project via .mcp.json or opencode.jsonc in the project root — different projects have different SonarQube project keys, URLs, and tokens.
Quick start
{
"mcp": {
"sonarqube": {
"type": "local",
"command": ["npx", "-y", "github:metalralf/sonarqube-mcp"],
"enabled": true,
"environment": {
"SONARQUBE_URL": "http://localhost:9000",
"SONARQUBE_TOKEN": "squ_...",
"SONARQUBE_PROJECT": "my_project"
}
}
}
}
Tools
| Tool | Purpose |
|---|---|
sonar_search_projects |
Discover project keys |
sonar_quality_gate |
Gate pass/fail + failing conditions |
sonar_measures |
Bugs, smells, coverage, ratings, ncloc, dup |
sonar_issues |
Open issues sorted by severity |
sonar_hotspots |
Security hotspots (needs user token) |
sonar_rule |
Explain a rule (why an issue fired) |
sonar_source |
View flagged source lines |
sonar_analysis_status |
Check if a project has been analyzed, with next steps |
sonar_setup_scanner |
Install sonar-scanner as a devDependency (detects pnpm/yarn/npm) |
sonar_run_analysis |
Run sonar-scanner analysis on the project |
sonar_raw |
Escape hatch — any GET endpoint |
For Claude Code or other MCP clients, copy .mcp.json.example to .mcp.json in your project root:
{
"mcp": {
"sonarqube": {
"type": "local",
"command": ["npx", "-y", "github:metalralf/sonarqube-mcp"],
"enabled": true,
"environment": {
"SONARQUBE_URL": "http://localhost:9000",
"SONARQUBE_TOKEN": "squ_...",
"SONARQUBE_PROJECT": "my_project"
}
}
}
}
For opencode, copy opencode.jsonc.example to opencode.jsonc in your project root:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"sonarqube": {
"type": "local",
"command": ["npx", "-y", "github:metalralf/sonarqube-mcp"],
"enabled": true,
"environment": {
"SONARQUBE_URL": "http://localhost:9000",
"SONARQUBE_TOKEN": "squ_...",
"SONARQUBE_PROJECT": "my_project"
}
}
}
}
Setting up SonarQube locally
Spin up with Docker:
docker run -d --name sonarqube -p 9000:9000 sonarqube:community
Open http://localhost:9000, log in with admin/admin, change the password, and generate a user token (squ_...).
Install the scanner (one-time):
pnpm add -D sonar-scanner
Create a sonar-project.properties in your project root with at minimum:
sonar.host.url=http://localhost:9000
sonar.projectKey=my_project
sonar.projectName=My Project
sonar.sources=src
sonar.javascript.lcov.reportPaths=coverage/lcov.info
Then run:
sonar-scanner -Dsonar.token=squ_...
For inline IDE feedback, install SonarLint in your editor and bind it to your local SonarQube instance.
Configuration
| Env var | Description |
|---|---|
SONARQUBE_URL |
SonarQube instance base URL |
SONARQUBE_TOKEN |
Auth token |
SONARQUBE_PROJECT |
Default project key |
SONARQUBE_ORGANIZATION |
SonarCloud org key |
SONARQUBE_AUTH_SCHEME |
basic (default) or bearer |
Agent-driven analysis
The MCP tools can handle the full analysis flow. Ask your agent to:
sonar_setup_scanner— Installs sonar-scanner in your project- Generate coverage — Run
npm run coverage(requires c8 or similar) sonar_run_analysis— Runs the scanner and pushes results to SonarQube
Or manually, copy sonar-project.properties.example to sonar-project.properties and run:
pnpm exec sonar-scanner -Dsonar.token=squ_...
Agent usage guidelines
When acting as an AI agent with these tools available, follow this order:
sonar_analysis_status— first, check if the project has ever been analyzed. IfNOT_FOUNDorNOT_ANALYZED, guide the user to runsonar_setup_scanner+sonar_run_analysis.sonar_quality_gate— check if the project passes its quality gate. IfERROR, inspect failing conditions to understand what's blocking.sonar_measures— get the high-level metrics (coverage, bugs, smells, ratings).sonar_issues— drill into specific issues, filtered by severity or type. Start withCRITICAL/BLOCKER.sonar_rule— when you find an issue you don't understand, look up the rule for a plain-English explanation.sonar_source— view the flagged source code around an issue to understand the context.sonar_hotspots— review security hotspots (only works withsqu_user tokens).
If analysis data is missing or the project isn't even on the server, prompt the user to run:
# Install scanner
npx sonar_setup_scanner or use the tool
# Generate coverage
npx c8 node --test
# Run analysis
npx sonar_run_analysis
Or if the tools are available, let the agent orchestrate the whole flow automatically.
Token tip: If sonar_hotspots returns a 403, tell the user they need a user token (squ_...), not an analysis token. The user token can do everything the analysis token can plus hotspots.
Token types
| Type | Prefix | Hotspots? |
|---|---|---|
| User token | squ_ |
✅ |
| Project analysis | sqp_ |
❌ 403 |
| Global analysis | sqa_ |
❌ 403 |
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。