🐍 🏠 🪟 🐧 🍎 - Retrieve SonarQube project information: current and historical metrics, issues and health status
FastMCP SonarQube Metrics
以下摘录自该仓库的 README(片段) · 在 GitHub 读完整 README →
Overview
This project provides a set of tools for retrieving information about SonarQube projects using the FastMCP (Fast Model Context Protocol) framework. It serves as an interface to SonarQube, allowing users to programmatically access metrics, historical data, and component tree metrics for specified projects. This automated access enables reporting, analysis, and integration of SonarQube data with other systems.
The project distinguishes itself by offering a simplified, message-based approach to interacting with the SonarQube API, abstracting away the complexities of direct API calls and data handling. It's designed for developers, DevOps engineers, and analysts who need to incorporate SonarQube data into their workflows or build custom reporting solutions.
This repository specifically houses the client and server components that facilitate communication and data retrieval. The server exposes tools to fetch data from SonarQube, while the client provides a command-line interface for users to invoke these tools and display the results. Each internal module contributes to this goal by encapsulating specific functionalities, such as API interaction, data processing, and client-server communication.
The client included in the project is only for testing how the code works; we recommend using Claude Desktop or developing your own custom client.
> ***REMEMBER, THIS REPO IS WORK IN PROGRESS, SOME FEATURES MAY NOT BE PERFECT.***
Hosted deployment
A hosted deployment is available on Fronteir AI.
Supported MCP Tools
* get_status: Performs a health check on the configured SonarQube instance.
* create_sonarqube_project: Creates a new SonarQube project. Requires administrator privileges.
* delete_sonarqube_project: Deletes a SonarQube project. Requires administrator privileges. **USE WITH CAUTION!**
* list_projects: Lists all accessible SonarQube projects, optionally filtered by name or key.
* get_sonarqube_metrics: Retrieves specified metrics (bugs, vulnerabilities, code smells, coverage, duplication density) for a given SonarQube project key.
* get_sonarqube_metrics_history: Retrieves historical metrics (bugs, vulnerabilities, code smells, coverage, duplication density) for a given SonarQube project using /api/measures/search_history. Optional date filters can be applied.
* get_sonarqube_component_tree_metrics: Retrieves metric values for all components (e.g., files or directories) in a project using /api/measures/component_tree Automatically handles pagination to retrieve all results.
* get_project_issues: Fetch SonarQube issues for a given project, optionally filtered by type, severity, and resolution status. Returns up to *limit* results (default: 10).
Technology Stack
* **Language:** Python
* **Frameworks:** FastMCP
* **Libraries:** httpx, pydantic, dotenv, asyncio, json, pathlib, typing, base64
* **Tools:** SonarQube API
Directory Structure
Getting Started
Prerequisites
* Python 3.7+
* SonarQube instance with API access
* A SonarQube API token with appropriate permissions
* FastMCP installed (pip install fastmcp)
* httpx installed (pip install httpx)
* pydantic installed (pip install pydantic)
* python-dotenv installed (pip install python-dotenv)
General Build Steps
1. **Clone the repository:** git clone
2. **Navigate to the project directory:** cd fastmcp-sonarqube-metrics
3. **Set up environment variables:** Create a .env file in the project root directory with the following content:
The schema is the same for *OpenAI* and *Groq*, if you want to use *AzureOpenAI*:
Replace with the URL of your SonarQube instance (e.g., http://localhost:9000) and with your SonarQube API token.
4. **Run the server:** python server.py
5. **Run the client:** python client_test.py *(Optionally, only for test)*
6. **Connect to your client:** follow the official documentation
Module Usage
Server (server.py)
The server.py module defines the FastMCP server that exposes tools for retrieving SonarQube metrics. It initializes the server, loads environment variables, defines the available tools, and handles communication with the SonarQube API. To use the server, you need to set the SONARQUBE_URL and SONARQUBE_TOKEN environment variables. The server is started by running the server.py script directly.