SonarQube MCP server

Integrates with SonarQube and SonarCloud platforms for code quality analysis, issue management, metrics retrieval, quality gate monitoring, and system administration across both server and cloud environments.
Back to servers
Setup instructions
Provider
SonarSource
Release date
Jul 07, 2025
Stats
55 stars

The SonarQube MCP Server provides seamless integration with SonarQube Server or Cloud through the Model Context Protocol (MCP). It enables direct code snippet analysis within the agent context, allowing you to access SonarQube's powerful code quality features from your development environment.

Installation Options

Using Docker (Recommended)

The simplest installation method is to use the official Docker image:

docker run -i --rm -e SONARQUBE_TOKEN="<your-token>" -e SONARQUBE_ORG="<your-org>" mcp/sonarqube

For SonarQube Server connection:

docker run -i --rm -e SONARQUBE_TOKEN="<your-token>" -e SONARQUBE_URL="<your-server-url>" mcp/sonarqube

Manual Installation

You can manually install the SonarQube MCP server by adding configuration to your MCP servers configuration file:

For SonarQube Cloud:

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

For SonarQube Server:

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

Building from Source

If you prefer to build from source:

  1. Ensure you have JDK 21+ installed
  2. Run the build command:
./gradlew clean build -x test
  1. Configure the MCP server with the built JAR:
{
  "sonarqube": {
    "command": "java",
    "args": [
      "-jar",
      "<path_to_sonarqube_mcp_server_jar>"
    ],
    "env": {
      "STORAGE_PATH": "<path_to_your_mcp_storage>",
      "SONARQUBE_TOKEN": "<token>",
      "SONARQUBE_ORG": "<org>"
    }
  }
}

Configuration

Required Environment Variables

Variable Description
STORAGE_PATH An absolute path to a writable directory where SonarQube MCP Server will store its files

For SonarQube Cloud

Variable Description
SONARQUBE_TOKEN Your SonarQube Cloud token
SONARQUBE_ORG Your SonarQube Cloud organization key

For SonarQube Server

Variable Description
SONARQUBE_TOKEN Your SonarQube Server USER token
SONARQUBE_URL Your SonarQube Server URL

Available Tools

Analysis Tools

  • analyze_code_snippet: Analyze a code snippet with SonarQube analyzers
    • Parameters:
      • codeSnippet (Required): Code snippet or full file content
      • language: Optional language of the code snippet

Languages Tools

  • list_languages: List all supported programming languages
    • Parameters:
      • q: Optional pattern to match language keys/names against

Issues Tools

  • change_sonar_issue_status: Change the status of a SonarQube issue

    • Parameters:
      • key (Required): Issue key
      • status (Required): New issue's status (accept, falsepositive, reopen)
  • search_sonar_issues_in_projects: Search for SonarQube issues in your organization's projects

    • Parameters:
      • projects: Optional list of Sonar projects
      • pullRequestId: Optional Pull Request's identifier
      • p: Optional page number (default: 1)
      • ps: Optional page size (default: 100, max: 500)

Measures Tools

  • get_component_measures: Get measures for a component
    • Parameters:
      • component: Optional component key
      • branch: Optional branch to analyze
      • metricKeys: Optional metric keys to retrieve
      • pullRequest: Optional pull request identifier

Projects Tools

  • search_my_sonarqube_projects: Find Sonar projects in your organization
    • Parameters:
      • page: Optional page number

Quality Gates Tools

  • get_project_quality_gate_status: Get the Quality Gate Status for a project

    • Parameters:
      • analysisId, branch, projectId, projectKey, pullRequest: Optional filters
  • list_quality_gates: List all quality gates in the organization

Rules Tools

  • list_rule_repositories: List rule repositories available in SonarQube

    • Parameters:
      • language: Optional language key
      • q: Optional search query
  • show_rule: Shows detailed information about a SonarQube rule

    • Parameters:
      • key (Required): Rule key

System Tools (SonarQube Server only)

  • get_system_health: Get health status of SonarQube Server
  • get_system_info: Get detailed system configuration information
  • ping_system: Check if the SonarQube Server is alive
  • get_system_status: Get state information about SonarQube Server

Troubleshooting

Application logs are written to the STORAGE_PATH/logs/mcp.log file. Check these logs if you encounter any issues with the server.

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

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

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

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

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

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

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later