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

  • 18 MCP Tools for comprehensive SonarQube management
  • Multi-instance support for managing multiple SonarQube servers
  • Issue management - list, transition, comment, bulk operations
  • Quality gates - check status, validate against goals
  • Metrics - coverage, ratings, file-level analysis
  • Project detection - auto-detect from git remote

Installation

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

# Using pip
pip install sonar-mcp

Configuration

Configure the MCP server in your Claude Code settings:

{
  "mcpServers": {
    "sonar-mcp": {
      "command": "python",
      "args": ["-m", "sonar_mcp"],
      "env": {
        "SONAR_TOKEN": "your-sonarqube-token",
        "SONAR_URL": "https://sonarqube.example.com"
      }
    }
  }
}

Environment Variables

Variable Description Required
SONAR_TOKEN SonarQube API token Yes
SONAR_URL SonarQube server URL Yes

Available Tools

Instance Management

  • sonar_manage_instance - Create, update, delete, or test instances
  • sonar_list_instances - List all configured instances
  • sonar_select_instance - Set the active instance

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

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

Quality Gates

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

Metrics

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

Rules

  • sonar_get_rule - Get rule details and remediation guidance

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 specific test file
pytest tests/unit/test_client.py -v

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

Linting

# Check linting
ruff check src/ tests/

# Auto-fix issues
ruff check src/ tests/ --fix

# Format code
ruff format src/ tests/

# Type checking
mypy src/

Quality Gates

Before committing, ensure all quality gates pass:

# All-in-one check
ruff check src/ tests/ && \
ruff format --check src/ tests/ && \
mypy src/ && \
pytest tests/ -v --cov=src/sonar_mcp --cov-fail-under=80

Architecture

src/sonar_mcp/
├── __init__.py          # Package initialization
├── __main__.py          # Entry point
├── server.py            # MCP server core
├── instance_manager.py  # Multi-instance management
├── types.py             # Type definitions
├── auth/                # Token management
├── client/              # SonarQube API client
├── config/              # Configuration models
├── models/              # Data models (Issue, Metric, Project)
├── tools/               # MCP tools (18 total)
└── utils/               # Utilities (logging)

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.0.tar.gz (53.9 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.0-py3-none-any.whl (59.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sonar_mcp-1.0.0.tar.gz
  • Upload date:
  • Size: 53.9 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.0.tar.gz
Algorithm Hash digest
SHA256 d74efb45a0474ba34a50c789712a4bb6aa1f75b4c64cda6f3abb19259dc3325d
MD5 2c8dfabdf7a4cfc442c572db028c2c35
BLAKE2b-256 deed13cb57ec1d48a8b618695a1b1bf5b29ee68d5381e90cbf49c942a2d99be6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sonar_mcp-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 59.1 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1c45182b428b5a6b827802bec0ee9c09d82513f5a428249b4c9532043b836f9e
MD5 2d0e1163227ef1f850df075b22fac1d4
BLAKE2b-256 1f595ff898d644f994c7461dc3cdd32336ed52d5f95a8688f9a7db453171777c

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