# Integrate with SonarQube for IDE

Integrate the SonarQube MCP Server with [SonarQube for IDE](https://www.sonarsource.com/products/sonarqube/ide/) to get code analysis and insights directly in your IDE.

> **Note:** Although the examples below use `docker`, any OCI-compatible container runtime works (for example, Podman, nerdctl, etc). Simply replace `docker` with commands specific to your preferred tool.

When using SonarQube for IDE, set the `SONARQUBE_IDE_PORT` environment variable to the correct port number. See the list of [base variables](/agent-centric-development-cycle/developer-tools/mcp-server/reference/environment-variables.md#base-variables) for more information.

SonarQube for VS Code includes a Quick Install button when running an agent-enabled IDE, which automatically sets the correct port configuration.

The following examples show configurations for SonarQube Cloud and SonarQube Server. Specify `SONARQUBE_IDE_PORT` in each.

> **Warning:** *User tokens* are required when setting up connected mode or an MCP Server between SonarQube Server and SonarQube for IDE. Binding won't work if *project tokens*, *global tokens*, or *scoped organization tokens* are used during setup.

### SonarQube Cloud

```json
{
  "sonarqube": {
    "command": "docker",
    "args": [
      "run",
      "-i",
      "--rm",
      "--init",
      "--pull=always",
      "-e",
      "SONARQUBE_TOKEN",
      "-e",
      "SONARQUBE_ORG",
      "-e",
      "SONARQUBE_IDE_PORT",
      "mcp/sonarqube"
    ],
    "env": {
      "SONARQUBE_TOKEN": "<YourSonarQubeUserToken>",
      "SONARQUBE_ORG": "<YourSonarQubeOrganization>",
      "SONARQUBE_IDE_PORT": "<Your-IDE-Port>"
    }
  }
}
```

> **Note:** SONARQUBE\_URL should be defined as `https://sonarqube.us` each time you use a SonarQube Cloud configuration (`SONARQUBE_TOKEN` + `SONARQUBE_ORG`) and want to connect to a US-region instance. See the [Connecting to SonarQube Cloud in the US region](/agent-centric-development-cycle/developer-tools/mcp-server/setup/environment-considerations.md#connecting-to-sonarqube-cloud-in-the-us-region) section for details.

### SonarQube Server

Use this code sample when using Docker to configure your MCP server for integrating with SonarQube Server or SonarQube Community Build.

```json
{
  "sonarqube": {
    "command": "docker",
    "args": [
      "run",
      "-i",
      "--rm",
      "--init",
      "--pull=always",
      "-e",
      "SONARQUBE_TOKEN",
      "-e",
      "SONARQUBE_URL",
      "-e",
      "SONARQUBE_IDE_PORT",
      "mcp/sonarqube"
    ],
    "env": {
      "SONARQUBE_TOKEN": "<YourSonarQubeUserToken>",
      "SONARQUBE_URL": "<YourSonarQubeURL>",
      "SONARQUBE_IDE_PORT": "<64120-64130>"
    }
  }
}
```

> **Note:** On Linux, containers can't access the SonarQube for IDE embedded server on localhost. Add the `--network=host` option to your container run command to fix this.

## MCP Server setup in your IDE

For detailed quickstart instructions to set up the SonarQube MCP Server with the most popular AI agents, see the [IDE/CLI quickstart guides](/agent-centric-development-cycle/developer-tools/mcp-server/setup/quickstart-guides.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sonarsource.com/agent-centric-development-cycle/developer-tools/mcp-server/setup/integrate-with-sonarqube-for-ide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
