> For the complete documentation index, see [llms.txt](https://docs.sonarsource.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sonarsource.com/sonarqube-for-intellij/ai-capabilities/ai-agents.md).

# AI agents

SonarQube for IntelliJ offers tools to engage with AI agents running in your IDE, such as Claude Code and GitHub Copilot, to bring SonarQube analysis into your AI-assisted workflow.

{% hint style="info" %}
**For AI agents:** You're in the SonarQube for IntelliJ documentation. For a list of all its pages, see the [SonarQube for IntelliJ page index](https://2586659349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNvI4wotPmITyM0mnsmtp%2Fuploads%2FzEPt2RGJTHEoVax9hk24%2Fsonarqube-for-intellij-llms.txt?alt=media). For the whole site, see the [page index](https://docs.sonarsource.com/llms.txt) or the [full text](https://docs.sonarsource.com/llms-full.txt).
{% endhint %}

SonarQube for IDE's code analysis workflow is enhanced by a set of tools designed to integrate with AI agents. These tools allow you to interact with AI agents in natural language to perform specific SonarQube-related tasks directly within your IDE. This integration streamlines your development process by bringing the power of SonarQube analysis into your AI-assisted conversations, helping you focus on and resolve code quality and security issues more efficiently.

## SonarQube MCP Server

The SonarQube MCP Server is a Model Context Protocol (MCP) server that runs locally and enables a seamless connection between your AI agents and your SonarQube platform. The tools are designed to bridge the divide between productivity and quality. Please see the full details in the [SonarQube MCP Server](https://docs.sonarsource.com/sonarqube-mcp-server/) documentation.

Using SonarQube MCP Server together with the SonarQube for IDE plugin allows the MCP server to trigger analyses directly in the editor, just like regular on-the-fly analysis by SonarQube for IDE. This powerful combination helps AI agents deliver more reliable, maintainable, and secure code.

## GitHub Copilot plugin

SonarQube for IntelliJ includes tools for the GitHub Copilot plugin. The interactive tools come automatically with your installation and are best accessed with the Copilot **Agent** mode enabled.

> **Note:** Organizations and enterprises on a Copilot Business or Copilot Enterprise plan must have the **MCP servers in Copilot** policy enabled by an administrator before MCP can be used with Copilot.

1. Open the GitHub Copilot plugin.
2. Make sure you're in Agent mode and select **Configure tools** to open the setup menu.
3. Select **Add MCP Tools** or **+ Add More Tools** to open an `mcp.json` file where you can paste your configuration.
4. Use either the SonarQube MCP configuration generator, or adapt the setup below to add your configuration.

The following sample is the static equivalent of the [SonarQube MCP Server configuration generator](https://mcp.sonarqube.com/config-generator.html) output and can be adapted for SonarQube Cloud or SonarQube Server.

```jsonc
{
  "servers": {
    "io.github.SonarSource/sonarqube-mcp-server": {
      "type": "stdio",
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "docker.io/sonarsource/sonarqube-mcp"
      ],
      "env": {
        "SONARQUBE_TOKEN": "", //Only User tokens are allowed.
        "SONARQUBE_ORG": "", //Optional. Fixes the SonarQube Cloud organization.
        //"SONARQUBE_URL": "https://sonarqube.us", //For an organization in the SonarQube Cloud US region.
        "SONARQUBE_URL": "" //Use for connection to SonarQube Server.
      }
    }
  }
}
```

5. Save the file. The SonarQube tools appear immediately — select the tools icon in Copilot to confirm.

{% hint style="warning" %}
*User tokens* are required when setting up connected mode or an MCP Server between SonarQube (Server, Cloud) and SonarQube for IDE. Note that the binding will not function properly if *project tokens*, *global tokens*, or *scoped organization tokens* are used during the setup process.
{% endhint %}

### **Instructions for the AI agent**

To get the best results, give the agent clear instructions so it uses the SonarQube MCP Server effectively. For GitHub Copilot, you can add a `copilot-instructions.md` file in the `.github` folder at the root of your project. That file is read by the agent each time you interact with it.

Once the MCP Server is configured, you can ask the agent in natural language to analyze code snippets, check dependency risks, change issue status (for example Accept or False Positive), list issues in your project or current file, summarize project status (coverage, duplication, open issues), or list issues for a pull request. Providing project context (such as build files with SonarQube properties) and defining guardrails in `copilot-instructions.md` helps the agent target the right project and use the MCP Server effectively.

## Setup with Claude Code

Details coming soon.

## The SonarQube MCP Server tools

Once you’ve set up the Sonar MCP Server with your IDE, you can start using the SonarQube MCP Server [Tools](https://docs.sonarsource.com/sonarqube-mcp-server/reference/tools.md).

## Related pages

To bring SonarQube's AI agent capabilities into your development workflow, see the following pages.

* [Sonar Vortex analysis](https://docs.sonarsource.com/agent-centric-development-cycle/inside-your-agent-the-agentic-loop/sonar-vortex-analysis.md)
* [Sonar Vortex context](https://docs.sonarsource.com/agent-centric-development-cycle/inside-your-agent-the-agentic-loop/sonar-vortex-context.md)
* [SonarQube Remediation Agent](https://docs.sonarsource.com/agent-centric-development-cycle/in-your-long-living-branches-the-code-maintenance-loop/remediation-agent.md)
* [SonarQube agent plugins](https://docs.sonarsource.com/agent-centric-development-cycle/developer-tools/agent-plugins.md)
* [Gitar](https://docs.gitar.ai/introduction)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.sonarsource.com/sonarqube-for-intellij/ai-capabilities/ai-agents.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
