SonarQube MCP Server
Provides tools to query SonarQube for code quality metrics, issues, and duplication reports on pull requests and files.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@SonarQube MCP ServerWhat are the Sonar metrics on PR 257?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
SonarQube MCP Server
A Model Context Protocol (MCP) server that gives Cursor AI (and any MCP-compatible AI) live access to SonarQube — so you can ask questions like:
"What SonarQube issues are in this file?" "What does Sonar say about my PR?" "Fix all issues in config.ts for PR 257"
…and Cursor fetches the data itself, no copy-pasting JSON.
Tools exposed
Tool | When AI uses it |
| "What's my coverage?" / "Does Sonar pass?" / "What are the Sonar metrics on PR 257?" |
| "What issues are on my PR?" / "What does Sonar say?" |
| "What issues are in this file?" / "Fix issues in config.ts" |
| "Which files have duplicated code?" / "What's the duplication?" |
Related MCP server: mcp-sonarcloud
Architecture
Cursor AI
│ (MCP protocol over stdio)
▼
SonarQube MCP Server (this repo)
│ (HTTPS with Teleport client certificates)
▼
Teleport (company SSO gateway)
│
▼
SonarQube APINote: SonarQube at OpenGov is behind Teleport, a secure access gateway. The server uses Teleport client certificates generated by
tsh apps login. If your SonarQube is directly accessible (no Teleport), the server works withouttsh.
Prerequisites
Node.js 18+ (Node 22 recommended)
tsh(Teleport CLI) — only needed if SonarQube is behind TeleportSonarQube user token — generate at SonarQube → My Account → Security → Generate Token
Cursor (or any MCP-compatible AI client)
Installation
Step 1 — Clone the repo
git clone https://github.com/rahulsingh-cloud/SonarQube-MCP-Server.git
cd SonarQube-MCP-ServerStep 2 — Install dependencies
npm installStep 3 — Build
npm run buildThis compiles index.ts → dist/index.js.
Configuration
Step 4 — Get your SonarQube token
Open SonarQube in your browser and log in
Go to My Account → Security → Generate Token
Name it
cursor-mcp, click Generate, copy the token
Step 5 — Register the MCP server with Cursor
Edit (or create) the Cursor MCP config file. The location depends on your OS:
OS | Path |
Windows |
|
macOS |
|
Linux |
|
Windows
{
"mcpServers": {
"sonarqube": {
"command": "node",
"args": ["C:\\Users\\YourName\\SonarQube-MCP-Server\\dist\\index.js"],
"env": {
"SONARQUBE_TOKEN": "squ_your_token_here",
"SONARQUBE_URL": "https://your-sonarqube-host",
"SONARQUBE_PROJECT": "your-project-key"
}
}
}
}Tip (Windows): Use double backslashes
\\in the path, or use forward slashes/— both work.
macOS / Linux
{
"mcpServers": {
"sonarqube": {
"command": "node",
"args": ["/Users/yourname/SonarQube-MCP-Server/dist/index.js"],
"env": {
"SONARQUBE_TOKEN": "squ_your_token_here",
"SONARQUBE_URL": "https://your-sonarqube-host",
"SONARQUBE_PROJECT": "your-project-key"
}
}
}
}Tip (macOS): Use
pwdinside the cloned repo folder to get the full path.
Replace in both:
your-project-key— found in SonarQube → Project → Project Informationsqu_your_token_here— your SonarQube token from Step 4https://your-sonarqube-host— your SonarQube base URL (e.g.https://sonarqube.yourcompany.com)
Step 6 — Restart Cursor
Close Cursor completely (Quit, not just close the window) and reopen it.
Windows: Right-click Cursor in the system tray → Quit
macOS:
Cmd+Qor Cursor menu → Quit Cursor
You'll see sonarqube listed with a green dot under Cursor Settings → MCP.
If SonarQube is behind Teleport (OpenGov setup)
Teleport is a secure access gateway. The server automatically detects and uses Teleport client certificates if tsh is installed and logged in.
Install tsh (Teleport CLI)
Windows:
Download from https://goteleport.com/download/ → Windows →
.exeinstallerRun the installer
Add the install folder to your
Pathenvironment variable (e.g.C:\Program Files\Teleport Connect\Programs)Restart your terminal
tsh version # verifymacOS (Homebrew):
brew install teleport
tsh version # verifymacOS (manual):
Download from https://goteleport.com/download/ → macOS →
.pkginstallerRun the installer —
tshis added to/usr/local/binautomatically
tsh version # verifyLog in to Teleport
Works the same on Windows, macOS, and Linux:
# Step 1 — Log in via browser SSO (Okta)
tsh login --proxy=opengov.teleport.sh --skip-version-check
# Step 2 — Get access to SonarQube specifically
tsh apps login sonarqube-engops-production --skip-version-check
# Step 3 — Verify access
tsh apps ls --skip-version-checkAfter tsh login, your browser opens for Okta SSO. After authenticating, return to the terminal and run steps 2 and 3.
The server automatically finds the certificates at:
macOS / Linux:
~/.tsh/keys/opengov.teleport.sh/<username>-app/opengov.teleport.sh/sonarqube-engops-production.crt
~/.tsh/keys/opengov.teleport.sh/<username>-app/opengov.teleport.sh/sonarqube-engops-production.keyWindows:
C:\Users\<YourName>\.tsh\keys\opengov.teleport.sh\<username>-app\opengov.teleport.sh\sonarqube-engops-production.crt
C:\Users\<YourName>\.tsh\keys\opengov.teleport.sh\<username>-app\opengov.teleport.sh\sonarqube-engops-production.keySupports both:
Teleport v18+ —
.crt/.keyfilesTeleport v17 and older —
-x509.pemfiles
Cert expiry: Teleport certificates expire (typically 12 hours). Run
tsh apps login sonarqube-engops-production --skip-version-checkagain and restart Cursor when they expire.
Usage
Once connected, just ask Cursor in plain English:
# Get PR metrics
"What does SonarQube say about PR 257?"
"Does my PR pass Sonar?"
"What's my coverage on PR 257?"
# Get file issues
"What SonarQube issues are in apps/web/src/og-assist/tools/config.ts?"
"Fix all issues in this file for PR 257"
# Get PR issues
"What issues were introduced in PR 257?"
"Show me all new code smells on my PR"
# Get duplication
"Which files have duplicated code in PR 257?"
"What's the duplication on my PR?"Cursor selects the right tool automatically based on your question.
Manual testing
You can test the server without Cursor by piping JSON-RPC directly.
macOS / Linux:
# List available tools
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | \
SONARQUBE_TOKEN=your_token \
SONARQUBE_URL=https://your-sonarqube \
SONARQUBE_PROJECT=your-project \
node dist/index.js
# Call a tool
echo '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"sonar_get_pr_metrics","arguments":{"pullRequest":"257"}}}' | \
SONARQUBE_TOKEN=your_token \
SONARQUBE_URL=https://your-sonarqube \
SONARQUBE_PROJECT=your-project \
node dist/index.jsWindows (PowerShell):
$env:SONARQUBE_TOKEN = "your_token"
$env:SONARQUBE_URL = "https://your-sonarqube"
$env:SONARQUBE_PROJECT = "your-project"
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | node dist/index.js
echo '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"sonar_get_pr_metrics","arguments":{"pullRequest":"257"}}}' | node dist/index.jsEnvironment variables
Variable | Required | Default | Description |
| ✅ Yes | — | SonarQube user token ( |
| No |
| SonarQube base URL |
| No |
| SonarQube project key |
Project structure
SonarQube-MCP-Server/
├── index.ts ← MCP server source (all logic)
├── dist/index.js ← compiled output (run this)
├── package.json
├── tsconfig.json
└── README.mdHow it works
Cursor reads
~/.cursor/mcp.jsonat startup and launches the server as a background processThe server registers 4 tools with names and descriptions
When you ask a question, Cursor's AI reads the tool descriptions and decides which tool to call
The server makes an HTTPS request to SonarQube (with Teleport certs if applicable) and returns the data
Cursor uses the data to answer your question or take action
Troubleshooting
Problem | Fix |
| Fully quit and reopen Cursor ( |
| Run |
| Token is wrong or expired — generate a new one from SonarQube → My Account → Security |
| Run |
Certs expired | Run |
| Run |
| Add |
License
MIT
Available Tools
4 toolssonar_get_duplication_reportA
Get the duplicated lines report for a pull request — which files have duplicated code and what percentage. Use this when the user mentions 'duplication' or 'duplicated lines'.
| Name | Required | Description | Default |
|---|---|---|---|
| pullRequest | Yes | Pull request number, e.g. '257' |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description must carry the full burden. It only states the basic purpose without disclosing behavior such as read-only guarantee, error handling, or performance characteristics. Minimal transparency.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Two sentences with no filler. The first sentence states the purpose and output, the second gives usage guidance. Efficient and front-loaded.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
The tool is simple with one parameter and no output schema. The description gives a high-level overview of the output (files and percentages) but lacks detailed structure or examples. Adequate but slightly incomplete.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 100% for the single parameter 'pullRequest', and its schema description is clear. The description does not add any extra meaning beyond the schema, resulting in a baseline score of 3.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the verb 'get' and the resource 'duplicated lines report for a pull request', specifying what the tool returns (files with duplicated code and percentage). It is distinct from sibling tools which focus on issues and metrics.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Explicitly advises using the tool when the user mentions 'duplication' or 'duplicated lines', providing clear context. However, it does not mention when not to use it compared to alternatives, leaving room for improvement.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
sonar_get_file_issuesA
Get open SonarQube issues for a specific source file. Use this when the user asks about issues in a particular file they are editing or viewing. Returns the list of issues with line number, rule, severity, and fix message.
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | File path relative to repo root, e.g. 'apps/web/src/og-assist/tools/config.ts' | |
| pullRequest | No | Optional PR number to scope to new code only. Omit to get all issues on main. |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Describes the return format (line number, rule, severity, fix message) but no additional behavioral traits like read-only nature or rate limits. With no annotations, it's adequate but not rich.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Two sentences: first defines core function, second adds usage and output shape. Efficient, no fluff.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given 2 params, no output schema, and no annotations, the description covers purpose, usage, and output shape well. Could mention error handling or preconditions, but not essential.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 100%, so baseline is 3. Description does not add significant meaning beyond the schema; it merely restates filePath relative path and pullRequest scope. No extra constraints or examples.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Clearly states the verb 'Get' and resource 'open SonarQube issues for a specific source file'. Differentiates from siblings like sonar_get_pr_issues (PR-level) and sonar_get_duplication_report.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Explicitly says 'Use this when the user asks about issues in a particular file they are editing or viewing', providing clear context. No explicit when-not-to-use or alternatives, but sufficient for typical use.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
sonar_get_pr_issuesA
Get all open SonarQube issues for a specific pull request, grouped by file. Use this when the user asks about issues on their PR, branch, or 'what does Sonar say'. Returns each file with its issues (rule, line, severity, message).
| Name | Required | Description | Default |
|---|---|---|---|
| pullRequest | Yes | Pull request number, e.g. '257' | |
| severity | No | Optional: filter by severity. Omit to get all severities. |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description must disclose behavioral traits. It mentions the return format (grouped by file with rule, line, severity, message) but does not explicitly state that the operation is read-only, safe, or describe potential side effects or limits. The 'get' verb implies read-only, but explicit safety information is missing.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is exceptionally concise, consisting of two sentences that deliver purpose, usage guidance, and output structure without any redundant words or filler. It is well-organized and front-loaded with the core action.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the tool's low complexity (2 params, no output schema), the description adequately covers input requirements and output format (grouped by file with issue details). It does not address error conditions or absence of issues, but for a straightforward list retrieval, it is sufficiently complete.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 100%, so the parameter descriptions are already clear in the schema. The description adds no new semantic value beyond restating that pullRequest is a number and severity is optional with enum values. It does not explain parameter usage nuances or format expectations beyond the schema.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool retrieves all open SonarQube issues for a specific PR, grouped by file. It distinguishes itself from siblings by specifying the use case (user asks about issues on PR, branch, or 'what does Sonar say') and mentions return structure, making the purpose distinct and actionable.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description explicitly advises when to use the tool (when user asks about issues on PR, branch, or 'what does Sonar say'), providing clear context. However, it does not explicitly state when not to use it or mention alternative sibling tools for other needs, though the differentiation is implied by context.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
sonar_get_pr_metricsA
Get quality metrics for a pull request: coverage on new code, duplication percentage, and issue counts (bugs, code smells, vulnerabilities). Use this when the user asks 'what is my coverage?', 'does Sonar pass?', or 'what are the Sonar metrics on my PR?'.
| Name | Required | Description | Default |
|---|---|---|---|
| pullRequest | Yes | Pull request number, e.g. '257' |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations provided, so description carries full burden. It states the tool retrieves metrics (read-only), but does not mention authentication, rate limits, or error behavior. Adequate but could add more context about the system (e.g., SonarQube/Cloud).
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Two concise sentences, front-loaded with purpose and metrics, followed by usage examples. No wasted words.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given a simple tool with one parameter and no output schema, the description explains the output (metrics list) and usage context. Lacks details on return format or pagination, but sufficient for typical use.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 100% with a clear param description. The tool description adds context about what metrics are returned but does not enhance parameter meaning beyond the schema.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Description clearly states 'Get quality metrics for a pull request' and lists specific metrics (coverage, duplication, issues). It distinguishes from sibling tools by specifying the scope (overall PR metrics vs. duplication or file-level issues).
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Provides explicit example queries when the tool should be used ('what is my coverage?', 'does Sonar pass?', etc.). Does not explicitly mention when not to use, but the examples cover common intents.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
4 tool updates
v1.0.0- First observed
sonar_get_duplication_report - First observed
sonar_get_file_issues - First observed
sonar_get_pr_issues - First observed
sonar_get_pr_metrics
TDQS
Scored across 4 tools
Each tool targets a distinct aspect of SonarQube data: duplication, file issues, PR issues, and PR metrics. No overlap in functionality.
All tools follow a consistent 'sonar_get_<descriptive_noun_phrase>' pattern, using snake_case throughout.
4 tools cover the essential read operations for SonarQube integration, neither too few nor too many for the domain.
Covers key retrieval needs (duplication, file-level issues, PR issues, metrics). Missing quality gate status check, but core workflows are addressed.
Maintenance
Related MCP Connectors
Direct access to Cypress tests results and accessibility reports in your AI workflow.
Deep security scans of repos you own from your editor: dependency CVEs, SAST, git-history secrets.
Read-only access to your CodeMouse accounts, repositories, and AI pull-request reviews.
Connects AI assistants to CloudQuell multi-cloud and AI cost, savings, anomaly, and budget data.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceServer for SonarQube Give AI assistants direct access to your code quality, security & analysis data2MIT
- AlicenseAqualityCmaintenanceEnables interaction with SonarCloud projects, issues, quality gates, and security hotspots through natural language.15MIT
- FlicenseNot gradedqualityDmaintenanceEnables access to SonarQube code quality analysis through MCP, including issue searching, metrics retrieval, and quality gate status.-
- AlicenseNot gradedqualityDmaintenanceEnables Cursor AI to interact with SQL Server databases, including querying, schema exploration, report generation, and chart creation.8 npmMIT