Skip to content

🎃 New adapter: SonarQube (code quality, Server or Cloud) #1240

Closed

Description

@helpcodeai

Part of the October Challenge #997.

Why

SonarQube is one of the most widely used code-quality and code-security tools. Teams run it as SonarQube Server (self-hosted, including the free Community Build) or as SonarQube Cloud (formerly SonarCloud). Its Web API exposes projects, quality gate status, issues, measures and analysis history. With an adapter, a user could ask "did the main branch of payments-api pass its quality gate?", "list the open high-severity security issues in project X" or "how has coverage changed since June?". The catalog has GitHub, GitLab and Sentry but no SonarQube (ls packages/backend/src/adapters/*/ | grep -i sonar finds nothing).

Self-hosted vs Cloud

  • Self-hosted AnythingMCP: available in Community and Business. Catalog adapters have no edition gating. SonarQube Cloud and any SonarQube Server reachable on the internet work as they are. A SonarQube Server on a private network or private IP needs its host in SSRF_ALLOWED_HOSTS, because the outbound guard blocks private address space by default (same wording as intl/directus.json:9).
  • AnythingMCP Cloud (DEPLOYMENT_MODE=cloud): available, but only for SonarQube Cloud (sonarcloud.io, or sonarqube.us for the US region) or a SonarQube Server that is publicly reachable. Private-network servers cannot be reached from Cloud. On Cloud trial plans, installs count toward the trial's connector limit (license-guard.service.ts:75-92).
  • Who can use it: any role except VIEWER can install it (adapters.controller.ts:306). The connector and its encrypted token belong to the installer's organization. The token sees only the projects its SonarQube user can browse.

What to build

packages/backend/src/adapters/intl/sonarqube.json, one adapter for both SonarQube Server and SonarQube Cloud. Start with npm run adapter:new -- sonarqube --region intl --auth BEARER_TOKEN.

Tool Endpoint Expected hints
sonarqube_list_projects GET /components/search with fixed qualifiers=TRK, organization=$SONARQUBE_ORGANIZATION (q, p, ps) read-only
sonarqube_get_quality_gate_status GET /qualitygates/project_status (projectKey, branch, pullRequest) read-only
sonarqube_get_measures GET /measures/component (component, metricKeys required, branch, pullRequest) read-only
sonarqube_get_measures_history GET /measures/search_history (component, metrics required, from, to, branch, p, ps) read-only
sonarqube_search_issues GET /issues/search (componentKeys, organization, issueStatuses, impactSeverities, impactSoftwareQualities, createdAfter, assigned, branch, pullRequest, p, ps) read-only
sonarqube_list_project_analyses GET /project_analyses/search (project required, category, from, to, p, ps) read-only
sonarqube_list_branches GET /project_branches/list (project) read-only

All tools are GET, so they are derived as readOnlyHint: true, destructiveHint: false (docs/tool-definition.md:782-806). Server and Cloud differences that the JSON must handle (checked against the api/webservices/list output of sonarcloud.io and of a SonarQube Server 24.12 Community Build):

  • Listing projects: use components/search, not projects/search. On Server, projects/search requires Administer System. On Cloud, components/search requires organization; on Server it requires qualifiers=TRK. Each product ignores the other's parameter, so one request with both works on both.
  • Issues by project: use componentKeys. Cloud only accepts componentKeys; on Server it is the deprecated alias of components and still works. Use the impact filters (impactSeverities, impactSoftwareQualities, issueStatuses): Cloud has deprecated types, severities and statuses.
  • Quality gate: on Cloud, qualitygates/project_status is marked deprecated since 16 September 2025, with no v2 replacement yet. It still answers. instructions should name the fallback: sonarqube_get_measures with metricKeys=alert_status,quality_gate_details. Both metrics exist on both products.
  • Metrics: suggest software_quality_reliability_issues, software_quality_security_issues and software_quality_maintainability_issues in descriptions and instructions, not bugs, vulnerabilities or code_smells, which Cloud has deprecated (https://docs.sonarsource.com/sonarqube-cloud/deprecations-and-removals/). coverage, duplicated_lines_density, ncloc and alert_status exist on both.

Where to look

  • packages/backend/src/adapters/intl/gitlab.json — the closest match: one adapter for a SaaS host and self-managed instances, with {{GITLAB_URL}}/api/v4 (:46), address envVarMeta (:14-32) and verifyHints.
  • packages/backend/src/adapters/intl/directus.json — Bearer auth (:15-18) and the SSRF / private-network wording in instructions (:9).
  • packages/backend/src/adapters/intl/ebay-sell.json:199 — a connector variable sent as a query param.
  • packages/backend/src/adapters/intl/todoist.live.spec.ts — spec template; gate live calls behind RUN_SONARQUBE_LIVE=1 as intl/sentry.live.spec.ts:28 does.
  • docs/tool-definition.md:18-28 — optionalEnvVars; docs/tool-definition.md:343-356 — how $param and connector variables map into the query string.
  • .github/CONTRIBUTING.md:137-155 — the "Add an adapter" checklist; 🐣 Good first issue: contribute a new MCP adapter #982 — good-first-issue adapter guide.

Acceptance criteria

  • intl/sonarqube.json exists with the 7 read-only tools, requiredEnvVars: ["SONARQUBE_URL","SONARQUBE_TOKEN"], optionalEnvVars: ["SONARQUBE_ORGANIZATION"], and a docsUrl.
  • No tool uses POST/PUT/PATCH/DELETE (asserted in the spec).
  • validate-adapters.mjs --warn is clean (the validator requires instructions ≥ 800 chars and each tool description ≥ 60 chars, scripts/validate-adapters.mjs:32-33); catalog.ts is regenerated; adapter-count.mjs --check passes.
  • intl/sonarqube.live.spec.ts: static checks (base URL is {{SONARQUBE_URL}}/api, Bearer auth, read-only methods, sonarqube_list_projects sends qualifiers=TRK and organization, sonarqube_search_issues uses componentKeys); with RUN_SONARQUBE_LIVE=1 it lists projects and reads the quality gate, measures and issues of the first one. Run it against both a SonarQube Server and SonarQube Cloud, and say in the PR which versions you tested. npx jest src/adapters/intl/sonarqube passes in packages/backend.
  • Logo at packages/frontend/public/logos/connectors/sonarqube.svg.
  • instructions cover the three URL cases, which token type to create, SONARQUBE_ORGANIZATION for Cloud, the private-network / SSRF_ALLOWED_HOSTS rule, the quality-gate fallback and the 429 rate limit on Cloud ("wait a few minutes", per the Cloud Web API page).
  • Docs updated: optional content/guides/en/sonarqube-to-mcp.mdx.

Out of scope

  • Any write: issue transitions, assignments and comments, quality gate and quality profile changes, project creation or deletion, token management.
  • Security hotspots (api/hotspots/*): Cloud marks them deprecated since 16 June 2026, replaced by security issues, which sonarqube_search_issues already covers.
  • Web API v2, portfolios and applications, administration and system endpoints.
  • New-code filters on issues: the parameter is inNewCodePeriod on Server and sinceLeakPeriod on Cloud. It can come in a follow-up.

Free / test account: SonarQube Cloud is free for public projects, and for private projects up to 50k lines of code (https://www.sonarsource.com/plans-and-pricing/sonarcloud/). Import any public GitHub repo to get data. For Server, run the Community Build locally: docker run -d --name sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9000:9000 sonarqube:latest, log in at http://localhost:9000 as admin/admin, and analyze a small project (https://docs.sonarsource.com/sonarqube-community-build/try-out-sonarqube/).

Size

S (a few hours)

How to claim

Comment "I'd like to work on this" and we'll assign you. Rules in #997.

Activity

  1. aj-codespy commented on Oct 26, 2026

    @aj-codespy
    Contributor

    I'd like to work on this

    Plan: add intl/sonarqube.json with the 7 read-only v1 Web API tools ({{SONARQUBE_URL}}/api base URL, Bearer auth, qualifiers=TRK plus optional SONARQUBE_ORGANIZATION on components/search, componentKeys and impact filters on issues, a quality-gate fallback through alert_status/quality_gate_details). I'll also add the live spec gated on RUN_SONARQUBE_LIVE=1, the logo and the guide. I'll test against a local SonarQube Community Build (Docker) and SonarQube Cloud, and list the versions in the PR.

  2. helpcodeai commented on Oct 27, 2026

    @helpcodeai
    ContributorAuthor

    Thanks @aj-codespy, it's yours. The plan looks good. Please keep all tools read-only and note in the PR which SonarQube versions you tested against.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesthacktoberfestGood for Hacktoberfest contributorshelp wantedExtra attention is needed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions