> 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-mcp-server/setup/quickstart-guides/claude-code.md).

# Claude Code

[Claude Code](https://www.anthropic.com/claude-code) is Anthropic's CLI for Claude that runs in your terminal. Use this MCP server setup when you want to use Sonar tools directly from the command line or when working in a terminal-based AI workflow.

If you prefer using the [SonarQube-hosted MCP server](#sonarqube-hosted-mcp-server) instead, see the [SonarQube-hosted MCP server](#sonarqube-hosted-mcp-server) section.

To install MCP servers with Claude Code, see the [official Anthropic docs](https://docs.anthropic.com/en/docs/claude-code/mcp#installing-mcp-servers).

For an automated setup, use the [Claude Code setup flow](/sonarqube-cli/integrations/claude-code.md). It configures the MCP server automatically and also adds secrets detection, agentic analysis, and context augmentation.

## Use the configuration generator

Use the official [SonarQube MCP Server configuration generator](https://mcp.sonarqube.com/config-generator.html) to get a configuration code snippet for your setup:

1. Identify the target MCP Client.
2. Find your [#common-variables](/sonarqube-mcp-server/reference/environment-variables.md#common-variables).
3. Choose a [hosting method](/sonarqube-mcp-server/setup/environment-considerations.md#hosting-method).
4. Enter the information into the configuration generator.
5. Paste the generated configuration into your configuration file.

## Manual setup

### Environment variables

The following [common variables](/sonarqube-mcp-server/reference/environment-variables.md#common-variables) are required. `SONARQUBE_TOKEN` applies to stdio transport only. For HTTP, HTTPS, or the embedded SonarQube Cloud MCP server, use the `Authorization: Bearer <YourSonarQubeUserToken>` header instead.

* `SONARQUBE_TOKEN`: Your SonarQube user token (stdio transport).
* `SONARQUBE_ORG`: Your SonarQube Cloud organization key. Required for SonarQube Cloud only.
* `SONARQUBE_URL`: Your SonarQube Server or Community Build URL. Also required for SonarQube Cloud in the US region (`https://sonarqube.us`). Not needed for SonarQube Cloud in the EU region.

> **Important:** Your SonarQube token is a sensitive credential. Use environment variables to pass tokens rather than hardcoding them in command-line arguments or configuration files. Never commit tokens to version control.

### Transport options

The SonarQube MCP Server supports three transport modes. Use [Stdio](/sonarqube-mcp-server/setup/self-hosted.md#local-server-stdio) for local development and most use cases, [HTTPS](/sonarqube-mcp-server/setup/self-hosted.md#https-streamable-http-over-tls) for production and team deployments, and [HTTP](/sonarqube-mcp-server/setup/self-hosted.md#http-streamable-http) only on trusted internal networks.

#### Stdio (recommended)

Use [Stdio](/sonarqube-mcp-server/setup/self-hosted.md#local-server-stdio) for local development or when you're the only user. It's also the transport mode used in your [agentic analysis](/agent-centric-development-cycle/verify/how-to-guides/make-your-agent-verify-its-code.md) and [context augmentation](/agent-centric-development-cycle/guide/add-context-to-generate-better-code.md) workflows.

Use the `claude mcp add sonarqube` command to set up the SonarQube MCP Server as a local stdio server:

> **Warning:** *User tokens* are required when setting up connected mode or your SonarQube MCP server with SonarQube (Server, Cloud). Your binding won't function properly if you use *project tokens*, *global tokens*, or *scoped organization tokens* during setup.

> **Tip:** SONARQUBE\_URL should be defined as `https://sonarqube.us` each time you use a SonarQube Cloud configuration (`SONARQUBE_TOKEN` + `SONARQUBE_ORG`) and want to connect to a US-region instance. See the [Connecting to SonarQube Cloud in the US region](/sonarqube-mcp-server/setup/environment-considerations.md#connecting-to-sonarqube-cloud-in-the-us-region) section for details.

> **Note:** Docker's MCP Hub publishes the [`mcp/sonarqube`](https://hub.docker.com/r/mcp/sonarqube) image on its own cadence, so it may occasionally lag behind the latest release. The examples below use [`sonarsource/sonarqube-mcp`](https://hub.docker.com/r/sonarsource/sonarqube-mcp/tags) instead, which receives new releases first and supports versioned tags for stable pinning.

For SonarQube Cloud:

```bash
claude mcp add sonarqube \
  --env SONARQUBE_TOKEN=$SONARQUBE_TOKEN \
  --env SONARQUBE_ORG=$SONARQUBE_ORG \
  -- \
docker run -i --rm --init --pull=always -e SONARQUBE_TOKEN -e SONARQUBE_ORG sonarsource/sonarqube-mcp
```

For SonarQube Server:

```bash
claude mcp add sonarqube \
  --env SONARQUBE_TOKEN=$SONARQUBE_TOKEN \
  --env SONARQUBE_URL=$SONARQUBE_URL \
  -- \
  docker run -i --rm --init --pull=always -e SONARQUBE_TOKEN -e SONARQUBE_URL sonarsource/sonarqube-mcp
```

For a manual configuration, add this MCP configuration to your `~/.claude.json` file.

> **Note:** This code sample configures the MCP server using [Stdio](/sonarqube-mcp-server/setup/self-hosted.md#local-server-stdio) transport, where `SONARQUBE_TOKEN` is passed as an environment variable.
>
> For [HTTPS](/sonarqube-mcp-server/setup/self-hosted.md#https-streamable-http-over-tls), [HTTP](/sonarqube-mcp-server/setup/self-hosted.md#http-streamable-http), or the [SonarQube-hosted MCP server](#sonarqube-hosted-mcp-server), the `SONARQUBE_TOKEN` header is deprecated. Pass the token using the `"Authorization": "Bearer <YourSonarQubeUserToken>"` header instead.

> **Tip:** SONARQUBE\_URL should be defined as `https://sonarqube.us` each time you use a SonarQube Cloud configuration (`SONARQUBE_TOKEN` + `SONARQUBE_ORG`) and want to connect to a US-region instance. See the [Connecting to SonarQube Cloud in the US region](/sonarqube-mcp-server/setup/environment-considerations.md#connecting-to-sonarqube-cloud-in-the-us-region) section for details.

**Claude Code with SonarQube Cloud**

```jsonc
{
  "mcpServers": {
    "sonarqube": {
      "type": "stdio",
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "--init",
        "--pull=always",
        "-e",
        "SONARQUBE_TOKEN",
        "-e",
        "SONARQUBE_ORG",
        //"-e",
        //"SONARQUBE_URL",
        "sonarsource/sonarqube-mcp"
      ],
      "env": {
        "SONARQUBE_TOKEN": "<YourSonarQubeUserToken>",
        "SONARQUBE_ORG": "<YourOrganizationName>",
        //"SONARQUBE_URL": "https://sonarqube.us"
      }
    }
  }
}
```

**Claude Code with SonarQube Server**

```json
{
  "mcpServers": {
    "sonarqube": {
      "type": "stdio",
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "--init",
        "--pull=always",
        "-e",
        "SONARQUBE_TOKEN",
        "-e",
        "SONARQUBE_URL",
        "sonarsource/sonarqube-mcp"
      ],
      "env": {
        "SONARQUBE_TOKEN": "<YourSonarQubeUserToken>",
        "SONARQUBE_URL": "<YourSonarQubeServerURL>"
      }
    }
  }
}
```

> **Tip:** To verify the connection, ask your AI agent to call the SonarQube MCP `ping_system` tool. For example: *"Ping the SonarQube MCP server."*

> **Tip:** Restart your AI agent for good measure, although it might not be required.

#### HTTPS

Use HTTPS when connecting Claude Code to a shared MCP server deployed for a team. This requires an [HTTPS transport server](/sonarqube-mcp-server/setup/self-hosted.md#https-streamable-http-over-tls) to be running and accessible.

Add the following to your `~/.claude.json` file:

```json
{
  "mcpServers": {
    "sonarqube": {
      "type": "https",
      "url": "https://<YourSonarQubeMCPServer>:8443/mcp",
      "headers": {
        "Authorization": "Bearer <YourSonarQubeUserToken>"
      }
    }
  }
}
```

#### HTTP

> **Important:** The [HTTP](/sonarqube-mcp-server/setup/self-hosted.md#http-streamable-http) transport mode is not recommended. Use [Stdio](/sonarqube-mcp-server/setup/self-hosted.md#stdio) for local development or [HTTPS](/sonarqube-mcp-server/setup/self-hosted.md#https-streamable-http-over-tls) for multi-user production deployments.

Use HTTP only on a trusted internal network or for local testing. This requires an [HTTP transport server](/sonarqube-mcp-server/setup/self-hosted.md#http-streamable-http) to be running.

Add the following to your `~/.claude.json` file:

```json
{
  "mcpServers": {
    "sonarqube": {
      "type": "http",
      "url": "http://<YourSonarQubeMCPServer>:8080/mcp",
      "headers": {
        "Authorization": "Bearer <YourSonarQubeUserToken>"
      }
    }
  }
}
```

## Sonar Vortex: agentic analysis and context augmentation features

Set up agentic analysis and context augmentation using the SonarQube plugin or SonarQube CLI. See the [Make your agent verify its code](/agent-centric-development-cycle/verify/how-to-guides/make-your-agent-verify-its-code.md) and [Add context to generate better code](/agent-centric-development-cycle/guide/add-context-to-generate-better-code.md) pages.

When using these features, your `SONARQUBE_TOKEN` lets your local MCP server, configured for [Stdio](/sonarqube-mcp-server/setup/self-hosted.md#local-server-stdio) mode, authenticate to the SonarQube Cloud API. See [agentic analysis](/agent-centric-development-cycle/verify/how-to-guides/make-your-agent-verify-its-code.md) and [context augmentation](/agent-centric-development-cycle/guide/add-context-to-generate-better-code.md).

## SonarQube-hosted MCP server

Connect to a SonarQube-hosted MCP server to skip running your own MCP infrastructure and always use the current server version:

* SonarQube Cloud-hosted: the MCP server embedded in SonarQube Cloud. It exposes a smaller, fixed subset of tools. See the [SonarQube Cloud-hosted](/sonarqube-mcp-server/setup/sonarqube-cloud-hosted.md) page.
* SonarQube Server-hosted: the MCP server installed as an extension on SonarQube Server (Developer, Enterprise, and Data Center editions), available on SonarQube Server 2026.3 and newer. See the [SonarQube Server-hosted](/sonarqube-mcp-server/setup/sonarqube-server-hosted.md) page.

## Use Sonar tools from Claude Code

Once connected, Claude Code can call SonarQube MCP tools on your behalf. See the [tools](/sonarqube-mcp-server/reference/tools.md) page for the full list of available tools.


---

# 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-mcp-server/setup/quickstart-guides/claude-code.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.
