Start Free
Latest | AI capabilities | SonarQube MCP Server

SonarQube MCP Server

On this page

The SonarQube MCP Server is a Model Context Protocol (MCP) server that provides seamless integration with SonarQube Server or SonarQube Cloud for code quality and code security. It also enables the analysis of code snippets directly within the agent context.

Overview

The SonarQube MCP Server allows you to retrieve information and perform actions on your SonarQube Server instance or SonarQube Cloud organization. It is compatible with MCP clients such as:

  • Cursor
  • Windsurf
  • VS Code with GitHub Copilot

Upon receiving a request from an MCP client, the SonarQube MCP Server calls the SonarQube Cloud or SonarQube Server API to perform actions:

Overview of the SonarQube MCP Server setup.

Prerequisites

  • For the Docker container installation: Docker installed.
  • For the local build: 
    • Java Development Kit (JDK), version 21 or later
    • Gradle
  • One of the IDEs compatible with the SonarQube MCP Server, for example:
    • Cursor
    • VS Code with GitHub Copilot 
    • Windsurf

Setting up the SonarQube MCP Server with Docker

The SonarQube MCP Server can be launched in two ways: With a Docker container (recommended), or from a JAR file built locally.

The recommended method is to rely on the official Docker image hosted at mcp/sonarqube by following the Quick configuration or Manual configuration instructions below to integrate your MCP Server with SonarQube Server.

Setup in Cursor

Quick configuration 

You can use the following link to quickly set up the SonarQube MCP Server in Cursor. This will generate a configuration file in Cursor and automatically fill it with your environment variables. Make sure your environment variables (see below) are configured first.

Manual configuration

For a manual configuration, add this MCP configuration to your mcp.json file, at the location specified in the Cursor documentation.

{
"mcpServers":
{
  "sonarqube": {
    "command": "docker",
    "args": [
      "run",
      "-i",
      "--rm",
      "-e",
      "SONARQUBE_TOKEN",
      "-e",
      "SONARQUBE_ORG",
      "mcp/sonarqube"
    ],
    "env": {
      "SONARQUBE_TOKEN": "<token>",
      "SONARQUBE_ORG": "<org>"
    }
  }
}

For more information on the environment variables and how to retrieve the token and organization information, see the Environment variables section below.

Once you’ve set up the Sonar MCP Server, the configuration appears under Tools & Integrations in Cursor.

Using the SonarQube MCP Server tools

You can use the Cursor chat to use one of the available tools, for example, by typing: "search my sonarQube projects".

The full list of tools is available the sonarqube-mcp-server GitHub repository.

Setup in VS Code with GitHub Copilot

To use the SonarQube MCP server in VS Code, you must first install Copilot Chat.

Quick configuration

You can use the following link to quickly set up the SonarQube MCP Server in VS Code with GitHub Copilot. This will generate a configuration file in VS Code and automatically fill it with your environment variables. Make sure your environment variables (see section below) are configured first.

Manual configuration

Follow the VS Code instructions and add the SonarQube MCP Server to your .vscode/mcp.json file:

{
"mcp": {
"servers": 
{
  "sonarqube": {
    "command": "docker",
    "args": [
      "run",
      "-i",
      "--rm",
      "-e",
      "SONARQUBE_TOKEN",
      "-e",
      "SONARQUBE_ORG",
      "mcp/sonarqube"
    ],
    "env": {
      "SONARQUBE_TOKEN": "<token>",
      "SONARQUBE_ORG": "<org>"
    }
  }
}

For more information on the environment variables and how to retrieve the token and organization information, see the Environment variables section below.

Using the SonarQube MCP Server tools

Once you’ve set up the Sonar MCP Server in VS Code, you can use the tools it provides in agent mode. See the VS Code documentation for more information. 

Setup in Windsurf

SonarQube MCP Server is available as a Windsurf plugin. Follow these instructions:

  1. Click on the Plugins button at the top right of the Cascade view
  2. Search for sonarqube on the Plugin store
  3. Click Install
  4. Add the required SonarQube token. Then add the SonarQube URL to connect to SonarQube Server or Community Build.

Using the  SonarQube MCP Server tools

Once you’ve set up the Sonar MCP Server in Windsurf, you can use the tools it provides in the agent mode. See the Windsurf docs for more information on adding explicit context. 

Analyzing code snippets directly within the agent context

Once the MCP Server is set up, you can analyze code snippets directly within your agent context. 

Example in Cursor

In the chat, you can the agent to perform the following actions:

  • “analyze the current file with SonarQube” 
  • “analyze the following piece of code with SonarQube” to analyze a piece of code that you paste into the chat. Note that this command has limitations as some analyzers require the full context of the file to run an analysis.

You can also add explicit context for the analysis. See the Cursor documentation for more details on adding context.

Example of “Analyze the current file with SonarQube” in Cursor.
Example of “Analyze the current file with SonarQube” in Cursor.

Environment Variables

Depending on which Sonar product you want the MCP Server to connect to, you should provide specific environment variables.

To enable full functionality, the following environment variables must be set before starting the SonarQube MCP server.

Environment variableDescription
SONARQUBE_TOKENYour SonarQube Server USER token
SONARQUBE_URLYour SonarQube Server URL

Storage PATH 

Required only if you build the SonarQube MCP Server locally. You should add the following variable when running the MCP Server:

Environment variableDescription
STORAGE_PATHAn absolute path to a writable directory where SonarQube MCP Server will store its files (e.g., for creation, updates, and persistence)

Tools

The tools available with the SonarQube MCP Server are listed in the SonarQube MCP Server repository

Building the SonarQube MCP Server locally 

We recommend setting up the SonarQube MCP Server with Docker as mentioned above, but if you need to build it locally, follow these steps:

  1. Download the SonarQube MCP Server project from the sonarqube-mcp-server repository.
  2. Run the following Gradle command to clean the project and build the application:
    ./gradlew clean build -x test.
    The JAR file will be created in build/libs/.
  3. Perform the manual installation as explained below.

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:

To connect with SonarQube Server:

{
  "sonarqube": {
    "command": "java",
    "args": [
      "-jar",
      "<path_to_sonarqube_mcp_server_jar>"
    ],
    "env": {
      "STORAGE_PATH": "<path_to_your_mcp_storage>",
      "SONARQUBE_TOKEN": "<token>",
      "SONARQUBE_URL": "<url>"
    }
  }
}

Once the SonarQube MCP server is connected, its tools become available. See the Tools sections above for more information. 


Was this page helpful?

© 2008-2025 SonarSource SA. All rights reserved.

Creative Commons License