SonarQube MCP Server
Supports SonarCloud via organization filtering, enabling similar capabilities as SonarQube for cloud-based code quality and security analysis.
Provides tools for interacting with SonarQube to list projects, retrieve project metrics, manage code quality issues, analyze security vulnerabilities, check quality gates, and view historical analysis trends.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@SonarQube MCP Server Show quality metrics for project 'my-app'"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
SonarQube MCP Server
A Model Context Protocol (MCP) server that provides AI assistants with access to SonarQube code quality, security, and project analytics data.
Features
Project Listing: Get comprehensive project information with quality metrics
Project Metrics: Fetch detailed quality metrics including coverage, duplication, maintainability
Issue Management: List and analyze code quality issues with filtering capabilities
Security Analysis: Get detailed security vulnerability and hotspot information
Quality Gates: Check quality gate status and conditions
Historical Analysis: View project evolution and quality trends over time
Related MCP server: sonarqube-mcp
Installation
npm (Recommended)
# Global installation
npm install -g mcp-sonarqube
# Local installation in your project
npm install mcp-sonarqubeFrom Source
Clone the repository:
git clone https://github.com/akhilthomas236/sonarqube-mcp-npm.git
cd sonarqube-mcpInstall dependencies:
npm installBuild the project:
npm run buildQuick Start
1. Install the package
npm install -g mcp-sonarqube2. Set up environment variables
export SONARQUBE_URL="http://your-sonarqube-instance:9000"
export SONARQUBE_TOKEN="your-sonarqube-token"3. Run as MCP Server
mcp-sonarqube4. VS Code Integration
Create .vscode/mcp.json in your workspace:
{
"servers": {
"sonarqube": {
"command": "npx",
"args": ["mcp-sonarqube"],
"env": {
"SONARQUBE_URL": "http://localhost:9000",
"SONARQUBE_TOKEN": "your-sonarqube-token-here"
}
}
}
}Then use with GitHub Copilot:
@copilot List all projects in our SonarQube instance
@copilot Show me quality metrics for project "my-app"
@copilot What are the critical security vulnerabilities in project "api-service"?Getting a SonarQube Token
Log in to your SonarQube instance
Go to User > My Account > Security
Generate a new token with appropriate permissions
Use this token as your
SONARQUBE_TOKEN
Usage
Running the Server
npm startThe server runs on stdio transport and communicates via the Model Context Protocol.
Available Tools
1. list_projects
Lists all projects in your SonarQube instance with key metrics.
Parameters:
search(optional): Filter projects by name or keyqualityGate(optional): Filter by quality gate status (OK, WARN, ERROR)organization(optional): Filter by organization (SonarCloud)
2. get_project_metrics
Get comprehensive metrics for a specific project.
Parameters:
projectKey(required): The SonarQube project keybranch(optional): Branch name (defaults to main branch)metrics(optional): Comma-separated list of specific metrics
3. list_issues
List code quality issues with filtering options.
Parameters:
projectKey(required): The SonarQube project keybranch(optional): Branch nametypes(optional): Issue types (BUG, VULNERABILITY, CODE_SMELL)severities(optional): Severities (BLOCKER, CRITICAL, MAJOR, MINOR, INFO)statuses(optional): Statuses (OPEN, CONFIRMED, REOPENED, RESOLVED, CLOSED)assignees(optional): Assignee usernamestags(optional): Issue tagslimit(optional): Maximum number of issues (default: 50)
4. get_security_vulnerabilities
Get detailed security vulnerability analysis.
Parameters:
projectKey(required): The SonarQube project keybranch(optional): Branch nameseverities(optional): Filter by severitiesstatuses(optional): Filter by statusesassigned(optional): Filter by assigned/unassignedlimit(optional): Maximum number of vulnerabilities (default: 50)
5. get_quality_gate
Check quality gate status and conditions.
Parameters:
projectKey(required): The SonarQube project keybranch(optional): Branch name
6. get_analysis_history
View historical analysis data and trends.
Parameters:
projectKey(required): The SonarQube project keybranch(optional): Branch namefrom(optional): Start date (YYYY-MM-DD)to(optional): End date (YYYY-MM-DD)limit(optional): Maximum number of analyses (default: 10)
Development
Project Structure
src/
├── index.ts # MCP server entry point
├── services/
│ └── sonarqube-client.ts # SonarQube API client
├── tools/ # MCP tool implementations
│ ├── list-projects.ts
│ ├── get-project-metrics.ts
│ ├── list-issues.ts
│ ├── get-security-vulnerabilities.ts
│ ├── get-quality-gate.ts
│ └── get-analysis-history.ts
├── types/
│ └── sonarqube.ts # TypeScript type definitions
└── utils/
└── formatting.ts # Utility functionsScripts
npm run build- Build the TypeScript projectnpm run dev- Run in development mode with ts-nodenpm start- Start the MCP servernpm test- Run tests
Adding New Tools
Create a new tool file in
src/tools/Implement the tool schema and handler function
Add the tool to the imports and tools array in
src/index.tsAdd a case for the tool in the CallTool handler
VS Code Integration
To use this MCP server with VS Code and Copilot:
Method 1: Using npx (Recommended)
Create
.vscode/mcp.jsonin your workspace:
{
"servers": {
"sonarqube": {
"command": "npx",
"args": ["mcp-sonarqube"],
"env": {
"SONARQUBE_URL": "http://localhost:9000",
"SONARQUBE_TOKEN": "your-token-here"
}
}
}
}Method 2: Using local installation
If you have the package installed locally:
{
"servers": {
"sonarqube": {
"command": "node",
"args": ["./node_modules/mcp-sonarqube/dist/index.js"],
"env": {
"SONARQUBE_URL": "http://localhost:9000",
"SONARQUBE_TOKEN": "your-token-here"
}
}
}
}Method 3: Global installation
If you have the package installed globally:
{
"servers": {
"sonarqube": {
"command": "mcp-sonarqube",
"env": {
"SONARQUBE_URL": "http://localhost:9000",
"SONARQUBE_TOKEN": "your-token-here"
}
}
}
}Install the MCP extension for VS Code
The SonarQube tools will be available in Copilot Chat
Examples
Check Project Quality
@copilot Use the SonarQube tools to give me a quality overview of project "my-app"Security Analysis
@copilot Show me all security vulnerabilities in project "my-app" that are CRITICAL or BLOCKERQuality Gate Status
@copilot Check if project "my-app" passes its quality gateHistorical Trends
@copilot Show me the quality trends for project "my-app" over the last monthError Handling
The server provides detailed error messages for common issues:
Missing environment variables
Invalid project keys
SonarQube connection issues
Authentication failures
Invalid parameters
Troubleshooting
"Server exited before responding to initialize request"
If you encounter this error in VS Code or when using the MCP server, try these solutions:
Test the server directly first:
# Test if the server starts correctly node dist/index.js # Should output: "SonarQube MCP Server started successfully" # Test with an MCP initialize request echo '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test", "version": "1.0.0"}}}' | node dist/index.jsFor VS Code integration issues:
Make sure the package is installed globally:
npm install -g mcp-sonarqubeTry using the full path instead of
npx:{ "servers": { "sonarqube": { "command": "node", "args": ["/path/to/global/node_modules/mcp-sonarqube/dist/index.js"], "env": { "SONARQUBE_URL": "http://localhost:9000", "SONARQUBE_TOKEN": "your-token" } } } }Restart VS Code after changing the MCP configuration
For npx issues:
Clear npm cache:
npm cache clean --forceReinstall the package:
npm uninstall -g mcp-sonarqube && npm install -g mcp-sonarqubeCheck Node.js version (requires Node.js 18+)
Environment variable issues:
Ensure
SONARQUBE_URLandSONARQUBE_TOKENare properly setTest connection:
curl -u your-token: $SONARQUBE_URL/api/projects/search
SonarQube API Parameter Errors
If you encounter API errors related to invalid parameters:
"additionalFields components must be one of..."
This error has been fixed in version 1.0.2+
Update to the latest version:
npm update -g mcp-sonarqubeThe server now uses valid
additionalFieldsvalues:rules,users,comments
Invalid parameter values:
Check that your SonarQube version supports the API endpoints being used
Some parameters may have different valid values in different SonarQube versions
Refer to your SonarQube instance's API documentation at:
{SONARQUBE_URL}/web_api
Network and Authentication Issues
Connection errors:
Verify SonarQube URL is accessible
Check firewall settings
Ensure SonarQube server is running
Authentication errors:
Verify token is valid and has appropriate permissions
Check token expiration
Ensure token has at least "Browse" permission on projects
SSL/TLS issues:
For self-signed certificates, you may need to set
NODE_TLS_REJECT_UNAUTHORIZED=0(not recommended for production)
Contributing
Fork the repository
Create a feature branch
Make your changes
Add tests if applicable
Submit a pull request
License
MIT License - see LICENSE file for details
Links
npm Package: https://www.npmjs.com/package/mcp-sonarqube
GitHub Repository: https://github.com/akhilthomas236/sonarqube-mcp-npm
SonarQube Documentation: https://docs.sonarqube.org/
Model Context Protocol: https://modelcontextprotocol.io/
Support
For issues and questions:
Check the SonarQube API documentation
Verify your token permissions
Ensure network connectivity to SonarQube
Check the server logs for detailed error messages
Create an issue on GitHub
Available Tools
7 toolsget_analysis_historyB
Get historical analysis data and trends for a SonarQube project
Inputs: projectKey (required), branch, from, to, +1 more.
get_project_repositoryB
Get git repository information and source code management details for a SonarQube project
Inputs: projectKey (required), includeBranches.
get_quality_gateB
Get quality gate status and conditions for a SonarQube project
Inputs: projectKey (required), branch.
get_security_vulnerabilitiesC
Get detailed security vulnerability analysis from a SonarQube project
Inputs: projectKey (required), branch, severities, statuses, +2 more.
list_issuesB
List code quality issues from a SonarQube project with filtering options
Inputs: projectKey (required), branch, types, severities, +4 more.
sonarqube_get_project_metricsA
Retrieve comprehensive project quality metrics including coverage, technical debt, complexity, and issue counts
Inputs: projectKey (required), branch, metrics.
sonarqube_list_projectsB
List all accessible SonarQube projects with their basic information and quality status
Inputs: organization, search, qualityGate.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
Each tool targets a distinct SonarQube resource: project listing, metrics, quality gate, issues, security vulnerabilities, analysis history, and repository info. No overlap in purpose.
Most tools use verb_noun snake_case (e.g., get_analysis_history), but two tools include a 'sonarqube_' prefix (sonarqube_get_project_metrics, sonarqube_list_projects), breaking the pattern. The convention is mixed but still readable.
7 tools is well-scoped for a SonarQube analysis server, covering the primary read operations without redundancy.
Covers major reading operations (metrics, issues, security, quality gate), but misses some likely endpoints like 'get_project' for a single project or 'get_issue' for a specific issue. Minor gaps that agents can work around.
Maintenance
Related MCP Connectors
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
The Cortex MCP server provides read-only access to real-time engineering context from the Cortex developer portal, allowing AI coding assistants to answer natural language questions about your organization's catalog (microservices, libraries, domains, teams, infrastructure), scorecards (engineering standards and best practices), initiatives (goals and deadlines), and Engineering Intelligence metrics. It includes tools for querying documentation, tracking personal entities, and accessing AI-assisted insights across the entire Cortex ecosystem.
MCP server for AI access to SmartBear tools, including BugSnag, Reflect, Swagger, PactFlow, QTM4J.
MCP server for Sentry - error monitoring, issue tracking, and debugging for AI assistants
Related MCP Servers
- FlicenseAqualityDmaintenanceA read-only MCP server that provides AI assistants with structured access to SonarQube projects, issues, metrics, and rules. It enables safe analysis of code quality and security findings through a set of validated, safety-first tools.6-
- AlicenseAqualityCmaintenanceAn MCP server for SonarQube that enables LLM agents to discover projects, analyze code quality metrics, check Quality Gate status, search issues with filters, and rank projects by worst-performing metrics. It provides read-only, safe access to SonarQube instances with structured outputs and error handling.590 PyPI1MIT
- AlicenseAqualityDmaintenanceA Model Context Protocol (MCP) server for interacting with SonarQube code quality platform.31MIT
- AlicenseCqualityDmaintenanceA Python MCP server for SonarQube, enabling AI agents to query projects, issues, quality gates, coverage, and security hotspots.13MIT