Skip to main content

sonar_get_issue_details

Get detailed information about a specific SonarQube issue with rich context for intelligent fixing.

Description

Retrieves comprehensive issue information including plain-text source code context, rule explanation, and (optionally) additional context to make fixes more accurate and less “trial and error”:

  • File header (imports/signature)
  • Data flow (when Sonar provides flows)
  • Similar FIXED issues (opt-in)
  • Related tests + coverage hints (opt-in)
  • SCM hints (opt-in)

Parameters

ParameterTypeRequiredDefaultDescription
issueKeystringYes-SonarQube issue key (e.g., AYx123abc456)
contextLinesnumberNo10Lines of code context around the issue
includeRuleDetailsbooleanNotrueInclude rule explanation
includeCodeExamplesbooleanNotrueInclude compliant/non-compliant examples
includeFilePathbooleanNotrueInclude absolute file path for editing
includeFileHeaderbooleanNotrueInclude the file header (imports/signature) before the issue context
headerMaxLinesnumberNo60Max lines to include in the file header (max: 200)
includeDataFlowboolean | "auto"No"auto"Include security data flow when available ("auto" only shows it if Sonar provides flows)
maxFlowsnumberNo3Max flows to include when data flow is present
maxFlowStepsnumberNo12Max steps per flow to include
flowContextLinesnumberNo3Context lines per dataflow step
includeSimilarFixedbooleanNofalseInclude similar issues already FIXED in this project
maxSimilarIssuesnumberNo3Max similar FIXED issues to include
includeRelatedTestsbooleanNofalseInclude related tests (best-effort) and coverage hints
includeCoverageHintsbooleanNotrue (when includeRelatedTests is true)Include coverage hints for the issue line
includeScmHintsbooleanNofalseInclude SCM hints (author/date/revision) when available

Usage

Basic Usage

Show me details for issue AYx123abc456

Tool call:

{
"issueKey": "AYx123abc456"
}

With More Context

Show me more code context for this issue

Tool call:

{
"issueKey": "AYx123abc456",
"contextLines": 20
}
Give me fix-ready details (header, flow if present, tests/coverage hints)

Tool call:

{
"issueKey": "AYx123abc456",
"includeFileHeader": true,
"includeDataFlow": "auto",
"includeRelatedTests": true,
"includeCoverageHints": true
}

Minimal Response

Just show me the issue location, skip the examples

Tool call:

{
"issueKey": "AYx123abc456",
"includeCodeExamples": false,
"includeRuleDetails": false
}

Learn From Similar FIXED Issues (Opt-in)

Show similar FIXED issues for the same rule (same project)

Tool call:

{
"issueKey": "AYx123abc456",
"includeSimilarFixed": true,
"maxSimilarIssues": 3
}

Response Format

SONARQUBE ISSUE ANALYSIS

ISSUE DETAILS

Key: `AYx123abc456`
Type: 🔒 VULNERABILITY
Severity: 🔴 BLOCKER
Rule: `typescript:S3649`
Status: OPEN
Message: Make sure that executing SQL queries is safe here.

LOCATION

Component: `my-project:src/db/queries.ts`
File Path: `/Users/dev/my-project/src/db/queries.ts`
Line: 45

FILE HEADER (first 60 lines)

```ts
1 | import { db } from './connection';
2 |
3 | export async function getUser(id: string) {
4 | // ...

SOURCE CODE CONTEXT

  42 | export async function getUser(id: string) {
43 | // ...
44 | const query = `SELECT * FROM users WHERE id = '${id}'`;
45 | return db.execute(query);
46 | }

DATA FLOW (only when available)

Flow 1 (showing 8/14 steps) Step 1: user input → src/api/routes.ts:12 ... Step 8: SQL execution → src/db/queries.ts:45 (PRIMARY LOCATION)

RELATED TESTS + COVERAGE HINTS (opt-in)

  • Related tests: src/db/queries.test.ts (best-effort)
  • Coverage: issue line appears uncovered → consider adding/adjusting tests

SCM HINTS (opt-in)

  • Author: Jane Doe
  • Date: 2025-11-18
  • Revision: abcdef123

NEXT STEPS

  1. Replace the query construction with a parameterized query.
  2. Add/adjust tests if coverage indicates the risky path is uncovered.

RULE INFORMATION (optional) Compliant / non-compliant examples (optional)


## Examples

### Example 1: Security Vulnerability

**Prompt:**

Tell me more about this SQL injection issue


**Tool Call:**
```json
{
"issueKey": "AYx123abc456"
}

Example 2: Code Smell Investigation

Prompt:

Why is this function too complex?

Tool Call:

{
"issueKey": "AYx789def012",
"contextLines": 30
}

Example 3: Quick Location Check

Prompt:

Where exactly is issue AYx456 located?

Tool Call:

{
"issueKey": "AYx456",
"includeRuleDetails": false,
"includeCodeExamples": false,
"contextLines": 5
}

Response Fields

FieldDescription
Issue KeyUnique identifier for the issue
TypeBUG, VULNERABILITY, CODE_SMELL
SeverityBLOCKER, CRITICAL, MAJOR, MINOR, INFO
EffortEstimated fix time
FileAbsolute path to affected file
LineLine number of the issue
MessageBrief issue description
Code ContextSource code with surrounding lines
File HeaderFile imports/signature to provide structural context
Data FlowSource→sink flow steps for vulnerabilities (when available)
Similar FIXED IssuesExamples of the same rule resolved in this project (opt-in)
Related TestsBest-effort related test discovery (opt-in)
Coverage HintsPer-line coverage hints for the issue location (opt-in)
SCM HintsAuthor/date/revision info when available (opt-in)
RuleRule ID and full explanation
Compliant CodeExample of correct code
Non-compliant CodeExample of problematic code

Notes & Compatibility

Plain-text snippets (no HTML)

SonarQube has endpoints that return syntax-highlighted HTML in the code field. Bob retrieves snippets as plain text (preferring range-based endpoints when available) and falls back to slicing the raw file when needed.

Best Practices

  1. Get details before fixing - Always understand the issue fully
  2. Use context - More lines help understand the problem
  3. Keep data flow on "auto" - Shows flow only when Sonar provides it
  4. Enable tests/coverage hints when writing tests - Set includeRelatedTests: true
  5. Use similar FIXED issues sparingly - Helpful for patterns, but keep it opt-in
  6. Read the rule - Explains why the issue matters

Common Issues

"Issue not found"

Cause: Invalid issue key or issue was resolved.

Solution: Run sonar_scan_project to get fresh issue keys.

"No code context"

Cause: File was deleted or moved.

Solution: Re-scan to update issue locations.