MCP server for SonarCloud
Project description
MCP SonarCloud Server
A Model Context Protocol (MCP) server implementation for SonarCloud, providing tools to interact with SonarCloud projects, issues, quality gates, and security hotspots.
Default layout:
- Config:
~/.config/lukleh/mcp-sonarcloud/config.toml- Credentials: injected via the MCP client or shell environment
- State:
~/.local/state/lukleh/mcp-sonarcloud/- Cache:
~/.cache/lukleh/mcp-sonarcloud/
Features
This MCP server provides 15 comprehensive tools with detailed parameter documentation and examples:
Project Management (3 tools)
- search_my_sonarqube_projects: List all SonarCloud projects in your organization with pagination
- show_component: Get detailed metadata for a specific project or component
- component_tree: Traverse the file/directory structure of a project
Issues (4 tools)
- search_sonar_issues_in_projects: Search for issues with filtering by pull request, severity (INFO, LOW, MEDIUM, HIGH, BLOCKER), and more
- list_issue_authors: Discover SCM authors who contributed to issues
- get_issue_changelog: Retrieve the change history of an issue
- list_issue_tags: List available tags used on issues
Quality Gates (5 tools)
- get_project_quality_gate_status: Get the quality gate status (OK, ERROR, WARN, NONE) for a project, branch, or pull request
- list_quality_gates: List all quality gates in your organization
- show_quality_gate: Get detailed conditions for a specific quality gate
- search_quality_gates: Find projects associated with a quality gate
- get_quality_gate_by_project: Get the quality gate assigned to a project
Security Hotspots (3 tools)
- search_hotspots: Search for security hotspots in a project with file, branch, or PR filters
- show_hotspot: Get detailed information about a specific hotspot
- change_hotspot_status: Change the status of a hotspot (TO_REVIEW or REVIEWED with resolution: FIXED, SAFE, ACKNOWLEDGED)
All tools include comprehensive parameter descriptions, valid value documentation, and usage examples for optimal AI agent integration.
Prerequisites
- Python 3.11 or higher
- uv package manager
- A SonarCloud account with an API token
- Claude Code or Codex AI client
Quick Start
1. Get Your SonarCloud Token
- Log in to SonarCloud
- Click on your avatar → My Account → Security
- Under "Generate Tokens", enter a name (e.g., "MCP Server")
- Click Generate
- Copy and save the token - you won't be able to see it again!
2. Find Your Organization Key
- Go to your organization on SonarCloud
- Look at the URL:
https://sonarcloud.io/organizations/YOUR-ORG-KEY - The
YOUR-ORG-KEYpart is your organization key
3. Install the Server
# Run the published package without cloning the repository
uvx mcp-sonarcloud --write-sample-config
# Or install it once and reuse the command directly
uv tool install mcp-sonarcloud
mcp-sonarcloud --write-sample-config
4. Create the Config File
The command above writes a starter config to ~/.config/lukleh/mcp-sonarcloud/config.toml.
You can confirm the resolved runtime locations at any time:
uvx mcp-sonarcloud --print-paths
Edit ~/.config/lukleh/mcp-sonarcloud/config.toml:
base_url = "https://sonarcloud.io"
organization = "your-org-key"
timeout_sec = 30
5. Set the Token Environment Variable
Set SONARCLOUD_TOKEN in the environment used to launch the server. For local
shell testing, you can export it directly:
export SONARCLOUD_TOKEN=your-token-here
6. Configure Your AI Client
Claude Code:
claude mcp add sonarcloud \
--scope {local, user, or project} \
-e SONARCLOUD_TOKEN=your-token-here \
-- uvx mcp-sonarcloud
Codex:
codex mcp add sonarcloud \
--env SONARCLOUD_TOKEN=your-token-here \
-- uvx mcp-sonarcloud
Important: Replace your-token-here with your real SonarCloud token.
7. Restart and Test
- Restart your AI client
- Try asking: "Can you list my SonarCloud projects?"
Configuration
Files
config.tomlbase_url(optional): SonarCloud or SonarQube base URLorganization(optional): SonarCloud organization keytimeout_sec(optional): HTTP timeout in seconds
Environment Overrides
Environment variables are the source of secrets and also override file values when present:
SONARCLOUD_TOKENSONARCLOUD_ORGANIZATIONSONARCLOUD_URLSONARCLOUD_TIMEOUT_SEC
Command Line Testing
You can test the server directly:
# Show the resolved runtime paths
uvx mcp-sonarcloud --print-paths
# Write or refresh the default config file
uvx mcp-sonarcloud --write-sample-config
uvx mcp-sonarcloud --write-sample-config --overwrite
# Export the token for local testing
export SONARCLOUD_TOKEN=your-token-here
# Run the server with the default home-directory config
uvx mcp-sonarcloud
# Or point at a different config root
uvx mcp-sonarcloud --config-dir /path/to/config-dir
Local Development
If you want to work on the repository itself:
git clone https://github.com/lukleh/mcp-sonarcloud.git
cd mcp-sonarcloud
uv sync --extra dev
uv run pytest -q
uv run mcp-sonarcloud --print-paths
Usage Examples
Natural Language Queries
Once configured, you can ask your AI client:
- List projects: "Show me all my SonarCloud projects"
- Check quality gate: "What's the quality gate status for project X on PR 123?"
- Search hotspots: "Find all security hotspots in project X"
- Get hotspot details: "Show me details for hotspot AY1234567890"
- Update hotspot: "Mark hotspot AY1234567890 as reviewed and safe"
- Search issues: "Find all blocker issues in project X's pull request 123"
Tool Examples (Python)
List Projects
# Get first page of projects
search_my_sonarqube_projects(page="1")
Search Issues in Pull Request
# Search for issues in a specific pull request
search_sonar_issues_in_projects(
projects=["my-project"],
pullRequestId="123",
ps=100
)
Check Quality Gate Status
# Get quality gate status for a pull request
get_project_quality_gate_status(
projectKey="my-project",
pullRequest="123"
)
Search Security Hotspots
# Search hotspots in a project
search_hotspots(
projectKey="my-project",
pullRequest="123"
)
# Search hotspots in a specific file
search_hotspots(
projectKey="my-project",
files="src/main/java/com/example/MyClass.java",
branch="main"
)
Get Hotspot Details
# Get detailed information about a hotspot
show_hotspot(hotspot="AX1234567890")
Change Hotspot Status
# Mark a hotspot as reviewed and safe
change_hotspot_status(
hotspot="AX1234567890",
status="REVIEWED",
resolution="SAFE"
)
# Mark a hotspot for review
change_hotspot_status(
hotspot="AX1234567890",
status="TO_REVIEW"
)
Valid status values:
TO_REVIEW: Mark for reviewREVIEWED: Mark as reviewed (requires resolution)
Valid resolution values (when status=REVIEWED):
FIXED: The vulnerability has been fixedSAFE: The code is safe and not a vulnerabilityACKNOWLEDGED: The risk is acknowledged but accepted
Troubleshooting
Common Issues
"Config file already exists"
--write-sample-configwill not replace an existing file unless you add--overwrite- Use
uvx mcp-sonarcloud --print-pathsto confirm which config path is active
"SONARCLOUD_TOKEN environment variable is required"
- Double-check your token is correctly set in the environment variables
- Verify there are no extra spaces or quotes around the token
"401 Unauthorized"
- Your token might be invalid or expired
- Generate a new token from SonarCloud and update your configuration
MCP server not available
- Verify the server was added:
claude mcp listorcodex mcp list - Run
uvx mcp-sonarcloud --print-pathsin your shell to confirm the package starts cleanly - Try removing and re-adding the server
- Check your AI client logs for errors
API Endpoints Used
This server uses the following SonarCloud API endpoints:
Components / Projects
GET /api/components/search- List projectsGET /api/components/show- Show component metadataGET /api/components/tree- Traverse component hierarchy
Issues
GET /api/issues/search- Search issuesGET /api/issues/authors- List issue authorsGET /api/issues/changelog- Get issue change historyGET /api/issues/tags- List issue tags
Quality Gates
GET /api/qualitygates/project_status- Get quality gate statusGET /api/qualitygates/list- List quality gatesGET /api/qualitygates/show- Show quality gate detailsGET /api/qualitygates/search- Search projects by quality gateGET /api/qualitygates/get_by_project- Get quality gate for project
Security Hotspots
GET /api/hotspots/search- Search security hotspotsGET /api/hotspots/show- Show hotspot detailsPOST /api/hotspots/change_status- Change hotspot status
For complete API documentation, see SONARCLOUD_API_SUPPORT.md.
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
Releasing
Maintainer release instructions live in RELEASING.md.
License
MIT License - see LICENSE file for details
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
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 mcp_sonarcloud-0.1.3.tar.gz.
File metadata
- Download URL: mcp_sonarcloud-0.1.3.tar.gz
- Upload date:
- Size: 73.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16211f39845f3b3f0e9723903d9bf8422f6ad382a05155e78a56dbaf1baf01e0
|
|
| MD5 |
3cef9d6198391b1a158356373c9f2534
|
|
| BLAKE2b-256 |
4e9b65fb24b390094a77f1d24d647f19232a698325c8379407ec00e15102a45f
|
Provenance
The following attestation bundles were made for mcp_sonarcloud-0.1.3.tar.gz:
Publisher:
publish.yml on lukleh/mcp-sonarcloud
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_sonarcloud-0.1.3.tar.gz -
Subject digest:
16211f39845f3b3f0e9723903d9bf8422f6ad382a05155e78a56dbaf1baf01e0 - Sigstore transparency entry: 1229036028
- Sigstore integration time:
-
Permalink:
lukleh/mcp-sonarcloud@1d6479af69ef597b6015aa77d4916ad8cc4d9ea5 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/lukleh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1d6479af69ef597b6015aa77d4916ad8cc4d9ea5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mcp_sonarcloud-0.1.3-py3-none-any.whl.
File metadata
- Download URL: mcp_sonarcloud-0.1.3-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
983039f5f559cbc6f7aed99fedb870f680ab616dd17abc2070fddffcea24c7d7
|
|
| MD5 |
cd5c35c1903ca34c6475fbbb56e4b4be
|
|
| BLAKE2b-256 |
999fa35ac46e80f4af327ef96d22e68eba58db29c4386f4170006b89a50e7b14
|
Provenance
The following attestation bundles were made for mcp_sonarcloud-0.1.3-py3-none-any.whl:
Publisher:
publish.yml on lukleh/mcp-sonarcloud
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_sonarcloud-0.1.3-py3-none-any.whl -
Subject digest:
983039f5f559cbc6f7aed99fedb870f680ab616dd17abc2070fddffcea24c7d7 - Sigstore transparency entry: 1229036064
- Sigstore integration time:
-
Permalink:
lukleh/mcp-sonarcloud@1d6479af69ef597b6015aa77d4916ad8cc4d9ea5 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/lukleh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1d6479af69ef597b6015aa77d4916ad8cc4d9ea5 -
Trigger Event:
push
-
Statement type: