The SonarQube MCP Server integrates with SonarQube to provide AI assistants with access to code quality metrics, issues, and analysis results through the Model Context Protocol. This server enables AI assistants to retrieve code metrics, access and filter issues, check quality status, and analyze project quality over time.
There are two primary ways to set up the SonarQube MCP server:
{
"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",
"[email protected]"
],
"env": {
"SONARQUBE_URL": "https://sonarqube.example.com",
"SONARQUBE_TOKEN": "your-sonarqube-token",
"SONARQUBE_ORGANIZATION": "your-organization-key (optional)"
}
}
}
}
These environment variables control the server's connection to SonarQube:
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 CloudEdit your Claude Desktop configuration:
Settings
-> Developer
-> Edit Config
mcpServers
sectionRestart Claude Desktop to apply the changes
The SonarQube MCP Server provides two main tools:
Lists all SonarQube projects with pagination support.
Parameters:
organization
(optional) - Organization key for SonarQube Cloudpage
(optional) - Page number for results paginationpage_size
(optional) - Number of items per pageGets detailed issue information from SonarQube projects with extensive filtering options.
Required Parameters:
project_key
- The unique identifier for the SonarQube projectOptional Parameters:
severity
- Filter issues by severity (INFO, MINOR, MAJOR, CRITICAL, BLOCKER)organization
- Organization key for SonarQube Cloudpage
- Page number for results paginationpage_size
- Number of items per pagestatuses
- Filter issues by status (array of: OPEN, CONFIRMED, REOPENED, RESOLVED, CLOSED, TO_REVIEW, IN_REVIEW, REVIEWED)resolutions
- Filter issues by resolution (array of: FALSE-POSITIVE, WONTFIX, FIXED, REMOVED)resolved
- Whether to return only resolved issues (true) or unresolved issues (false)types
- Filter issues by type (array of: CODE_SMELL, BUG, VULNERABILITY, SECURITY_HOTSPOT)rules
- Array of rule keys to filter issuestags
- Array of tags to filter issuescreated_after
- Return issues created after the given date (format: YYYY-MM-DD)created_before
- Return issues created before the given date (format: YYYY-MM-DD)created_at
- Return issues created on the given datecreated_in_last
- Return issues created during a time span before the current time (e.g., "1d" for issues created in the last day)assignees
- Array of assignee login names to filter issuesauthors
- Array of author login names to filter issuescwe
- Array of CWE identifiers to filter vulnerability issueslanguages
- Array of languages to filter issuesowasp_top10
- Array of OWASP Top 10 categories to filter issuessans_top25
- Array of SANS Top 25 categories to filter issuessonarsource_security
- Array of SonarSource security categories to filter issueson_component_only
- Return only issues at the specified component level (true) or issues from the component's subtree (false)facets
- Array of facets to return along with the issuessince_leak_period
- Return only issues created since the leak periodin_new_code_period
- Return only issues created in the new code periodThere 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.