Skip to main content

MCP server for SonarQube code quality platform

Project description

SonarQube MCP Server

PyPI version Python 3.11+ License: MIT Coverage

A Model Context Protocol (MCP) server for interacting with SonarQube code quality platform.

Features

  • 24 MCP Tools organized into 7 categories with lazy loading
  • 6 MCP Prompts for code review, security audits, and quality reports
  • 7 MCP Resources for browseable URI-based access to SonarQube data
  • Multi-instance support for managing multiple SonarQube servers
  • HTTP transport modes - stdio, SSE, and streamable-http

Installation

# Using pip
pip install sonar-mcp

# Using uv (recommended)
uv pip install sonar-mcp

Quick Start

1. Configure for Claude Code

Add to your Claude Code MCP settings:

{
  "mcpServers": {
    "sonar-mcp": {
      "command": "sonar-mcp",
      "env": {
        "SONAR_TOKEN": "your-sonarqube-token",
        "SONAR_URL": "https://sonarqube.example.com"
      }
    }
  }
}

2. Use the Tools

The server uses hierarchical tool loading to minimize context usage:

# First, list available categories
sonar_list_categories()

# Enable the categories you need
sonar_enable_category("project")
sonar_enable_category("issue")

# Now use the tools
sonar_list_projects()
sonar_list_issues(project="my-project")

Running the Server

Stdio Mode (Default)

For Claude Code and other MCP clients that use stdio transport:

sonar-mcp
# or
python -m sonar_mcp

Streamable HTTP Mode

For web-based clients or remote access:

# Start server on default port 8000
sonar-mcp --transport streamable-http

# Custom host and port
sonar-mcp --transport streamable-http --host 0.0.0.0 --port 3000

# Using environment variables
SONAR_MCP_TRANSPORT=streamable-http SONAR_MCP_PORT=3000 sonar-mcp

SSE Mode (Server-Sent Events)

For clients that support SSE transport:

sonar-mcp --transport sse --port 8000

Command Line Options

Option Description Default
--transport Transport protocol: stdio, sse, streamable-http stdio
--host Host address for HTTP transports 127.0.0.1
--port Port for HTTP transports 8000
--all-tools Load all tools at startup (legacy mode) false
--version Show version and exit -

Environment Variables

Variable Description Required
SONAR_TOKEN SonarQube API token Yes
SONAR_URL SonarQube server URL Yes
SONAR_MCP_TRANSPORT Default transport mode No
SONAR_MCP_HOST Default host for HTTP No
SONAR_MCP_PORT Default port for HTTP No
SONAR_MCP_ALL_TOOLS Load all tools at startup No

Running the Server

Stdio Mode (Default)

For Claude Code and other MCP clients that use stdio transport:

sonar-mcp
# or
python -m sonar_mcp

Streamable HTTP Mode

For web-based clients or remote access:

# Start server on default port 8000
sonar-mcp --transport streamable-http

# Custom host and port
sonar-mcp --transport streamable-http --host 0.0.0.0 --port 3000

# Using environment variables
SONAR_MCP_TRANSPORT=streamable-http SONAR_MCP_PORT=3000 sonar-mcp

SSE Mode (Server-Sent Events)

For clients that support SSE transport:

sonar-mcp --transport sse --port 8000

Command Line Options

Option Description Default
--transport Transport protocol: stdio, sse, streamable-http stdio
--host Host address for HTTP transports 127.0.0.1
--port Port for HTTP transports 8000
--all-tools Load all tools at startup (legacy mode) false
--version Show version and exit -

Available Tools

Meta-Tools (Always Available)

These 3 tools are always loaded for category management:

  • sonar_list_categories - List available tool categories
  • sonar_enable_category - Enable tools in a category
  • sonar_disable_category - Disable a category

Category: instance (4 tools)

Instance management for SonarQube server connections:

  • sonar_list_instances - List all configured instances
  • sonar_manage_instance - Create, update, delete instances
  • sonar_select_instance - Set the active instance
  • sonar_test_connection - Test instance connectivity

Category: project (3 tools)

