How to configure Sonar MCP Server on Copilot Coding Agent from my GitHub repository

I need help configuring Sonar’s MCP in the Copilot Coding Agent from the GitHub repository. https://github.com/ORG/REPO/settings/copilot/coding_agent
The configuration is the same as found at?

Can you give me an example or guide?

Thank you very much.

Hey there.

This README is exactly where you should be looking at.

Where do you get stuck?

Hi my friend,

For local configuration in my IDE (VSCode), it worked exactly as in the documentation.

To configure the Copilot Code Agent from the GitHub Repository, I needed to make a small change. Here’s how it worked:

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

You can still add variables or secrets for JSON to use here:

https://github.com/ORG/REPO/settings/secrets/actions

1 Like

Hello,

Thank you for bringing this to our attention! We’ll update our documentation to include configuration with GitHub Copilot Agent. For reference, here is the related ticket on our side.

As a side note, you don’t need to provide both SONARQUBE_URL and SONARQUBE_ORG simultaneously:

  • If you provide SONARQUBE_ORG, you’ll automatically be redirected to sonarcloud.io.

  • If you provide SONARQUBE_URL, you should specify your own SonarQube Server host. In this case, the SONARQUBE_ORG parameter is not required, since it applies only to SonarCloud.

Thank you very much, I’m happy to contribute. You also raised a great point: we are indeed using SonarCloud.

Hello Lucas, thank you for sharing as I am interested in learning more. I am trying to see if I can configure GitHub Copilot to interact with our SonarQube Server Enterprise. As developers are engaging with GitHub Copilot, then GitHub Copilot can engage the SonarQube MCP Server to connect to our SonarQube Enterprise Server to consider all of the Quality Rules and Quality Criteria we have established. I wonder if this is possible and potentially leveraging GitHub Copilot custom instructions.

Hello @John.Morales,

I’m not sure I got your question right. Please have a look at this page, more specifically the section about configuring the MCP server and the SonarQube IDE extension to allow something close to what you suggest:

This rule file contains instructions for the agent on how to effectively utilize SonarQube MCP Server. As an example, it instructs the agent to disable SonarQube automatic analysis before starting code generation, and to enable it after the generation is complete. It also asks the agent to analyze changed files in batches, once the changes are done.

Does that help?