Skip to main content

Add your description here

Project description

SonarQube MCP Server

This project packages a Model Context Protocol (MCP) server for AI coding agents that need to investigate and remediate SonarQube issues. The server is built with FastMCP and wraps the official SonarQube REST API to deliver:

  • High-signal issue search results that highlight severity, ownership, and file locations.
  • Detailed remediation context for a specific SonarQube issue, including the associated rule description and fix suggestions.
  • Direct access to rule metadata for bespoke workflows.

🧠 Goal: Provide enough structured context for an agent to understand an issue, locate the offending code, and apply the recommended fix without visiting the SonarQube UI.

Requirements

  • Python 3.12+
  • Access to a SonarQube instance (cloud or self-hosted) with an API token that can read issues and rules.
  • The fastmcp package is already included; no MCP client is bundled.

Configuration

You must configure the base URL of your SonarQube instance. Authentication can be provided in two ways:

  1. Per-user Bearer token via an Authorization: Bearer <token> HTTP header when using the HTTP/SSE transports (recommended – allows each user/agent to have least-privilege access).
  2. A static environment variable token (SONARQUBE_TOKEN) used as a fallback when no header is present (needed for stdio transport where HTTP headers are not available).

Set the following environment variables before starting the server:

Variable Description Example
SONARQUBE_BASE_URL Base URL of your SonarQube instance (no trailing slash) https://sonarqube.internal
SONARQUBE_TOKEN (optional) Fallback personal access token with Browse access to projects. Used only if no Authorization header is supplied. squ_XXXXXXXXXXXXXXXXXXXXXXXXXXXX
SONARQUBE_TIMEOUT (optional) Request timeout in seconds (defaults to 15) 20

You can store these in a .env file or provide them through your process manager.

Installation

uv sync

For development and testing dependencies:

uv sync --extra test

Running the server

By default the server runs over stdio, which is ideal for local MCP clients:

uv run python -m src.main

To expose an HTTP transport, add the appropriate options when you run it:

uv run python -m src.main --transport http --host 0.0.0.0 --port 8765

Supported transports mirror the ones from FastMCP (stdio, http, sse). When using http/sse, send an Authorization header with each request so the server can perform SonarQube calls on behalf of that user:

Authorization: Bearer squ_XXXXXXXXXXXXXXXXXXXXXXXXXXXX

If the header is omitted the server will fall back to SONARQUBE_TOKEN.

Header-based auth example

The server internally inspects incoming headers (via FastMCP's get_http_headers) on every tool call. A simplified example:

from fastmcp import FastMCP
from fastmcp.server.dependencies import get_http_headers

mcp = FastMCP(name="Demo")

@mcp.tool
async def who_am_i() -> dict:
	headers = get_http_headers()
	auth = headers.get("authorization", "") if headers else ""
	return {
		"has_auth": bool(auth),
		"auth_is_bearer": auth.lower().startswith("bearer "),
		"user_agent": headers.get("user-agent") if headers else None,
	}

This mirrors the mechanism used by the SonarQube tools to resolve the active token for each request.

VS Code MCP client configuration

If you are using the VS Code built‑in MCP client (or an extension that reads a mcp.json style manifest), you can prompt the user for their SonarQube token and pass it as a bearer header. Example configuration snippet:

{
	"servers": {
		"sonarqube": {
			"url": "http://localhost:8765/mcp",
			"type": "http",
			"headers": {
				"Authorization": "Bearer ${input:sonarqube_token}"
			}
		}
	},
	"inputs": [
		{
			"id": "sonarqube_token",
			"type": "promptString",
			"description": "SonarQube Token"
		}
	]
}

Notes:

  • The ${input:...} placeholder ensures the token is not stored in plain text in the config file; the user will be prompted in VS Code.
  • If you prefer not to prompt each time, you can instead set the environment variable SONARQUBE_TOKEN and omit the headers block (less granular for multi-user scenarios).
  • When using a remote SonarQube instance over HTTPS behind a corporate CA, ensure your Python environment trusts that CA (e.g. via REQUESTS_CA_BUNDLE / SSL_CERT_FILE).

Available tools

Tool Purpose Key arguments
get_issue_context Fetch a single issue by key, pull its rule, and return a markdown-rich brief plus machine-readable metadata. issue_key (string)
search_issues Wrapper around /api/issues/search that exposes the most common filters and augments each result with the component path. issue_keys, components, severities, issue_statuses, resolutions, types, tags, assignees, languages, created_after, created_before, resolved, sort_field, ascending, page, page_size
get_rule Retrieve raw rule metadata from /api/rules/show. rule_key (string)

All tools return JSON-serialisable dictionaries, making them easy to chain in agent workflows.

Example workflow

  1. Call search_issues with project="Agrega-Server" to retrieve open issues.
  2. For each issue, call get_issue_context(issue_key).
  3. Use the markdown field to brief an LLM, and the structured issue/rule sections to build automated fixes.

Sample API responses from the SonarQube reference instance are provided in sample_search_api_response.json and sample_rule_api_response.json.

Testing

After installing the optional test extra:

uv run python -m pytest

The tests stub external HTTP calls using respx, so they run offline and quickly.

Troubleshooting

  • If the server starts but every tool call fails immediately, ensure the Authorization header is accepted by your SonarQube instance and that your token has permission to view the project/issue.
  • You can invoke the configuration_status tool (only available when the server is misconfigured) to diagnose missing environment variables.
  • Enable HTTP-level logging by setting HTTPX_LOG_LEVEL=debug when running the process for deeper visibility.

Roadmap / Ideas

  • Surface code snippets when available via the flows metadata.
  • Cache rule metadata to reduce duplicate requests during long sessions.
  • Add tooling metrics (latency, error rates) to help identify flaky integrations.

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

iflow_mcp_sertaykabuk_sonarqube_mcp-0.1.0.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file iflow_mcp_sertaykabuk_sonarqube_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: iflow_mcp_sertaykabuk_sonarqube_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_sertaykabuk_sonarqube_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 45d65c7d729b2e2cda0ab9bc2d408ccae38c4e55d831b7d3d99b566ce04c3fd2
MD5 b350345957d86e4758867ade83993963
BLAKE2b-256 939d1f86e077eb9c886faf3520969a1b0e9e74d0c19799910db8b52efe16de4d

See more details on using hashes here.

File details

Details for the file iflow_mcp_sertaykabuk_sonarqube_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: iflow_mcp_sertaykabuk_sonarqube_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_sertaykabuk_sonarqube_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 18df350a310775a33421e6683695fc65e736031b1be79fecf603dfdedb2fa06e
MD5 41834759a451cbe56147eb7d796e5b6c
BLAKE2b-256 e52fd1f795942ff6cefc45c8b8acdc802f2ac9f3e2147d4bb81a73539fa9a6a0

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