Project operations:

  • sonar_list_projects - List all accessible projects
  • sonar_get_project - Get project details and metrics
  • sonar_detect_project - Auto-detect project from current directory

Category: issue (5 tools)

Issue management:

  • sonar_list_issues - List issues with filtering (severity, type, status)
  • sonar_get_issue - Get detailed issue information
  • sonar_transition_issue - Change issue status (resolve, falsepositive, etc.)
  • sonar_add_comment - Add a comment to an issue
  • sonar_bulk_transition - Bulk transition multiple issues

Category: quality (2 tools)

Quality gate operations:

  • sonar_get_quality_gate - Get quality gate status (OK/ERROR)
  • sonar_check_goals - Validate against quality goals

Category: metrics (3 tools)

Metrics retrieval:

  • sonar_get_metrics - Get project metrics
  • sonar_get_coverage - Get coverage percentage
  • sonar_get_file_coverage - Get file-level coverage details

Category: rules (1 tool)

Rule information:

  • sonar_get_rule - Get rule details and remediation guidance

Category: task (3 tools)

Async task management:

  • sonar_get_task - Get task status
  • sonar_list_tasks - List background tasks
  • sonar_cancel_task - Cancel a running task

MCP Resources

Browseable URI-based access to SonarQube data:

URI Pattern Description
sonarqube://projects List all projects
sonarqube://projects/{key} Get project details
sonarqube://projects/{key}/issues Get project issues
sonarqube://projects/{key}/issues/{severity} Get issues by severity
sonarqube://projects/{key}/metrics Get project metrics
sonarqube://projects/{key}/quality-gate Get quality gate status

MCP Prompts

Reusable prompt templates for code quality workflows:

Prompt Description
code_review Review code issues and suggest fixes
fix_issues Generate fix recommendations for issues
quality_report Generate quality report for a project
quality_goals Check project against quality goals
security_audit Perform security vulnerability audit
vulnerability_fix Generate fixes for security vulnerabilities

Development

Setup

# Clone the repository
git clone https://github.com/wadew/sonar-mcp.git
cd sonar-mcp

# Create virtual environment
uv venv
source .venv/bin/activate

# Install dependencies
uv pip install -e ".[dev]"

Testing

# Run all tests with coverage
pytest tests/ -v --cov=src/sonar_mcp --cov-report=term-missing

# Run with coverage enforcement (80% minimum)
pytest tests/ -v --cov=src/sonar_mcp --cov-fail-under=80

Linting

# Check linting
ruff check src/ tests/

# Format code
ruff format src/ tests/

# Type checking
mypy src/

License

MIT License - see LICENSE for details.

Contributing

  1. Follow TDD (Test-Driven Development) - write tests first
  2. Maintain 80% coverage on ALL modules
  3. Ensure all linting and type checks pass
  4. Use conventional commits

See CONTRIBUTING.md for detailed guidelines.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sonar_mcp-1.0.1.tar.gz (55.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sonar_mcp-1.0.1-py3-none-any.whl (59.8 kB view details)

Uploaded Python 3

File details

Details for the file sonar_mcp-1.0.1.tar.gz.

File metadata

  • Download URL: sonar_mcp-1.0.1.tar.gz
  • Upload date:
  • Size: 55.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for sonar_mcp-1.0.1.tar.gz
Algorithm Hash digest
SHA256 e14f8e6ecfbc4cf654cebda39fa3a0e73bafe8fb2bd3b07c7a50750c07120ed8
MD5 22f9d4fac99ac0aba07c4a3b89d97934
BLAKE2b-256 ceb2cbee531cbcfe2fb5576fe2c1f4400d0440b5968d978352c0d2c2a034f4fe

See more details on using hashes here.

File details

Details for the file sonar_mcp-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: sonar_mcp-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 59.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for sonar_mcp-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4f724f05798e61e2002d564b92e20164ec26249fcb41856aab3afca911e3385b
MD5 ca7ea19b6ccfeb3d75d4557d339689c8
BLAKE2b-256 49ff5a6224fbf159f35f7b114739e41ac01b2d3507d7fd902a07d868b170b647

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page