MCP Server does not connect to SonarQube

I am trying to run a sonarQube MCP server locally (on windows) that should connect to our SonarQube server (version 2025.1.1.104738, I am not the admin, just a user).
Building works fine, but the authentication fails with:

Exception in thread "main" org.sonarsource.sonarqube.mcp.serverapi.exception.UnauthorizedException: SonarQube answered with Not authorized. Please check server credentials.
        at org.sonarsource.sonarqube.mcp.serverapi.ServerApiHelper.handleError(ServerApiHelper.java:99)
        at org.sonarsource.sonarqube.mcp.serverapi.ServerApiHelper.get(ServerApiHelper.java:51)
        at org.sonarsource.sonarqube.mcp.serverapi.plugins.PluginsApi.getInstalled(PluginsApi.java:36)
        at org.sonarsource.sonarqube.mcp.plugins.PluginsSynchronizer.synchronizeAnalyzers(PluginsSynchronizer.java:48)
        at org.sonarsource.sonarqube.mcp.SonarQubeMcpServer.start(SonarQubeMcpServer.java:120)
        at org.sonarsource.sonarqube.mcp.SonarQubeMcpServer.main(SonarQubeMcpServer.java:73)

I can access do successfully things like:
curl -u %SONARQUBE_TOKEN%: %SONARQUBE_ORG%/api/plugins/installed, so the token seems to be fine.
I tried it with a user token and a project analysis token.
Is there an error on my side?
What can I do to debug the problem?
Is there something the server administrator has to do to enable access for me or for the MCP server?
Thanks for your time!

Hey there.

Can you share how you’ve configured your MCP server?

Right now I have been starting the jar file directly with the environment variables STORAGE_PATH, SONARQUBE_TOKEN, SONARQUBE_URL set.
I also tried it from within visual studio code with this setup

 "mcp.servers": {
    "sonarqube": {
      "command": "java",
      "args": [
        "-jar",
        "f:/Projects/sonarqube-mcp-server/build/libs/sonarqube-mcp-server-0.0.2-SNAPSHOT.jar"
      ],
      "env": {
        "STORAGE_PATH": "F:\\Projects\\sonarqube-mcp-server\\storage",
        "SONARQUBE_TOKEN": "MY_TOKEN",
        "SONARQUBE_URL": "SONAR_URL"
      }
    }
  }

(I put in actual tokens, I just do not want to post them)
Anything else I need to do or check?

Hello @chr, can you please try using the latest version 0.0.3?

Also, the token has to be a USER token, this is important.

Is there something the server administrator has to do to enable access for me or for the MCP server?

There should be nothing to do on SonarQube Server side.

I have built the latest version from git and made sure that it is a user token. Same result as above.
One more thing: The server has about a dozen projects, my user token has only access rights to one project. Is that an issue? I did not see a project key parameter.

I’m surprised that this doesn’t work, especially if the curl command does.

One more thing: The server has about a dozen projects, my user token has only access rights to one project. Is that an issue? I did not see a project key parameter.

The synchronization on which the issue is happening does not require any project key, we are downloading plugins to run our analyzer and it’s global to your SonarQube Server instance.

I can access do successfully things like:
curl -u %SONARQUBE_TOKEN%: %SONARQUBE_ORG%/api/plugins/installed, so the token seems to be fine.

Just for confirmation, are you effectively querying your SonarQube Server and not SonarQube Cloud? I’m asking because you mentioned SONARQUBE_ORG.

Ideally, you could also try our Docker image and see if you reproduce the issue, this is usually the best way to use our MCP server.

Yes, I am querying, our SonarQube Server, not SonarQube cloud. It really looks like an authorization issue though, I could query the project with a skeleton mcp I have setup, that only queries the particular project. I will try out docker and see how that works.

I have downloaded MCP server and built it using JDK21. Now during connection to SonarCube server I am facing below error:

Error: LinkageError occurred while loading main class org.sonarsource.sonarqube.mcp.SonarQubeMcpServer java.lang.UnsupportedClassVersionError: org/sonarsource/sonarqube/mcp/SonarQubeMcpServer has been compiled by a more recent version of the Java Runtime (class file version 65.0), this version of the Java Runtime only recognizes class file versions up to 61.0 MCP error -32000: Connection closed

On asking sonarcube server team they suggested to check with MCP server team. Can you please suggest is there any lower version code / support available for SonarCube MCP server ?

While you may have built it with Java 21, it looks like it is being run by Java 17. You should make sure that java in your environment is pointing to Java 21, or adjust the command used to start your MCP server to point to a Java 21 distro.

1 Like