The SonarQube MCP Server enables AI assistants to access SonarQube's code quality metrics, issues, and analysis results through the Model Context Protocol. This integration allows you to retrieve code metrics, access and filter issues, check quality status, and analyze project quality over time.
First, edit your Claude Desktop configuration:
Settings
→ Developer
→ Edit Config
mcpServers
sectionRestart Claude Desktop to apply the changes
{
"mcpServers": {
"sonarqube": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"SONARQUBE_URL",
"-e",
"SONARQUBE_TOKEN",
"-e",
"SONARQUBE_ORGANIZATION",
"sapientpants/sonarqube-mcp-server"
],
"env": {
"SONARQUBE_URL": "https://sonarqube.example.com",
"SONARQUBE_TOKEN": "your-sonarqube-token",
"SONARQUBE_ORGANIZATION": "your-organization-key (optional)"
}
}
}
}
{
"mcpServers": {
"sonarqube": {
"command": "npx",
"args": [
"-y",
"sonarqube-mcp-server@latest"
],
"env": {
"SONARQUBE_URL": "https://sonarqube.example.com",
"SONARQUBE_TOKEN": "your-sonarqube-token",
"SONARQUBE_ORGANIZATION": "your-organization-key (optional)"
}
}
}
}
The server requires the following environment variables:
SONARQUBE_URL
- URL of your SonarQube instance (default: https://next.sonarqube.com/sonarqube)SONARQUBE_TOKEN
- Authentication token for SonarQube API accessSONARQUBE_ORGANIZATION
- (Optional) Organization key for SonarQube CloudList all SonarQube projects with pagination.
Parameters:
page
(optional) - Page number for results paginationpage_size
(optional) - Number of items per pageGet available metrics from SonarQube.
Parameters:
page
(optional) - Page number for results paginationpage_size
(optional) - Number of items per pageGet issues from a SonarQube project with extensive filtering options.
Parameters:
project_key
(required) - The unique identifier for the SonarQube projectbranch
(optional) - Filter issues for a specific branchpull_request
(optional) - Filter issues for a specific pull requesthotspots
(optional) - Filter for security hotspotsseverity
(optional) - Filter issues by severity (INFO, MINOR, MAJOR, CRITICAL, BLOCKER)page
(optional) - Page number for results paginationpage_size
(optional) - Number of items per pagestatuses
(optional) - Filter issues by status (array of: OPEN, CONFIRMED, REOPENED, RESOLVED, CLOSED, TO_REVIEW, IN_REVIEW, REVIEWED)resolutions
(optional) - Filter issues by resolution (array of: FALSE-POSITIVE, WONTFIX, FIXED, REMOVED)resolved
(optional) - Whether to return only resolved issues (true) or unresolved issues (false)types
(optional) - Filter issues by type (array of: CODE_SMELL, BUG, VULNERABILITY, SECURITY_HOTSPOT)rules
(optional) - Array of rule keys to filter issuestags
(optional) - Array of tags to filter issuescreated_after
(optional) - Return issues created after the given date (format: YYYY-MM-DD)created_before
(optional) - Return issues created before the given date (format: YYYY-MM-DD)created_at
(optional) - Return issues created on the given datecreated_in_last
(optional) - Return issues created during a time span before the current time (e.g., "1d" for issues created in the last day)Get measures for a specific component.
Parameters:
component
(required) - Component keymetric_keys
(required) - Comma-separated list or array of metric keysadditional_fields
(optional) - Additional fields to return in the responsebranch
(optional) - Branch namepull_request
(optional) - Pull request keyperiod
(optional) - Period indexGet measures for multiple components.
Parameters:
component_keys
(required) - Comma-separated list or array of component keysmetric_keys
(required) - Comma-separated list or array of metric keysGet measures history for a component.
Parameters:
component
(required) - Component keymetrics
(required) - Comma-separated list or array of metric keysfrom
(optional) - Start date (format: YYYY-MM-DD)to
(optional) - End date (format: YYYY-MM-DD)Get the health status of the SonarQube instance. No parameters required.
Get the status of the SonarQube instance. No parameters required.
Ping the SonarQube instance to check if it is up. No parameters required.
To use the MCP server with Claude, you'll need to have properly configured it as shown in the installation section. Once configured, you can ask Claude to use the SonarQube tools through natural language requests.
For example:
Claude will then use the appropriate tool with the correct parameters to retrieve the information from your SonarQube instance.
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.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
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.
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 explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.