> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloudthinker.io/llms.txt
> Use this file to discover all available pages before exploring further.

# SonarQube

> Connect SonarQube so agents can explain failed quality gates, triage issues and security hotspots, and find untested code

Connect SonarQube to let CloudThinker agents tell you why a quality gate failed, list the blocker and high-severity issues behind it, review open security hotspots, and find the files with the least test coverage. The connection signs in with one SonarQube **user token** and runs the official SonarSource MCP server, so it works with SonarQube Cloud and self-hosted SonarQube Server.

## Prerequisites

* A SonarQube Cloud organization, or a SonarQube Server or Community Build instance reachable from CloudThinker over HTTPS. For a private instance, see [Reaching private services](https://docs.cloudthinker.io/guide/connections/overview.md#reaching-private-services).
* A SonarQube account for CloudThinker with **Browse** permission on the projects agents should read (see [Required permissions](#required-permissions)).
* The **Admin** role in the CloudThinker workspace, which you need to add connections. See [Roles](https://docs.cloudthinker.io/guide/security/roles.md).

## Setup

> [tab] SonarQube Cloud
>
> **1. Generate a user token**
>
> Sign in to [SonarQube Cloud](https://sonarcloud.io) as the account CloudThinker will use. Go to **My Account → Security**, enter a name such as `cloudthinker`, set an expiry, and click **Generate Token**.
>
> Copy the token. SonarQube shows it only once.
>
> **2. Find your organization key**
>
> Open your organization. The key is the last part of the URL: `https://sonarcloud.io/organizations/<org-key>`.
>
> **3. Grant Browse on the projects**
>
> For each project agents should read, open the project, go to **Administration → Permissions**, and give the CloudThinker account **Browse**. Without it, the verify prompt comes back empty.
>
> **4. Add the connection in CloudThinker**
>
> In the sidebar, click **More → Workspace settings → Connections**, stay on the **Builtin Connections** tab, and select **SonarQube**. Fill in:
>
> * **SONARQUBE\_TOKEN**: the token you copied
> * **SONARQUBE\_DEPLOYMENT\_TYPE**: **SonarQube Cloud**
> * **SONARQUBE\_ORG**: your organization key
>
> Click **Connect**.
>
> **Success state:** the **Connect SonarQube** dialog closes without an error. Run the verify prompt below.

> [tab] SonarQube Server
>
> **1. Generate a user token**
>
> Sign in to your SonarQube instance as the account CloudThinker will use. Go to **My Account → Security**, enter a name such as `cloudthinker`, choose the **User Token** type, set an expiry, and click **Generate**.
>
> Copy the token. SonarQube shows it only once.
>
> **2. Grant Browse on the projects**
>
> For each project agents should read, open the project, go to **Project Settings → Permissions**, and give the CloudThinker account **Browse**. A permission template does the same for many projects at once. Without it, the verify prompt comes back empty.
>
> **3. Add the connection in CloudThinker**
>
> In the sidebar, click **More → Workspace settings → Connections**, stay on the **Builtin Connections** tab, and select **SonarQube**. Fill in:
>
> * **SONARQUBE\_TOKEN**: the token you copied
> * **SONARQUBE\_DEPLOYMENT\_TYPE**: **SonarQube Server**
> * **SONARQUBE\_URL**: your instance address, such as `https://sonarqube.example.com`
>
> Click **Connect**.
>
> **Success state:** the **Connect SonarQube** dialog closes without an error. Run the verify prompt below.

## Connection details

The form shows **SONARQUBE\_ORG** or **SONARQUBE\_URL** depending on the deployment type you pick. The **SonarQube Cloud** option connects to `sonarcloud.io`. There's no region field.

| Field | Description | Example |
| - | - | - |
| **SONARQUBE\_TOKEN** | User token for the CloudThinker account | `squ_...` |
| **SONARQUBE\_DEPLOYMENT\_TYPE** | **SonarQube Cloud** (default) for a Cloud organization, or **SonarQube Server** for a self-hosted Server or Community Build instance | SonarQube Cloud |
| **SONARQUBE\_ORG** | Organization key. Cloud only | `my-org` |
| **SONARQUBE\_URL** | Instance address, HTTPS. Server only | `https://sonarqube.example.com` |

## Required permissions

A user token acts with the permissions of the account that created it. Grant that account project permissions in SonarQube, per project or through a permission template.

| Goal | SonarQube permission |
| - | - |
| Read projects, quality gates, issues, measures, coverage, duplications, and hotspots | **Browse** |
| Change an issue's status, such as marking it a false positive | **Administer Issues** |
| Review a security hotspot and set its status | **Administer Security Hotspots** |

> [!TIP]
>
> Start with **Browse** only. Agents can explain every gate and issue with it. Add the two Administer permissions only on projects where you want agents to propose status changes.

## Agent capabilities

| Capability | What agents can do | Approval |
| - | - | - |
| **Discovery** | List projects with their quality gate status (**OK** or **ERROR**) and issue counts by severity | No |
| **Quality gates** | Check a project's or pull request's gate status and the conditions that failed | No |
| **Issues** | Search issues by project, pull request, severity, and status, and show the rule behind an issue with its fix guidance | No |
| **Security hotspots** | List hotspots to review and show the code and risk behind each one | No |
| **Measures, coverage, and duplication** | Read lines of code, coverage, bugs, vulnerabilities, code smells, and duplicated lines, and find files under a coverage threshold | No |
| **Change status** | Change an issue's status or review a hotspot | Goes through Approvals |

Severity names follow your instance's mode. Multi-Quality Rule mode reports **BLOCKER**, **HIGH**, **MEDIUM**, **LOW**, and **INFO**. Standard Experience reports **BLOCKER**, **CRITICAL**, **MAJOR**, **MINOR**, and **INFO**.

Every change an agent makes goes through your workspace's [Approvals](https://docs.cloudthinker.io/guide/approvals/overview.md) first. On the default **Auto · Rules + AI · Ask me** mode, AI judgment can let a safe change run without asking — and an Allow Rule can too, once CloudThinker turns on [Rule enforcement](https://docs.cloudthinker.io/guide/approvals/rules.md#troubleshooting) for your workspace. Choose **Manual** to approve every change yourself.

A rejected request isn't retried. To decide each status change yourself, such as marking an issue as a false positive, choose **Manual** so a person approves every change. Once CloudThinker turns on [Rule enforcement](https://docs.cloudthinker.io/guide/approvals/rules.md#troubleshooting) for your workspace, an **Ask first** [Rule](https://docs.cloudthinker.io/guide/approvals/rules.md) can narrow that to the SonarQube connection alone. Some tools depend on your SonarQube edition: dependency risks need an Advanced Security license, and system health tools work only on SonarQube Server.

Agents report each project's numbers as they are today. SonarQube returns current measures, so agents won't claim a trend unless you ask them to compare branches or pull requests.

### Verify the connection

```text theme={null}
List my SonarQube projects with their quality gate status and issue counts by severity
```

Expect a table of project keys and names, a gate status of **OK** or **ERROR** for each, and issue counts by severity, such as **BLOCKER**.

### Example prompts

```text theme={null}
Why did the quality gate fail on payments-api? List the failed conditions and the blocker issues behind them
Show the security hotspots still to review in payments-api, highest risk first
Which files in payments-api have under 50% coverage?
```

Use the real project key. Agents look keys up from the project list and won't guess one.

## Troubleshooting

> [accordion] Requests return 401
>
> The token is wrong, expired, or revoked. Generate a new user token, edit the connection, and paste it into **SONARQUBE\_TOKEN**.

> [accordion] Connect fails on SonarQube Server
>
> CloudThinker can't reach **SONARQUBE\_URL**. Check that the address is HTTPS and reachable from the internet, not `localhost` or a private hostname, and that the SonarQube service is running.

> [accordion] No projects come back (Cloud)
>
> **SONARQUBE\_ORG** is wrong, or the token's account isn't a member of that organization. Copy the key from the organization URL and confirm membership.

> [accordion] Some projects are missing
>
> The token's account lacks **Browse** on them. Grant **Browse** on those projects in SonarQube. No need to reconnect; permissions apply on the next request.

> [accordion] Changing a status returns 403
>
> The account lacks **Administer Issues** or **Administer Security Hotspots** on that project. Grant the permission in SonarQube, then ask again.

> [accordion] Dependency risks or system health aren't available
>
> Your edition doesn't include those tools. Dependency risks need an Advanced Security license, and system health tools exist only on SonarQube Server.

## Security

* **Least privilege** — grant only the permissions the agents need for your use case; start read-only and widen later.
* **Read-only by default** — use read-only credentials unless you want agents to make changes through this connection.
* **Rotate credentials** — rotate keys and tokens on your normal schedule; CloudThinker picks up the new value when you update the connection.
* **Revoke on offboarding** — remove the credential at the provider when you delete a connection or a teammate leaves.

- **Use a user token**: on SonarQube Server, pick the **User Token** type, not a Global Analysis Token, so access follows one account's project permissions.
- **Set an expiry**: give the token an expiry date and rotate it before it lapses.

## Related

> [card] [Review](https://docs.cloudthinker.io/guide/code-review/overview.md)
>
> Get AI review comments on every merge request and pull request.

> [card] [Semgrep connection](https://docs.cloudthinker.io/guide/connections/semgrep.md)
>
> Let agents triage static analysis findings from Semgrep.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.