# GitHub Copilot cloud agent

The [GitHub Copilot cloud agent](https://docs.github.com/en/copilot/concepts/agents/cloud-agent/about-cloud-agent) is an autonomous AI agent that operates inside your GitHub repository and CI/CD environment. Use this MCP server setup when you want Sonar tools available to the cloud agent during pull request workflows and automated tasks.

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

## 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](/agent-centric-development-cycle/developer-tools/mcp-server/reference/environment-variables.md#common-variables).
3. Choose a [hosting method](/agent-centric-development-cycle/developer-tools/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 cloud agent uses GitHub repository or organization secrets to supply environment variables to the MCP server. Only secrets with names prefixed with `COPILOT_MCP_` are available to your MCP configuration.

To add the required secrets to your repository, navigate to **Settings** > **Secrets and variables** > **Agents** > **Secrets** > **New repository secret**, and create one secret per environment variable your MCP server needs. To make the secrets available across all repositories in your organization, add them at the organization's **Settings** > **Secrets and variables** > **Agents** > **Secrets** > **New organization secret** instead.

For more details, see GitHub's documentation on [configuring secrets and variables for the Copilot cloud agent](https://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/configure-secrets-and-variables) and on [setting up a Copilot environment for Copilot cloud agent](https://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/extend-cloud-agent-with-mcp#setting-up-a-copilot-environment-for-copilot-cloud-agent).

The following [common variables](/agent-centric-development-cycle/developer-tools/mcp-server/reference/environment-variables.md#common-variables) are required, stored as `COPILOT_MCP_`-prefixed secrets:

* `SONARQUBE_TOKEN` (stored as `COPILOT_MCP_SONARQUBE_TOKEN`): Your SonarQube user token (stdio transport).
* `SONARQUBE_ORG` (stored as `COPILOT_MCP_SONARQUBE_ORG`): Your SonarQube Cloud organization key. Required for SonarQube Cloud only.
* `SONARQUBE_URL` (stored as `COPILOT_MCP_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.

### Transport options

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

#### Stdio (recommended)

Use [Stdio](/agent-centric-development-cycle/developer-tools/mcp-server/setup/self-hosted.md#local-server-stdio) when the cloud agent needs to spin up its own MCP server process within the CI/CD environment. It's also the transport mode used in your [Agentic Analysis](/agent-centric-development-cycle/features/agentic-analysis.md) and [Context Augmentation](/agent-centric-development-cycle/features/context-augmentation.md) workflows.

In your GitHub repository, navigate to **Settings** > **Code, planning, and automation** > **Copilot** > **Cloud agent** and add the following configuration in the MCP configuration section:

> **Warning:** *User tokens* are required when setting up connected mode or an MCP server between SonarQube Server and SonarQube for IDE. Your binding won't function properly if you use *project tokens*, *global tokens*, or *scoped organization tokens* during setup.

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

> **Note:** 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](/agent-centric-development-cycle/developer-tools/mcp-server/setup/environment-considerations.md#connecting-to-sonarqube-cloud-in-the-us-region) section for details.

**GitHub Copilot cloud agent with SonarQube Cloud**

```json
{
  "mcpServers": {
    "sonarqube": {
      "type": "local",
      "command": "docker",
      "args": [
        "run",
        "--init",
        "--pull=always",
        "--rm",
        "-i",
        "-e",
        "SONARQUBE_TOKEN=$SONAR_TOKEN",
        "-e",
        "SONARQUBE_ORG=$SONAR_ORG",
        "mcp/sonarqube"
      ],
      "env": {
        "SONAR_TOKEN": "COPILOT_MCP_SONARQUBE_TOKEN",
        "SONAR_ORG": "COPILOT_MCP_SONARQUBE_ORG",
        //"SONAR_URL": "COPILOT_MCP_SONARQUBE_URL"
      },
      "tools": ["*"]
    }
  }
}
```

**GitHub Copilot cloud agent with SonarQube Server**

```json
{
  "mcpServers": {
    "sonarqube": {
      "type": "local",
      "command": "docker",
      "args": [
        "run",
        "--init",
        "--pull=always",
        "--rm",
        "-i",
        "-e",
        "SONARQUBE_TOKEN=$SONAR_TOKEN",
        "-e",
        "SONARQUBE_URL=$SONAR_URL",
        "mcp/sonarqube"
      ],
      "env": {
        "SONAR_TOKEN": "COPILOT_MCP_SONARQUBE_TOKEN",
        "SONAR_URL": "COPILOT_MCP_SONARQUBE_URL"
      },
      "tools": ["*"]
    }
  }
}
```

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

> **Note:** No restart is required. Each Copilot cloud agent task runs in a fresh environment and picks up your updated `COPILOT_MCP_*` secrets automatically.

#### HTTPS

Use HTTPS when connecting the cloud agent to a shared MCP server deployed for a team. This requires an [HTTPS transport server](/agent-centric-development-cycle/developer-tools/mcp-server/setup/self-hosted.md#https) to be running and accessible.

In your GitHub repository, navigate to **Settings** > **Code, planning, and automation** > **Copilot** > **Cloud agent** and add the following configuration in the MCP configuration section:

```json
{
  "mcpServers": {
    "sonarqube": {
      "type": "https",
      "url": "https://<YourSonarQubeMCPServer>:8443/mcp",
      "headers": {
        "Authorization": "Bearer COPILOT_MCP_SONARQUBE_TOKEN"
      },
      "tools": ["*"]
    }
  }
}
```

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

> **Note:** No restart is required. Each Copilot cloud agent task runs in a fresh environment and picks up your updated `COPILOT_MCP_*` secrets automatically.

#### HTTP

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

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

In your GitHub repository, navigate to **Settings** > **Code, planning, and automation** > **Copilot** > **Cloud agent** and add the following configuration in the MCP configuration section:

```json
{
  "mcpServers": {
    "sonarqube": {
      "type": "http",
      "url": "http://<YourSonarQubeMCPServer>:8080/mcp",
      "headers": {
        "Authorization": "Bearer COPILOT_MCP_SONARQUBE_TOKEN"
      },
      "tools": ["*"]
    }
  }
}
```

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

> **Note:** No restart is required. Each Copilot cloud agent task runs in a fresh environment and picks up your updated `COPILOT_MCP_*` secrets automatically.

## Agentic analysis and context augmentation

When using Agentic Analysis and Context Augmentation services, your `SONARQUBE_TOKEN` lets your local MCP server configured for [Stdio](/agent-centric-development-cycle/developer-tools/mcp-server/setup/self-hosted.md#local-server-stdio) mode authenticate to the SonarQube Cloud API. See [Agentic Analysis](/agent-centric-development-cycle/features/agentic-analysis.md) and [Context Augmentation](/agent-centric-development-cycle/features/context-augmentation.md) for more information.

## SonarQube Cloud-hosted MCP server

Use the SonarQube Cloud-hosted MCP server to avoid running and maintaining your own MCP infrastructure while always using the current server version. The embedded server exposes a smaller, fixed subset of tools; for the available toolsets and configuration details, see the [SonarQube Cloud-hosted](/agent-centric-development-cycle/developer-tools/mcp-server/setup/sonarqube-cloud-hosted.md) page.

## Use Sonar tools from the cloud agent

Once connected, the GitHub Copilot cloud agent can call SonarQube MCP tools during its automated workflows. See the [tools](/agent-centric-development-cycle/developer-tools/mcp-server/reference/tools.md) page for the full list of available tools.


---

# 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/developer-tools/mcp-server/setup/quickstart-guides/github-copilot-cloud-agent.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.
