sonarqube-mcp

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.

Category
访问服务器

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:

  1. sonar_setup_scanner — Installs sonar-scanner in your project
  2. Generate coverage — Run npm run coverage (requires c8 or similar)
  3. 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:

  1. sonar_analysis_status — first, check if the project has ever been analyzed. If NOT_FOUND or NOT_ANALYZED, guide the user to run sonar_setup_scanner + sonar_run_analysis.
  2. sonar_quality_gate — check if the project passes its quality gate. If ERROR, inspect failing conditions to understand what's blocking.
  3. sonar_measures — get the high-level metrics (coverage, bugs, smells, ratings).
  4. sonar_issues — drill into specific issues, filtered by severity or type. Start with CRITICAL/BLOCKER.
  5. sonar_rule — when you find an issue you don't understand, look up the rule for a plain-English explanation.
  6. sonar_source — view the flagged source code around an issue to understand the context.
  7. sonar_hotspots — review security hotspots (only works with squ_ 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

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选