# Integrate with SonarQube for IDE

The SonarQube MCP Server can integrate with [SonarQube for IDE](https://www.sonarsource.com/products/sonarqube/ide/) to further enhance your development workflow, providing better code analysis and insights directly within your IDE.

When using SonarQube for IDE, the `SONARQUBE_IDE_PORT` environment variable should be set with the correct port number. See the list of [#base-variables](https://docs.sonarsource.com/sonarqube-mcp-server/build-and-configure/environment-variables#base-variables "mention") 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. See the [Cursor #Setup the SonarQube MCP Server](https://app.gitbook.com/s/6LPRABg3ubAJhpfR5K0Y/ai-capabilities/ides/cursor#setup-the-sonarqube-mcp-server "mention") article in our VS Code documentation for instructions.

Here are some example configurations; note that you'll need to specify the `SONARQUBE_IDE_PORT`:

{% tabs %}
{% tab title="SONARQUBE CLOUD" %}
{% hint style="info" %}
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.
{% endhint %}

```bash
{
  "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>"
    }
  }
}
```

{% hint style="warning" %}
*User tokens* are required when setting up connected mode or an MCP Server between SonarQube (Server, Cloud) and SonarQube for IDE. Note that the binding will not function properly if *project tokens*, *global tokens*, or *scoped organization tokens* are used during the setup process.
{% endhint %}

{% hint style="success" %}
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 US instance. See the [#common-variables](https://docs.sonarsource.com/sonarqube-mcp-server/build-and-configure/environment-variables#common-variables "mention") article which explains when to use these variables.
{% endhint %}
{% endtab %}

{% tab title="SONARQUBE SERVER" %}
Use this code sample when using Docker to configure your MCP server for integrating with SonarQube Server or SonarQube Community Build.

{% hint style="info" %}
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.
{% endhint %}

```bash
{
  "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>"
    }
  }
}
```

{% hint style="warning" %}
*User tokens* are required when setting up connected mode or an MCP Server between SonarQube (Server, Cloud) and SonarQube for IDE. Note that the binding will not function properly if *project tokens*, *global tokens*, or *scoped organization tokens* are used during the setup process.
{% endhint %}
{% endtab %}
{% endtabs %}

{% hint style="info" %}
When running the MCP server in a container on Linux, the container cannot access the SonarQube for IDE embedded server running on localhost. To allow the container to connect to the SonarQube for IDE server, add the `--network=host` option to your container run command.
{% endhint %}

## MCP Server setup in your IDE

For detailed quickstart instructions to set up the SonarQube MCP Server with the most popular AI agents, check the list of guides in the [#set-up-in-your-ide](https://docs.sonarsource.com/sonarqube-mcp-server/quickstart-guide#set-up-in-your-ide "mention") section for your IDE and CLI.


---

# 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/sonarqube-mcp-server/using/integration.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.
