SonarQube MCP Server
The SonarQube MCP Server is a Model Context Protocol (MCP) server that enables seamless integration with SonarQube Server or Cloud for code quality and security.
It also supports the analysis of code snippet directly within the agent context.
Quick setup
🔒 Important: Your SonarQube token is a sensitive credential. Follow these security practices:
When using CLI commands:
- Avoid hardcoding tokens in command-line arguments – they get saved in shell history
- Use environment variables – set tokens in environment variables before running commands
When using configuration files:
- Never commit tokens to version control
- Use environment variable substitution in config files when possible
🚀 Generate your configuration
The fastest way to get started is the SonarQube MCP Server Configuration Generator – an interactive tool that produces a ready-to-use configuration for your preferred AI agent client.
Manual setup
If you prefer to configure things yourself, the simplest method is to use our container image at sonarsource/sonarqube-mcp. Use sonarsource/sonarqube-mcp for automatic updates (with --pull=always), or pin to a version tag (e.g., sonarsource/sonarqube-mcp:1.19.0.2785) for reproducible deployments. Read below if you want to build it locally.
Note: While the examples below use docker, any OCI-compatible container runtime works (e.g., Podman, nerdctl). Simply replace docker with your preferred tool.
SonarQube MCP Server is available in the Antigravity MCP Store. Follow these instructions:
- Open the Agent Side Panel
- Click the three dots (...) at the top right and select MCP Servers
- Search for
SonarQube and select Install
- Provide the required SonarQube User token. You can also provide your organization key for SonarQube Cloud or the SonarQube URL if connecting to SonarQube Server.
For SonarQube Cloud US, set the URL to https://sonarqube.us.
Alternatively, you can manually configure the server via mcp_config.json:
- To connect with SonarQube Cloud:
In the Agent Side Panel, click the three dots (...) -> MCP Store -> Manage MCP Servers -> View raw config, and add the following:
{
"mcpServers": {
"sonarqube": {
"command": "docker",
"args": ["run", "--init", "--pull=always", "-i", "--rm", "-e", "SONARQUBE_TOKEN", "-e", "SONARQUBE_ORG", "sonarsource/sonarqube-mcp"],
"env": {
"SONARQUBE_TOKEN": "<YOUR_TOKEN>",
"SONARQUBE_ORG": "<YOUR_ORG>"
}
}
}
}
For SonarQube Cloud US, manually add "SONARQUBE_URL": "https://sonarqube.us" to the env section and "-e", "SONARQUBE_URL" to the args array.
- To connect with SonarQube Server:
{
"mcpServers": {
"sonarqube": {
"command": "docker",
"args": ["run", "--init", "--pull=always", "-i", "--rm", "-e", "SONARQUBE_TOKEN", "-e", "SONARQUBE_URL", "sonarsource/sonarqube-mcp"],
"env": {
"SONARQUBE_TOKEN": "<YOUR_USER_TOKEN>",
"SONARQUBE_URL": "<YOUR_SERVER_URL>"
}
}
}
}
- To connect with SonarQube Cloud:
claude mcp add sonarqube \
--env SONARQUBE_TOKEN=$SONAR_TOKEN \
--env SONARQUBE_ORG=$SONAR_ORG \
-- docker run --init --pull=always -i --rm -e SONARQUBE_TOKEN -e SONARQUBE_ORG sonarsource/sonarqube-mcp
For SonarQube Cloud US, add --env SONARQUBE_URL=https://sonarqube.us to the command.
- To connect with SonarQube Server:
claude mcp add sonarqube \
--env SONARQUBE_TOKEN=$SONAR_USER_TOKEN \
--env SONARQUBE_URL=$SONAR_URL \
-- docker run --init --pull=always -i --rm -e SONARQUBE_TOKEN -e SONARQUBE_URL sonarsource/sonarqube-mcp
Manually edit the configuration file at ~/.codex/config.toml and add the following configuration:
- To connect with SonarQube Cloud:
[mcp_servers.sonarqube]
command = "docker"
args = ["run", "--init", "--pull=always", "--rm", "-i", "-e", "SONARQUBE_TOKEN", "-e", "SONARQUBE_ORG", "sonarsource/sonarqube-mcp"]
env = { "SONARQUBE_TOKEN" = "<YOUR_USER_TOKEN>", "SONARQUBE_ORG" = "<YOUR_ORG>" }
For SonarQube Cloud US, add "SONARQUBE_URL" = "https://sonarqube.us" to the env section and "-e", "SONARQUBE_URL" to the args array.
- To connect with SonarQube Server:
[mcp_servers.sonarqube]
command = "docker"
args = ["run", "--init", "--pull=always", "--rm", "-i", "-e", "SONARQUBE_TOKEN", "-e", "SONARQUBE_URL", "sonarsource/sonarqube-mcp"]
env = { "SONARQUBE_TOKEN" = "<YOUR_TOKEN>", "SONARQUBE_URL" = "<YOUR_SERVER_URL>" }
- To connect with SonarQube Cloud:
For SonarQube Cloud US, manually add "SONARQUBE_URL": "https://sonarqube.us" to the env section in your MCP configuration after installation.
- To connect with SonarQube Server:
Note: The Gemini CLI extension has moved to the sonarqube-agent-plugins repository. Please install it from there going forward.
You can install our MCP server extension by using the following command:
gemini extensions install https://github.com/SonarSource/sonarqube-agent-plugins
You will need to set the required environment variables before starting Gemini:
Environment Variables Required:
-
For SonarQube Cloud:
SONARQUBE_TOKEN - Your SonarQube Cloud token
SONARQUBE_ORG - Your organization key
SONARQUBE_URL - (Optional) Set to https://sonarqube.us for SonarQube Cloud US
-
For SonarQube Server:
SONARQUBE_TOKEN - Your SonarQube Server USER token
SONARQUBE_URL - Your SonarQube Server URL
Once installed, the extension will be installed under <home>/.gemini/extensions/sonarqube/gemini-extension.json.
After starting Copilot CLI, run the following command to add the SonarQube MCP server:
/mcp add
You will have to provide different information about the MCP server, you can use tab to navigate between fields.
- To connect with SonarQube Cloud:
Server Name: sonarqube
Server Type: Local (Press 1)
Command: docker
Arguments: run, --init, --pull=always, --rm, -i, -e, SONARQUBE_TOKEN, -e, SONARQUBE_ORG, sonarsource/sonarqube-mcp
Environment Variables: SONARQUBE_TOKEN=<YOUR_TOKEN>,SONARQUBE_ORG=<YOUR_ORG>
Tools: *
For SonarQube Cloud US, add -e, SONARQUBE_URL to Arguments and SONARQUBE_URL=https://sonarqube.us to Environment Variables.
- To connect with SonarQube Server:
Server Name: sonarqube
Server Type: Local (Press 1)
Command: docker
Arguments: run, --init, --pull=always, --rm, -i, -e, SONARQUBE_TOKEN, -e, SONARQUBE_URL, sonarsource/sonarqube-mcp
Environment Variables: SONARQUBE_TOKEN=<YOUR_USER_TOKEN>,SONARQUBE_URL=<YOUR_SERVER_URL>
Tools: *
The configuration file is located at ~/.copilot/mcp-config.json.
GitHub Copilot coding agent can leverage the SonarQube MCP server directly in your CI/CD.
To add the secrets to your Copilot environment, follow the Copilot documentation. Only secrets with names prefixed with COPILOT_MCP_ will be available to your MCP configuration.
In your GitHub repository, navigate under Settings -> Copilot -> Coding agent, and add the following configuration in the MCP configuration section:
- To connect with SonarQube Cloud:
{
"mcpServers": {
"sonarqube": {
"type": "local",
"command": "docker",
"args": [
"run",
"--init",
"--pull=always",
"--rm",
"-i",
"-e",
"SONARQUBE_TOKEN",
"-e",
"SONARQUBE_ORG",
"sonarsource/sonarqube-mcp"
],
"env": {
"SONARQUBE_TOKEN": "COPILOT_MCP_SONARQUBE_TOKEN",
"SONARQUBE_ORG": "COPILOT_MCP_SONARQUBE_ORG"
},
"tools": ["*"]
}
}
}
For SonarQube Cloud US, add "-e", "SONARQUBE_URL" to the args array and "SONARQUBE_URL": "COPILOT_MCP_SONARQUBE_URL" to the env section, then set the secret COPILOT_MCP_SONARQUBE_URL=https://sonarqube.us.
- To connect with SonarQube Server:
{
"mcpServers": {
"sonarqube": {
"type": "local",
"command": "docker",
"args": [
"run",
"--init",
"--pull=always",
"--rm",
"-i",
"-e",
"SONARQUBE_TOKEN",
"-e",
"SONARQUBE_URL",
"sonarsource/sonarqube-mcp"
],
"env": {
"SONARQUBE_TOKEN": "COPILOT_MCP_SONARQUBE_USER_TOKEN",
"SONARQUBE_URL": "COPILOT_MCP_SONARQUBE_URL"
},
"tools": ["*"]
}
}
}
Create a .kiro/settings/mcp.json file in your workspace directory (or edit if it already exists), add the following configuration:
- To connect with SonarQube Cloud:
{
"mcpServers": {
"sonarqube": {
"command": "docker",
"args": [
"run",
"--init",
"--pull=always",
"-i",
"--rm",
"-e",
"SONARQUBE_TOKEN",
"-e",
"SONARQUBE_ORG",
"sonarsource/sonarqube-mcp"
],
"env": {
"SONARQUBE_TOKEN": "<YOUR_TOKEN>",
"SONARQUBE_ORG": "<YOUR_ORG>"
},
"disabled": false,
"autoApprove": []
}
}
}
For SonarQube Cloud US, add "-e", "SONARQUBE_URL" to the args array and "SONARQUBE_URL": "https://sonarqube.us" to the env section.
- To connect with SonarQube Server:
{
"mcpServers": {
"sonarqube": {
"command": "docker",
"args": [
"run",
"--init",
"--pull=always",
"-i",
"--rm",
"-e",
"SONARQUBE_TOKEN",
"-e",
"SONARQUBE_URL",
"sonarsource/sonarqube-mcp"
],
"env": {
"SONARQUBE_TOKEN": "<YOUR_USER_TOKEN>",
"SONARQUBE_URL": "<YOUR_SERVER_URL>"
},
"disabled": false,
"autoApprove": []
}
}
}
You can use the following buttons to simplify the installation process within VS Code.
For SonarQube Cloud US, manually add "SONARQUBE_URL": "https://sonarqube.us" to the env section in your MCP configuration after installation.
SonarQube MCP Server is available as a Windsurf plugin. Follow these instructions:
- Open Windsurf Settings > Cascade > MCP Servers and select Open MCP Marketplace
- Search for
sonarqube on the Cascade MCP Marketplace
- Choose the SonarQube MCP Server and select Install
- Add the required SonarQube User token. Then add the organization key if you want to connect with SonarQube Cloud, or the SonarQube URL if you want to connect to SonarQube Server or Community Build.
For SonarQube Cloud US, set the URL to https://sonarqube.us.
Navigate to the Extensions view in Zed and search for SonarQube MCP Server.
When installing the extension, you will be prompted to provide the necessary environment variables:
- When using SonarQube Cloud:
{
"sonarqube_token": "YOUR_SONARQUBE_TOKEN",
"sonarqube_org": "SONARQUBE_ORGANIZATION_KEY",
"docker_path": "DOCKER_PATH"
}
For SonarQube Cloud US, add "sonarqube_url": "https://sonarqube.us" to the configuration.
- When using SonarQube Server:
{
"sonarqube_token": "YOUR_SONARQUBE_USER_TOKEN",
"sonarqube_url": "YOUR_SONARQUBE_SERVER_URL",
"docker_path": "DOCKER_PATH"
}
The docker_path is the path to a docker executable. Examples:
Linux/macOS: /usr/bin/docker or /usr/local/bin/docker
Windows: C:\Program Files\Docker\Docker\resources\bin\docker.exe
💡 Tip: We recommend pulling the latest image regularly or before reporting issues to ensure you have the most up-to-date features and fixes.
Manual installation
You can manually install the SonarQube MCP server by copying the following snippet in the MCP servers configuration file:
- To connect with SonarQube Cloud:
{
"sonarqube": {
"command": "docker",
"args": [
"run",
"--init",
"--pull=always",
"-i",
"--rm",
"-e",
"SONARQUBE_TOKEN",
"-e",
"SONARQUBE_ORG",
"sonarsource/sonarqube-mcp"
],
"env": {
"SONARQUBE_TOKEN": "<token>",
"SONARQUBE_ORG": "<org>"
}
}
}
- To connect with SonarQube Server:
{
"sonarqube": {
"command": "docker",
"args": [
"run",
"--init",
"--pull=always",
"-i",
"--rm",
"-e",
"SONARQUBE_TOKEN",
"-e",
"SONARQUBE_URL",
"sonarsource/sonarqube-mcp"
],
"env": {
"SONARQUBE_TOKEN": "<token>",
"SONARQUBE_URL": "<url>"
}
}
}
Integration with SonarQube for IDE
The SonarQube MCP Server can integrate with SonarQube for 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. SonarQube for VS Code includes a Quick Install button, which automatically sets the correct port configuration.
For example, with SonarQube Cloud:
{
"sonarqube": {
"command": "docker",
"args": [
"run",
"--init",
"--pull=always",
"-i",
"--rm",
"-e",
"SONARQUBE_TOKEN",
"-e",
"SONARQUBE_ORG",
"-e",
"SONARQUBE_IDE_PORT",
"sonarsource/sonarqube-mcp"
],
"env": {
"SONARQUBE_TOKEN": "<token>",
"SONARQUBE_ORG": "<org>",
"SONARQUBE_IDE_PORT": "<64120-64130>"
}
}
}
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.
Tools
Analysis
When integration with SonarQube for IDE is enabled: (these two tools are tagged under both the analysis and ide toolsets)
-
analyze_file_list - Analyze files in the current working directory using SonarQube for IDE. This tool connects to a running SonarQube for IDE instance to perform code quality analysis on a list of files.
file_absolute_paths - List of absolute file paths to analyze - Required String[]
-
toggle_automatic_analysis - Enable or disable SonarQube for IDE automatic analysis. When enabled, SonarQube for IDE will automatically analyze files as they are modified in the working directory. When disabled, automatic analysis is turned off.
enabled - Enable or disable the automatic analysis - Required Boolean
On SonarQube Server, stdio lists Vortex context tools and run_advanced_code_analysis when both the CAG and A3S hubs are entitled.
When Vortex analysis is enabled:
Requires having the workspace mounted at /app/mcp-workspace
- run_advanced_code_analysis - Run Vortex analysis on a single file. Organization is inferred from MCP configuration (SonarQube Server uses the nil UUID placeholder).
projectKey - The key of the project - Required String (Ignored when SONARQUBE_PROJECT_KEY is defined)
branch - Branch name used to retrieve the latest analysis context - Required String
filePath - Project-relative path of the file to analyze (e.g., src/main/java/MyClass.java). - Required String
fileScope - Defines in which scope the file originates from: 'MAIN' or 'TEST' (default: MAIN) - String
Coverage
-
search_files_by_coverage - Search for files in a project sorted by coverage (ascending - worst coverage first). This tool helps identify files that need test coverage improvements.
projectKey - The project key to search in - Required String (Ignored when SONARQUBE_PROJECT_KEY is defined)
branch - Optional branch name for branch-based analysis. Use list_branches to discover valid names - String
pullRequest - Optional pull request key/ID. Use list_pull_requests to discover valid keys - String
maxCoverage - Maximum coverage threshold (0-100). Only return files with coverage <= this value - Number
pageIndex - Page index (1-based, default: 1) - Number
pageSize - Page size (default: 100, max: 500) - Number
-
get_file_coverage_details - Get line-by-line coverage information for a specific file, including which exact lines are uncovered and which have partially covered branches. This tool helps identify precisely where to add test coverage. Use after identifying files with low coverage via search_files_by_coverage.
key - File key (e.g. my_project:src/foo/Bar.java) - Required String
branch - Optional branch name for branch-based analysis. Use list_branches to discover valid names - String
pullRequest - Optional pull request key/ID. Use list_pull_requests to discover valid keys -
Dependency Risks
Note: Dependency risks are only available when connecting to SonarQube Server 2025.4 Enterprise or higher with SonarQube Advanced Security enabled.
- search_dependency_risks - Search for software composition analysis issues (dependency risks) of a SonarQube project, paired with releases that appear in the analyzed project, application, or portfolio.
projectKey - Project key - Required String (Ignored when SONARQUBE_PROJECT_KEY is defined)
branch - Optional branch name for branch-based analysis. Use list_branches to discover valid names - String
pullRequest - Optional pull request key/ID. Use list_pull_requests to discover valid keys - String
pageIndex - Optional page index (1-based, default: 1) - Integer
pageSize - Optional page size. Must be greater than 0 and less than or equal to 500 (default: 100) - Integer
Enterprises
Note: Enterprises are only available when connecting to SonarQube Cloud.
- list_enterprises - List the enterprises available in SonarQube Cloud that you have access to. Use this tool to discover enterprise IDs that can be used with other tools.
enterpriseKey - Optional enterprise key to filter results - String
Issues
-
change_sonar_issue_status - Change the status of a SonarQube issue to "accept", "falsepositive" or to "reopen" an issue.
key - Issue key - Required String
status - New issue's status - Required Enum {"accept", "falsepositive", "reopen"}
comment - Optional comment explaining the status change - String
-
search_sonar_issues_in_projects - Search for SonarQube issues in my organization's projects.
projectKeys - Optional list of SonarQube project keys - String[]
branch - Optional branch name for branch-based analysis. Use list_branches to discover valid names - String
pullRequest - Optional pull request key/ID. Use list_pull_requests to discover valid keys - String
severities - Optional list of severities to filter by. Possible values: INFO, LOW, MEDIUM, HIGH, BLOCKER - String[]
impactSoftwareQualities - Optional list of software qualities to filter by. Possible values: MAINTAINABILITY, RELIABILITY, SECURITY - String[]
issueStatuses - Optional list of issue statuses to filter by. Possible values: OPEN, CONFIRMED, FALSE_POSITIVE, ACCEPTED, FIXED, IN_SANDBOX - String[]
inNewCodePeriod - Only return issues in the new code period. Requires exactly one entry across projectKeys and files -
Security Hotspots
-
search_security_hotspots - Search for Security Hotspots in a SonarQube project.
projectKey - Project or application key - Required String (Ignored when SONARQUBE_PROJECT_KEY is defined)
hotspotKeys - Comma-separated list of specific Security Hotspot keys to retrieve - String[]
branch - Optional branch name for branch-based analysis. Use list_branches to discover valid names - String
pullRequest - Optional pull request key/ID. Use list_pull_requests to discover valid keys - String
files - Optional list of file paths to filter - String[]
status - Optional status filter: TO_REVIEW, REVIEWED - String
resolution - Optional resolution filter: FIXED, SAFE, ACKNOWLEDGED - String
sinceLeakPeriod - Filter hotspots created since the leak period (new code) - Boolean
onlyMine - Show only hotspots assigned to me - Boolean
pageIndex - Optional 1-based page index (default: 1) - Integer
pageSize - Optional page size. Must be greater than 0 and less than or equal to 500 (default: 100) - Integer
-
show_security_hotspot - Get detailed information about a specific Security Hotspot, including rule details, code context, flows, and comments.
Languages
- list_languages - List all programming languages supported in this SonarQube instance.
q - Optional pattern to match language keys/names against - String
Measures
- get_component_measures - Get SonarQube measures for a component (project, directory, file).
projectKey - The project key - Required String when SONARQUBE_PROJECT_KEY is not configured
branch - Optional branch name for branch-based analysis. Use list_branches to discover valid names - String
metricKeys - Optional metric keys to retrieve (e.g. ncloc, complexity, violations, coverage) - String[]
pullRequest - Optional pull request key/ID. Use list_pull_requests to discover valid keys - String
Metrics
- search_metrics - Search for SonarQube metrics.
pageIndex - Optional 1-based page index (default: 1) - Integer
pageSize - Optional page size. Must be greater than 0 and less than or equal to 500 (default: 100) - Integer
Portfolios
Projects
Quality Gates
Rules
- show_rule - Shows detailed information about a SonarQube rule.
key - Rule key - Required String
Duplications
-
search_duplicated_files - Search for files with code duplications in a SonarQube project. By default, automatically fetches all duplicated files across all pages (up to 10,000 files max). Returns only files with duplications.
projectKey - Project key - Required String (Ignored when SONARQUBE_PROJECT_KEY is defined)
branch - Optional branch name for branch-based analysis. Use list_branches to discover valid names - String
pullRequest - Optional pull request key/ID. Use list_pull_requests to discover valid keys - String
pageSize - Optional number of results per page for manual pagination (max: 500). If not specified, auto-fetches all duplicated files - Integer
pageIndex - Optional page number for manual pagination (starts at 1). If not specified, auto-fetches all duplicated files - Integer
-
get_duplications - Get duplications for a file. Require Browse permission on file's project.
key - File key - Required String
branch - Optional branch name for branch-based analysis. Use list_branches to discover valid names - String
pullRequest - Optional pull request key/ID. Use list_pull_requests to discover valid keys - String
Sources
-
get_raw_source - Get source code as raw text from SonarQube. Require 'See Source Code' permission on file.
key - File key - Required String
branch - Optional branch name for branch-based analysis. Use list_branches to discover valid names - String
pullRequest - Optional pull request key/ID. Use list_pull_requests to discover valid keys - String
-
get_scm_info - Get SCM information of SonarQube source files. Require See Source Code permission on file's project.
key - File key - Required String
commits_by_line - Group lines by SCM commit if value is false, else display commits for each line - String
from - First line to return. Starts at 1 - Number
to - Last line to return (inclusive) - Number
System
Note: System tools are only available when connecting to SonarQube Server.
-
get_system_health - Get the health status of SonarQube Server instance. Returns GREEN (fully operational), YELLOW (usable but needs attention), or RED (not operational).
-
get_system_info - Get detailed information about SonarQube Server system configuration including JVM state, database, search indexes, and settings. Requires 'Administer' permissions.
-
get_system_logs - Get SonarQube Server system logs in plain-text format. Requires system administration permission.
name - Optional name of the logs to get. Possible values: access, app, ce, deprecation, es, web. Default: app - String
-
ping_system - Ping the SonarQube Server system to check if it's alive. Returns 'pong' as plain text.
-
get_system_status - Get state information about SonarQube Server. Returns status (STARTING, UP, DOWN, RESTARTING, DB_MIGRATION_NEEDED, DB_MIGRATION_RUNNING), version, and id.
Webhooks
-
create_webhook - Create a new webhook for the SonarQube organization or project. Requires 'Administer' permission on the specified project, or global 'Administer' permission.
name - Webhook name - Required String
url - Webhook URL - Required String
projectKey - Optional project key for project-specific webhook - String
secret - Optional webhook secret for securing the webhook payload - String
-
list_webhooks - List all webhooks for the SonarQube organization or project. Requires 'Administer' permission on the specified project, or global 'Administer' permission.
projectKey - Optional project key to list project-specific webhooks - String
Context Augmentation
-
search_by_signature_patterns - Find code elements (classes, methods, interfaces, ...) by their declaration signatures using regex patterns.
include_code_regex_list - List of regex patterns to match against signatures - Required String[]
exclude_code_regex_list - List of regex patterns to exclude from results - String[]
include_glob - File filter glob pattern (e.g., *.java) - String
exclude_glob - File exclusion glob pattern - String
fields - Comma-separated list of fields to include in the response - String
limit - Maximum number of results to return (default: 10) - Integer
regex_lists_operator - How to combine multiple patterns: OR (default) or AND - String
-
search_by_body_patterns - Find code elements by their implementation body using regex patterns. Useful for locating where APIs or patterns are actually used.
include_code_regex_list - List of regex patterns to match in code bodies - Required String[]
exclude_code_regex_list - List of regex patterns to exclude from results - String[]
include_glob - File filter glob pattern - String
exclude_glob - File exclusion glob pattern - String
- get_guidelines - Get coding guidelines based on SonarQube project issues, catalog categories, or a combination of both.
mode - Guidelines retrieval mode: project_based, category_based, or combined - Required String
categories - List of category names (required for category_based and combined modes) - String[]
languages - List of target languages in SonarQube repository key format (required when categories is provided) - String[]
file_paths - Optional list of file paths to filter guidelines by - String[]
- check_dependency - Check a third-party dependency for security vulnerabilities, supply-chain malware, and license compliance before adding or updating it.
purl - Package URL (purl) with version, per purl-spec. Format: pkg:<type>/<namespace>/<name>@<version> (e.g. pkg:npm/lodash@4.17.21, pkg:maven/org.apache.logging.log4j/log4j-core@2.14.1, pkg:pypi/django@3.2.0) - Required String
| Variable | Description | Required | Default |
|---|
SONARQUBE_URL | SonarQube Cloud URL | Yes | https://sonarcloud.io |
SONARQUBE_TOKEN | Authentication token | Yes | None |
SONARQUBE_ORG | Organization key on SonarQube Cloud | Yes | None |
SONARQUBE_PROJECT_KEY | Project key on SonarQube Cloud | Yes | None |
SONAR_SQ_BRANCH | Explicit SonarQube branch override * | No | None |
SONARQUBE_DEBUG_ENABLED | Activate debug logging (for troubleshooting) | No | False |
|
- To be provided when not using git, or when the git branch name doesn't match the branch name in SonarQube.
First, export the SONARQUBE_TOKEN environment variable with a valid Personal Access Token (PAT) for your project.
# macOS/Linux (Bash/Zsh)
export SONARQUBE_TOKEN="{<YourUserToken>}"
Then, mount the project workspace to give the Context Augmentation server direct access to your source files:
{
"mcpServers": {
"sonarqube-mcp-server": {
"command": "docker",
"args": [
"run", "-i", "--rm", "--pull=always",
"-e", "SONARQUBE_URL",
"-e", "SONARQUBE_TOKEN",
"-e", "SONARQUBE_ORG",
"-e", "SONARQUBE_PROJECT_KEY",
"-e", "SONARQUBE_TOOLSETS",
"-v", "/ABSOLUTE/PATH/TO/YOUR/PROJECT:/app/mcp-workspace:rw",
"sonarsource/sonarqube-mcp"
],
"env": {
"SONARQUBE_URL": "https://sonarcloud.io",
"SONARQUBE_ORG": "<YourOrganizationKey>",
"SONARQUBE_PROJECT_KEY": "<YourProjectKey>",
"SONARQUBE_TOOLSETS": "cag"
}
}
}
}
Important: In a project-scoped config, do not put SONARQUBE_TOKEN in the env block. Export it as an environment variable (export SONARQUBE_TOKEN=...). Docker will forward it into the container via -e SONARQUBE_TOKEN.
Agentic Readiness
Note: Agentic Readiness tools are only available on SonarQube Cloud and require the feature to be enabled for your organization.
-
start_agentic_readiness_assessment - Start an agentic readiness assessment for a project. Returns immediately with status PENDING and an assessmentId. Use get_agentic_readiness_assessment to poll for results.
projectKey - The project key - Required String (Ignored when SONARQUBE_PROJECT_KEY is defined)
branch - Branch to assess. Omit to use the project's default branch - String
-
get_agentic_readiness_assessment - Retrieve the result of an assessment. Re-call with the same assessmentId until status is COMPLETED, FAILED, or INTERRUPTED. When completed, returns the overall level and a per-pillar breakdown with recommended actions and evidence.
assessmentId - The assessment ID returned by start_agentic_readiness_assessment - Required String
-
list_agentic_readiness_assessments - List all assessments for a project, newest first. Use get_agentic_readiness_assessment for full pillar-level results.
projectKey - The project key to list assessments for - Required String (Ignored when SONARQUBE_PROJECT_KEY is defined)
branch - Filter assessments by branch name. Omit to list assessments for all branches -
Example Prompts
Once you've set up the SonarQube MCP Server, here are some example prompts for common real-world scenarios:
My quality gate is failing for my project. Can you help me understand why and fix the most critical issues?
The quality gate on my feature branch is red. What do I need to fix to get it passing before I can merge to main?
I'm about to merge my pull request <#247> for the <web-app> project. Can you check if there are any quality issues I should address first?
We're deploying to production tomorrow. Can you check the quality gate status and alert me to any critical issues in this branch?
I want to reduce technical debt in my project. What are the top issues I should prioritize?
Our code coverage dropped below 70%. Can you identify which files have the lowest coverage and help me improve it?
I have 15 new code smells in my latest commit. Can you explain what they are and help me fix them?
SonarQube flagged a critical security vulnerability in <AuthController.java>. What's the issue and how do I fix it?
We need to pass a security audit. Can you check all our projects for security vulnerabilities and create a prioritized list of what needs to be fixed?
Are there any known vulnerabilities in our dependencies? Check this project for dependency risks.
I just wrote this authentication function. Can you analyze it for security issues and code quality problems before I commit?
Review the changes in <src/database/migrations> for any potential bugs or security issues.
Give me a health report for my project: quality gate status, number of bugs, Security Hotspots, and code coverage.
Compare code quality between our main branch and the develop branch. Are we introducing new issues?
What are the most common rule violations across all our projects? We might need to update our coding standards.
Show me all the issues that were marked as false positives in the last month. Are we seeing patterns that suggest our rules need adjustment?
Build
Prefer the sonarsource/sonarqube-mcp container image.
To run the server as a standalone JAR without Docker, download a pre-built release from the SonarSource binaries repository. Every released version is published there as sonarqube-mcp-server-<version>.jar (for example, sonarqube-mcp-server-1.19.0.2785.jar).
Download the JAR for the version you want from the binaries repository, then configure your MCP client to run it with Java 21 or later:
- To connect with SonarQube Cloud:
{
"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>"
}
}
}
- 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>"
}
}
}
SonarQube MCP Server requires a Java Development Kit (JDK) version 21 or later to build.
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/.
After adding or updating dependencies, regenerate the lock files:
./gradlew :dependencies --write-locks
./gradlew :its:dependencies --write-locks
Use the Run from JAR configuration above, pointing <path_to_sonarqube_mcp_server_jar> to the JAR in build/libs/.
Troubleshooting
Application logs are written to the STORAGE_PATH/logs/mcp.log file by default. To disable file logging entirely, set SONARQUBE_LOG_TO_FILE_DISABLED=true.
Common Issues
"Feature is not working" or "Missing tools/functionality"
You may be running an outdated Docker image. Docker caches images locally, so you won't automatically receive updates.
Solution: Update to the latest version:
docker pull sonarsource/sonarqube-mcp
After pulling the latest image, restart your MCP client to use the updated version.
Optionally, add the --pull=always flag to your docker run command to always check for and pull the latest version:
docker run --init --pull=always -i --rm -e SONARQUBE_TOKEN -e SONARQUBE_ORG sonarsource/sonarqube-mcp
"I want to pin to a specific version"
Browse available tags at sonarsource/sonarqube-mcp and reference the version you want:
docker pull sonarsource/sonarqube-mcp:1.19.0.2785
docker run --init -i --rm \
-e SONARQUBE_TOKEN -e SONARQUBE_ORG \
sonarsource/sonarqube-mcp:1.19.0.2785
In your MCP client config, use sonarsource/sonarqube-mcp:<version> instead of sonarsource/sonarqube-mcp and remove --pull=always so Docker does not silently upgrade the image.
Data and telemetry
This server collects anonymous usage data and sends it to SonarSource to help improve the product. No source code or IP address is collected, and SonarSource does not share the data with anyone else. Collection of telemetry can be disabled with the following system property or environment variable: TELEMETRY_DISABLED=true. Click here to see a sample of the data that are collected.
License
Copyright 2025 SonarSource.
Licensed under the SONAR Source-Available License v1.0. Using the SonarQube MCP Server in compliance with this documentation is a Non-Competitive Purpose and so is allowed under the SSAL.
Your use of SonarQube via MCP is governed by the SonarQube Cloud Terms of Service or SonarQube Server Terms and Conditions, including use of the Results Data solely for your internal software development purposes.