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
fastmcppackage 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:
- 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). - 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_TOKENand omit theheadersblock (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
- Call
search_issueswithproject="Agrega-Server"to retrieve open issues. - For each issue, call
get_issue_context(issue_key). - Use the
markdownfield to brief an LLM, and the structuredissue/rulesections 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
Authorizationheader is accepted by your SonarQube instance and that your token has permission to view the project/issue. - You can invoke the
configuration_statustool (only available when the server is misconfigured) to diagnose missing environment variables. - Enable HTTP-level logging by setting
HTTPX_LOG_LEVEL=debugwhen running the process for deeper visibility.
Roadmap / Ideas
- Surface code snippets when available via the
flowsmetadata. - Cache rule metadata to reduce duplicate requests during long sessions.
- Add tooling metrics (latency, error rates) to help identify flaky integrations.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file iflow_mcp_sertaykabuk_sonarqube_mcp-0.1.1.tar.gz.
File metadata
- Download URL: iflow_mcp_sertaykabuk_sonarqube_mcp-0.1.1.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4202acc7fe3c6ce888b97fb02f5c52b909893b7f02dc1f9b3121de1f51f8dc5
|
|
| MD5 |
02f4d0b60537f4e5626eb2ae08d8bcfd
|
|
| BLAKE2b-256 |
7fd72eeecbe321192bf956e34aac88b65ad6197aebe0be2cb7b5363f5b4aed9a
|
File details
Details for the file iflow_mcp_sertaykabuk_sonarqube_mcp-0.1.1-py3-none-any.whl.
File metadata
- Download URL: iflow_mcp_sertaykabuk_sonarqube_mcp-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a8cee9c688320f803c15135d8f283e6f1f6e38f9c306c9cb5822327af008a24
|
|
| MD5 |
52dbcfe1fcb5719e7f52d033b1d16be5
|
|
| BLAKE2b-256 |
3fd4203b3bf90c6a90da809339e3e935a48dc62a88b57bf2d74b3f5dbc637715
|