# Context Augmentation

> **Beta:** This feature is in Beta stage and is only available with SonarQube Cloud projects for organizations in the Team and Enterprise plans. See the [Product release lifecycle](/sonarqube-cloud/appendices/product-release-lifecycle.md) page for more information on release stages.

## Overview

Sonar Context Augmentation is the *Guide* phase of the [Agent Centric Development Cycle](/agent-centric-development-cycle/readme.md). It uses the SonarQube MCP Server to connect to SonarQube Cloud and provide deep, project-specific context to AI agents before they write or edit code.

This ensures that the resulting AI-generated code isn't generic and adheres to your repository's unique standards.

### Core capabilities

* **Architectural awareness**: Helps agents navigate complex class hierarchies, trace upstream/downstream call flows, and understand execution paths.
* **Intelligent guidelines**: Automatically injects relevant coding rules, quality standards, and security requirements based on your project's history and the current task.
* **Semantic navigation**: Moves beyond simple text matching to retrieve code based on its actual meaning and structure using Abstract Syntax Trees (AST), semantics, and control flow information.
* **Third-party dependency guidance**: Helps agents assess the health and safety of third-party dependencies before they're introduced or updated.

## Tool categories

When you activate Context Augmentation, the SonarQube MCP Server gains additional MCP tools for LLM context augmentation, grouped into four categories. Each category currently supports a specific set of languages, and we're actively expanding language coverage and adding more categories.

| Category                                     | Description                                                                                                                                                                                                                                                                                                                                                 | Supported languages                                                                                                                                                        |
| -------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Coding Guidelines**                        | Recommends Sonar rules to follow, based on the project's historical SonarQube issues filtered by what the agent is about to do (prompt nature and categories).                                                                                                                                                                                              | All [SonarQube Cloud languages](/sonarqube-cloud/analyzing-source-code/languages.md)                                                                                       |
| **Third-party dependency health and safety** | Assesses whether a third-party dependency is healthy and safe to use before it is introduced or updated. Currently covers known security vulnerabilities, supply-chain malware, and license compliance, with more checks in progress. Available only with the [SCA](/sonarqube-cloud/advanced-security/analyzing-projects-for-dependencies-sca.md) feature. | All [SCA-supported languages and package managers](/sonarqube-cloud/advanced-security/analyzing-projects-for-dependencies-sca.md#supported-languages-and-package-managers) |
| **Architecture**                             | Exposes the current architecture graph and user-defined architectural constraints, so the agent understands the current architecture and stays aligned with the intended design.                                                                                                                                                                            | All [languages supported by Architecture](/sonarqube-cloud/architecture.md#supported-languages)                                                                            |
| **Semantic navigation**                      | Helps the agent understand the meaning of the code rather than relying on text-based grep, by exposing call stacks, class hierarchies, references, and exact source locations. This lets the agent navigate the codebase and modify the right places effectively.                                                                                           | Java (other languages in progress)                                                                                                                                         |

The full list of MCP tools exposed by Context Augmentation, with their input parameters, is defined on the [SonarQube MCP Server Tools](/agent-centric-development-cycle/developer-tools/mcp-server/reference/tools.md) page.

<div align="left"><figure><img src="/files/RboO0gVFzbl5Gy2P7KZX" alt="Diagram showing the MCP tools for context augmentation."><figcaption></figcaption></figure></div>

### Context Augmentation for coding guidelines

The MCP tool for guidelines injects relevant Sonar rules into the LLM context:

* Based on your prompt: for example, if the user prompt involves access to DB, include all guidelines about DB.
* Based on the SonarQube issues found in files modified or related to the LLM task: for example, if the LLM plans to modify `DBStorage.java`, include guidelines from past issues in `DBStorage.java`.

<div align="left"><figure><img src="/files/qugPTTC7f5dtYqSALmid" alt="Diagram showing how MCP Tools for Guidelines combine prompt classification from Sonar Rules with historically relevant issues from past analysis to augment the LLM context."><figcaption></figcaption></figure></div>

### Context Augmentation for architecture

The MCP tools for architecture give the LLM understanding of both the current architecture and the user-defined intended constraints, powered by semantic data from SonarQube Cloud's [Architecture](/sonarqube-cloud/architecture.md) feature. These tools enable the LLM to:

* Build "the right thing", better aligning with user goals, avoiding mistakes and rework.
* Build "the thing right", provide an output that is in line with architecture expectations.

<div align="left"><figure><img src="/files/zGC2SkzypCPtoR8gynhz" alt="Diagram showing MCP Tools for Architecture exposes context to the LLM based on SonarQube Architecture analysis configuration and results."><figcaption></figcaption></figure></div>

### Context Augmentation for semantic navigation

The MCP tools for semantic navigation give the agent an understanding of the code's meaning, helping it find the right locations to modify based on meaning rather than text. With this context, the agent can:

* Reach the correct solution faster by jumping straight to the right symbols, references, types, call flows, class hierarchies, etc.
* Reduce token usage and cost, by avoiding blind reads of entire files.
* Produce safer, less buggy changes, by surfacing every relevant location that needs updating so nothing is missed.

## Guide-and-Verify loop

Using [Context Augmentation](/agent-centric-development-cycle/features/context-augmentation.md) together with Agentic Analysis allows you to build a guide-and-verify loop to ensure pull requests pass quality gates the first time, leading to faster code reviews with no back-and-forth. The loop has four steps:

1. **Guide**: [Context Augmentation](/agent-centric-development-cycle/features/context-augmentation.md) injects architectural awareness and coding guidelines into the LLM context before code generation.
2. **Generate**: The LLM generates code based on the augmented context.
3. **Verify**: [Agentic Analysis](/agent-centric-development-cycle/features/agentic-analysis.md) verifies the generated code with full CI-level precision.
4. **Loop**: The LLM refines the code based on analysis results and repeats until quality gates pass.

```mermaid
%%{init: {'themeVariables': {'actorBkg': 'rgba(18, 110, 211, 0.06)', 'actorBorder': '#126ED3', 'actorLineColor': '#126ED3', 'signalColor': '#126ED3', 'labelBoxBorderColor': '#126ED3'}}}%%
sequenceDiagram
    participant User
    participant LLM as AI Agent
    participant CAG as Context Augmentation<br/>(Guide)
    participant A3S as Agentic Analysis<br/>(Verify)

    User->>LLM: Request code generation
    LLM->>CAG: Request guidelines & architecture
    CAG-->>LLM: Inject coding standards & structure
    LLM->>LLM: Generate code
    LLM->>A3S: Analyze generated code
    A3S-->>LLM: Return analysis results

    alt Issues found
        LLM->>LLM: Refine code based on issues
        LLM->>A3S: Re-analyze code
        A3S-->>LLM: Return analysis results
    end

    LLM-->>User: Return verified code
```

## Setup

To guide agents using Context Augmentation, see [Guide your agents with context](/agent-centric-development-cycle/how-to-guides/guide-agents-with-context.md).

## Related pages

* [Guide your agents with context](/agent-centric-development-cycle/how-to-guides/guide-agents-with-context.md)
* [MCP Server](/agent-centric-development-cycle/developer-tools/mcp-server.md)
* [Tools](/agent-centric-development-cycle/developer-tools/mcp-server/reference/tools.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sonarsource.com/agent-centric-development-cycle/features/context-augmentation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
