Read-only MCP server for self-hosted SonarQube Community Build 26.4+: lets AI agents (Claude Code, Cursor, Copilot) read issues, security hotspots, rules and code snippets to fix findings locally
Sonar MCP Server
以下摘录自该仓库的 README(片段) · 在 GitHub 读完整 README →
A local MCP server providing read-only access to a SonarQube Community Build (26.4+) instance via its web-api.
It lets AI agents (Claude Code, Cursor, VS Code Copilot, etc.) fetch a project's issue list, the files and locations where they occur, rule descriptions, source-code snippets around issues, and Security Hotspots.
Typical scenario: "find and fix Sonar issues in such-and-such project" — the LLM calls listIssues, optionally getRule and getIssueSnippets, and edits files locally.
Why this server
There is an official SonarSource MCP server, but it targets SonarQube **10+** (and SonarCloud) and assumes a cloud-style deployment. This server is built for self-hosted **SonarQube Community Build 26.4+** installations that expose the classic /api/ web-api. It supports both Standard Experience and MQR mode, handling per-software-quality impacts when the instance runs in MQR mode.
It is also intentionally narrower in scope:
- **Read-only by design.** The server never creates, updates, or deletes anything in SonarQube — no marking issues as false-positive, no editing comments, no admin endpoints. The token's write permissions in SonarQube are irrelevant because the server never calls those endpoints.
- **Curated tool set.** Instead of mirroring the SonarQube API surface, the server exposes a small, focused set of tools (13 in total) chosen for a single workflow: *let an AI agent read Sonar's findings and fix the code based on them*. Listing components, issues and hotspots, drilling into a single finding, fetching the rule explanation, and pulling the source-code snippet around the location — and that's it. Anything outside this "diagnose -> fix the code locally" loop is deliberately left out to keep the tool list small and the agent's choices unambiguous.
In short: a focused, read-only bridge from a self-hosted SonarQube Community Build to an AI coding agent.
Quick start
1. Install JDK 25+.
2. Download sonar-mcp-server.jar from the latest release,
or build it yourself: ./gradlew bootJar (see Build). A Docker image is
published as well.
3. Get your SonarQube URL and user token (see Configuration).
4. Add the JAR to your client's MCP configuration (see Connecting to an AI client).
For Claude Code that is one command:
Architecture
The server only supports the stdio transport.
The AI client spawns the server as a child process; communication uses the MCP protocol over stdin/stdout.
The server does not open any HTTP port and accepts no incoming connections.
Tools
The server exports **13 read-only MCP tools**.
Projects
| Tool | Description |
|---|---|
| listProjects | List of SonarQube projects. Parameters: query (name substring), limit, offset. Returns key, name, qualifier. |
| listComponents | Search/browse components inside a project using Sonar's component tree. Parameters: projectKey, query, qualifiers, branch / pullRequest, limit, offset. Returns opaque component key values plus path, qualifier, name, language, and project. Use returned key values unchanged as listIssues.componentKeys; do not pass Java package names directly as component keys. |
| getProject | Project overview: header info (name, qualifier, visibility, description, version, last analysis date), quality gate status with failed conditions, and curated metrics (ncloc, bugs, vulnerabilities, security hotspots, code smells, coverage, duplicated lines density, technical debt in minutes, alert status). Parameters: projectKey, branch (opt.), pullRequest (opt.). |
| listProjectBranches | List of branches analysed for the project. Each entry: name, isMain, type (LONG/SHORT/BRANCH), excludedFromPurge, analysisDate, qualityGateStatus, plus bugs/vulnerabilities/codeSmells counts. No pagination — Sonar returns all branches at once. |
| listProjectPullRequests | List of PR analyses for the project. Each entry: PR key (use as pullRequest= elsewhere), title, branch (head), base, url, analysisDate, qualityGateStatus, plus bugs/vulnerabilities/codeSmells counts. Empty list if the Sonar install has no DevOps integration. |
Issues
| Tool | Description |
|---|---|
| listIssues | Flat list of issues for a project. Parameters: projectKey (required unless defaulted), componentPathPrefix (opt.) — a single subtree-or-file filter relative to the Sonar project root (e.g. bc-doc/src/main/java/ru/foo or bc-doc/src/main/java/ru/foo/Bar.java); convert Java/Kotlin package dots to slashes; honours directory boundaries (bc-doc/src does not match bc-doc/srcExtra). Plus severities, types, statuses, rules, branch / pullRequest (mutually exclusive), resolved, limit, offset. By default returns only open issues (resolved=false, statuses OPEN/CONFIRMED/REOPENED). Each item contains the rule, severity, type, status, file path, line, primary textRange, and secondary flows for cross-file rules. When componentPathPrefix is used, the server scans the project and filters client-side; the scan is capped (default 10000 issues) — if the cap is hit, pathPrefixTruncated=true in the response. |