SonarQube MCP Server is an official Model Context Protocol (MCP) server provided by SonarSource, used to implement code quality and security analysis in AI agents. It can integrate seamlessly with SonarQube Server or SonarQube Cloud, and supports analyzing code snippets directly within the agent context.
Purpose: To bring SonarQube's code quality and security capabilities into AI agents, enabling agents to call SonarQube's code analysis, issue query, quality gate, and other functions while performing tasks.
Main capabilities:
- Integration with SonarQube Server or SonarQube Cloud.
- Support for analyzing code snippets within the agent context (analyze_code_snippet).
- Provides toolsets to be enabled on demand; by default, only important toolsets are enabled; the projects toolset is always enabled automatically.
- Supports read-only mode (SONARQUBE_READ_ONLY).
- Supports workspace mounting (/app/mcp-workspace). When a mount is detected, the server can read files directly from disk, and file contents do not pass through the agent context, thereby reducing context bloat; in this case, analyze_code_snippet requires filePath, and fileContent is no longer used.
- If the organization has permissions, run_advanced_code_analysis is available when the mount is active.
- Supports integration with SonarQube for IDE; SONARQUBE_IDE_PORT must be set; when running in a Linux container, --network=host must be added to connect to the IDE embedded server.
- Supports two transport modes: Stdio and Streamable HTTP; in Streamable HTTP mode, the server is stateless, and each request must carry the Authorization: Bearer <token> header.
- Provides unauthenticated service endpoints (only in Streamable HTTP mode, for monitoring, orchestration, and client compatibility checks).
- Supports custom certificate mounting (.crt PEM/DER, .pem PEM).
Usage:
- Quick configuration: A configuration suitable for the target AI agent client can be generated via the SonarQube MCP Server configuration generator.
- Container image: sonarsource/sonarqube-mcp; use --pull=always for automatic updates, or pin a version tag (such as sonarsource/sonarquube-mcp:1.19.0.2785).
- Supports multiple client installation methods, including Antigravity MCP Store, VS Code, Windsurf plugin, Zed extension, Gemini CLI extension (migrated to the sonarqube-agent-plugins repository), GitHub Copilot coding agent, Copilot CLI, Codex, etc.; configuration methods differ by client and involve files such as mcp_config.json, ~/.codex/config.toml, ~/.copilot/mcp-config.json, and .kiro/settings/mcp.json.
- Environment variables:
- SonarQube Cloud: SONARQUBE_TOKEN, SONARQUBE_ORG; for the US region, optionally SONARQUBE_URL=https://sonarqube.us。
- SonarQube Server: SONARQUBE_TOKEN (USER type), SONARQUBE_URL.
- Whether it connects to Cloud or Server is determined by whether SONARQUBE_ORG exists: if set, it is Cloud; otherwise, it is Server.
- Security practices: avoid hardcoding tokens in command-line arguments (they will be saved to shell history); use environment variables; do not commit tokens in configuration files to version control, and use environment variable substitution where possible.
Applicable scenarios:
- AI agents need code quality and security checks in the development process.
- Local development and single-user scenarios (Stdio transport recommended).
- Multi-user production deployment (HTTPS Streamable HTTP recommended, requires an SSL certificate).
- Integration with IDEs to enhance development workflows.
- Use in CI/CD via the GitHub Copilot coding agent.
Limitations:
- SonarQube Server version requirement: 2025.1 (SQS) or 25.1 (Community Build) or higher; at startup, if the version is too old, it will error and exit (for example, older versions 9.x/10.x and Community Build 24.x are not supported). SonarQube Cloud is not subject to this check.
- Connecting to SonarQube Server must use a USER type token; project tokens or global tokens will not work.
- In Streamable HTTP mode, if SONARQUBE_ORG is set at startup, the client should not send the SONARQUBE_ORG header, otherwise an error will occur; if it is not set, then each request must provide the SONARQUBE_ORG header.
- The SONARQUBE_TOOLSETS and SONARQUBE_READ_ONLY request headers can only narrow the scope, and cannot expand or remove the restrictions set at server startup.
- The SONARQUBE_TOKEN request header is deprecated and will be removed; migration to Authorization: Bearer <token> should be made.
- By default binds to 127.0.0.1; in containers, you need to set SONARQUBE_HTTP_HOST=0.0.0.0 and set SONARQUBE_MCP_IN_CONTAINER=true (the official image automaticallysets it).
- Unauthenticated service endpoints are only available in Streamable HTTP mode.
- Instructions on running the server from a JAR are not fully provided in the materials.