# Build

As described in the [IDE/CLI quickstart guides](/agent-centric-development-cycle/developer-tools/mcp-server/setup/quickstart-guides.md), the easiest way to launch the SonarQube MCP Server is with the container image, but you have other options.

## Build from source

We recommend setting up the SonarQube MCP Server with the container image as explained in the [Quickstart guides](/agent-centric-development-cycle/developer-tools/mcp-server/setup/quickstart-guides.md) article, but if you want to build it locally, review the [Prerequisites](/agent-centric-development-cycle/developer-tools/mcp-server/setup/prerequisites.md), then follow these steps:

1. Clone the SonarQube MCP Server project from the [sonarqube-mcp-server repository](https://github.com/SonarSource/sonarqube-mcp-server).
2. Run the following Gradle command to clean the project and build the application:

   ```bash
   ./gradlew clean build -x test
   ```

   The JAR file will be created in `build/libs/`.
3. Perform the manual installation as described in [Manual installation](#manual-installation).

If you prefer, the JAR file is downloadable from the [sonarqube-mcp-server binaries page](https://binaries.sonarsource.com/?prefix=Distribution/sonarqube-mcp-server/).

## Manual installation

After you've built the SonarQube MCP Server locally, you'll need to manually install it in your MCP client. Add the following to your MCP configuration's JSON file.

The main difference between the server setup of SonarQube Cloud and SonarQube Server is:

* SonarQube Cloud requires a User token and an organization name.
  * If your SonarQube Cloud organization is in the US region, be sure to define SONARQUBE\_URL as `https://sonarqube.us` when configuring your connection. See the list of [common variables](/agent-centric-development-cycle/developer-tools/mcp-server/reference/environment-variables.md#common-variables) for complete details.
* SonarQube Server and SonarQube Community Build require a User token and server URL.

### SonarQube Cloud

```json
{
  "sonarqube": {
    "command": "java",
    "args": [
        "-jar",
        "<PathToYourSonarQubeMCPServerJAR>"
    ],
    "env": {
        "STORAGE_PATH": "<PathToYourMCPStorage>",
        "SONARQUBE_TOKEN": "<YourSonarQubeUserToken>",
        "SONARQUBE_ORG": "<YourOrganization>",
        //"SONARQUBE_URL": "https://sonarqube.us" //define this parameter to connect to an organization in the US region
    }
  }
}
```

> **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.

> **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

```json
{
  "sonarqube": {
    "command": "java",
    "args": [
        "-jar",
        "<PathToYourSonarQubeMCPServerJAR>"
    ],
    "env": {
        "STORAGE_PATH": "<PathToYourMCPStorage>",
        "SONARQUBE_TOKEN": "<YourSonarQubeUserToken>",
        "SONARQUBE_URL": "<YourSonarQubeServerURL>"
    }
  }
}
```

> **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.

## Deployment options

Depending on your environment, you may want to deploy your MCP server in different ways. See [Environment considerations](/agent-centric-development-cycle/developer-tools/mcp-server/setup/environment-considerations.md) to choose the right setup.


---

# 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/build.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.
