> 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 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": "", //Use for connection to SonarQube Cloud.
        //"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](/sonarqube-mcp-server/reference/tools.md).


---

# 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 dynamically by asking a question.

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

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
