Using SonarQube MCP Server
This page describes how to integrate the SonarQube MCP Server with SonarQube for IDE to enhance your development workflow in an AI-enabled environment.
The primary focus of these examples helps you set upyour environment variables, particularly SONARQUBE_IDE_PORT, using Docker examples for both SonarQube Cloud and SonarQube Server. Once configured, your can use your AI agent to analyze code snippets or entire files directly within your IDE.
If needed, check out the Quickstart guide to get on your way before interacting with the SonarQube MCP Server.
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. See the list of Base variables for more information.
SonarQube for VS Code includes a Quick Install button when running an agent-enabled IDE, which automatically sets the correct port configuration. See the Setup the SonarQube MCP Server article in our VS Code documentation for instructions.
Here are some example configurations; note that you'll need to specify the SONARQUBE_IDE_PORT:
{
"sonarqube": {
"command": "docker",
"args": [
"run",
"-i",
"--name",
"sonarqube-mcp-server",
"--rm",
"-e",
"SONARQUBE_TOKEN",
"-e",
"SONARQUBE_ORG",
"-e",
"SONARQUBE_IDE_PORT",
"mcp/sonarqube"
],
"env": {
"SONARQUBE_TOKEN": "<YourSonarQubeToken>",
"SONARQUBE_ORG": "<YourSonarQubeOrganization>",
"SONARQUBE_IDE_PORT": "<Your-IDE-Port>"
}
}
}Use this code sample when using Docker to configure your MCP server for integrating with SonarQube Server or SonarQube Community Build.
{
"sonarqube": {
"command": "docker",
"args": [
"run",
"-i",
"--name",
"sonarqube-mcp-server",
"--rm",
"-e",
"SONARQUBE_TOKEN",
"-e",
"SONARQUBE_URL",
"-e",
"SONARQUBE_IDE_PORT",
"mcp/sonarqube"
],
"env": {
"SONARQUBE_TOKEN": "<YourSonarQubeUserToken>",
"SONARQUBE_URL": "<YourSonarQubeURL>",
"SONARQUBE_IDE_PORT": "<64120-64130>"
}
}
}User tokens are required when setting up connected mode or an MCP Server between SonarQube Server and SonarQube for IDE. Note that binding will not function properly if SonarQube Server project tokens or global tokens are used during the setup process.
Analyzing code snippets in the agent
Once the MCP Server is set up, you can analyze code snippets directly within your agent context.
Example in Cursor
In the chat, you ask 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.
New and improved SonarQube MCP Server Tools are continuously being added. If the tool you want is not available, remember you can ask the IDE to filter results to help investigate and mange the issues it reports.
Using the MCP tools
After you Configure your SonarQube MCP server, you can open the chat view in your AI-enabled IDE and start using the MCP server. You'll see your custom tools available, and you can even get suggestions for how to use them. See the Tools page for a full list of built-in tools.
Last updated
Was this helpful?

