From sonarqube
Find files with low test coverage and inspect uncovered lines in a SonarQube project (project key optional when MCP integration already defines the default project)
npx claudepluginhub sonarsource/sonarqube-agent-plugins --plugin sonarqube[project-key?] [--max n] [--file key] [--pr id]# SonarQube — Coverage Identify files with insufficient test coverage and pinpoint the exact lines that need tests. ## Usage ## Instructions ### Step 1: Resolve the project key (only when needed) MCP tools sometimes **do not require** `projectKey` after **`sonar integrate claude`** has stored the default project for this workspace. Resolve a key only when you must pass it (tool schema requires it, or the user targets another project): - If `$ARGUMENTS` contains a project key, use it. - Otherwise look for `sonar.projectKey` in `sonar-project.properties` at the repo root. - If still n...
/coverageAnalyzes test coverage by running npm coverage scripts, reports on lines, branches, functions and gaps, prioritizes by risk, and recommends specific tests to add. Supports module paths and --recommend.
/coverageRuns Python test coverage analysis on unit tests (or integration with flag), identifies gaps and low-coverage files, generates summary with recommendations and optional HTML report. Supports --text, --integration, --gaps.
/coverageRuns test coverage analysis for auto-detected Drupal or Next.js projects using PHPUnit or Jest, displays coverage percentage and uncovered code, generates JSON and HTML reports.
/coverageAnalyzes test coverage for projects or specific files/directories, generates markdown report with metrics, directory breakdowns, low-coverage files, uncovered lines, and prioritized test recommendations. Supports --target flag.
/coverageReport on lineage coverage and identify symbols without full traceability
Identify files with insufficient test coverage and pinpoint the exact lines that need tests.
/sonarqube:coverage # worst-covered files in the current project
/sonarqube:coverage my-project # worst-covered files in a specific project
/sonarqube:coverage my-project --max 50 # only files with coverage <= 50%
/sonarqube:coverage my-project --file src/auth/login.py # line-by-line detail for one file
MCP tools sometimes do not require projectKey after sonar integrate claude has stored the default project for this workspace. Resolve a key only when you must pass it (tool schema requires it, or the user targets another project):
$ARGUMENTS contains a project key, use it.sonar.projectKey in sonar-project.properties at the repo root.projectKey in MCP calls and rely on the integration default.$ARGUMENTS| Flag | Meaning |
|---|---|
--max <n> | Only return files with coverage ≤ n% (maps to maxCoverage) |
--pr <id> | Analyse a pull request instead of the main branch |
--file <key> | Skip the file list and go straight to line-by-line detail for this file key |
--file)Call mcp__sonarqube__search_files_by_coverage. Include projectKey only if you resolved one in Step 1 and the tool requires it; otherwise omit it.
{
"projectKey": "<only-if-required>",
"maxCoverage": <n>, // if --max was given
"pullRequest": "<id>", // if --pr was given
"pageSize": 20
}
Omit projectKey from the payload entirely when the default project from integration applies. Omit unused optional fields.
Present results as a table sorted by coverage ascending:
## Coverage — `my-project`
Files with lowest coverage (worst first):
| File | Coverage |
| ------------------- | -------- |
| src/auth/login.py | 12.5% |
| src/utils/crypto.py | 23.0% |
| src/api/routes.py | 41.8% |
If no files are returned (all files exceed the threshold), say: "All files meet the coverage threshold."
Then offer to drill in:
"Ask me to inspect any of these files for uncovered lines, or run /sonarqube:coverage --file <file-key> (add a project key only if needed)."`
--file <key> given, or user asks to inspect a file)Call mcp__sonarqube__get_file_coverage_details:
{
"key": "<file-key>",
"pullRequest": "<id>" // if --pr was given
}
The file key format is <projectKey>:<path>, e.g. my-project:src/auth/login.py.
If the user provides just a path, prepend the resolved project key when you have one; if the integration supplies the default project, the detail tool may accept the path or key format your MCP schema documents — follow the tool schema.
Present uncovered and partially covered lines:
## Coverage Detail — `src/auth/login.py`
Overall coverage: **12.5%**
### Uncovered lines
Lines with no test coverage: 14, 15, 23, 45–52, 67
### Partially covered branches
| Line | Covered branches | Total branches |
| ---- | ---------------- | -------------- |
| 30 | 1 | 2 |
| 61 | 0 | 2 |
If the file is fully covered, say: "All lines in this file are covered."
/sonarqube:analyze <file>."/sonarqube:quality-gate (add a project key only if you are not using the integration default)."If the MCP server is unavailable or the project key is not found:
Unable to reach the SonarQube MCP Server, or project key not found.
**Possible causes:**
- MCP server not registered — run `/sonarqube:integrate` so `sonar integrate claude` can wire the SonarQube MCP Server, then restart Claude Code
- Credentials not configured — run `/sonarqube:integrate`
- Project key is wrong or no default project in MCP config — pass an explicit key, or verify `sonar-project.properties` / re-run `/sonarqube:integrate` for this project