-
Notifications
You must be signed in to change notification settings - Fork 5
MCP-84 Add a new tool to fetch dependency risks from SonarQube Server #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/org/sonarsource/sonarqube/mcp/serverapi/sca/ScaApi.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* SonarQube MCP Server | ||
* Copyright (C) 2025 SonarSource | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the Sonar Source-Available License for more details. | ||
* | ||
* You should have received a copy of the Sonar Source-Available License | ||
* along with this program; if not, see https://sonarsource.com/license/ssal/ | ||
*/ | ||
package org.sonarsource.sonarqube.mcp.serverapi.sca; | ||
|
||
import com.google.gson.Gson; | ||
import javax.annotation.Nullable; | ||
import org.sonarsource.sonarqube.mcp.serverapi.ServerApiHelper; | ||
import org.sonarsource.sonarqube.mcp.serverapi.UrlBuilder; | ||
import org.sonarsource.sonarqube.mcp.serverapi.sca.response.DependencyRisksResponse; | ||
|
||
public class ScaApi { | ||
|
||
public static final String DEPENDENCY_RISKS_PATH = "/api/v2/sca/issues-releases"; | ||
|
||
private final ServerApiHelper helper; | ||
|
||
public ScaApi(ServerApiHelper helper) { | ||
this.helper = helper; | ||
} | ||
|
||
public DependencyRisksResponse getDependencyRisks(String projectKey, @Nullable String branchKey, @Nullable String pullRequestKey) { | ||
try (var response = helper.get(buildPath(projectKey, branchKey, pullRequestKey))) { | ||
var responseStr = response.bodyAsString(); | ||
return new Gson().fromJson(responseStr, DependencyRisksResponse.class); | ||
} | ||
} | ||
|
||
private static String buildPath(String projectKey, @Nullable String branchKey, @Nullable String pullRequestKey) { | ||
var builder = new UrlBuilder(DEPENDENCY_RISKS_PATH); | ||
builder.addParam("projectKey", projectKey); | ||
builder.addParam("branchKey", branchKey); | ||
builder.addParam("pullRequestKey", pullRequestKey); | ||
return builder.build(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...in/java/org/sonarsource/sonarqube/mcp/serverapi/sca/response/DependencyRisksResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* SonarQube MCP Server | ||
* Copyright (C) 2025 SonarSource | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the Sonar Source-Available License for more details. | ||
* | ||
* You should have received a copy of the Sonar Source-Available License | ||
* along with this program; if not, see https://sonarsource.com/license/ssal/ | ||
*/ | ||
package org.sonarsource.sonarqube.mcp.serverapi.sca.response; | ||
|
||
import java.util.List; | ||
|
||
public record DependencyRisksResponse(List<IssueRelease> issuesReleases, List<Branch> branches, Integer countWithoutFilters, Page page) { | ||
|
||
public record IssueRelease(String key, String severity, String originalSeverity, String manualSeverity, Boolean showIncreasedSeverityWarning, | ||
Release release, String type, String quality, String status, String createdAt, Assignee assignee, | ||
Integer commentCount, String vulnerabilityId, List<String> cweIds, String cvssScore, Boolean withdrawn, | ||
String spdxLicenseId, List<String> transitions, List<String> actions) { | ||
} | ||
|
||
public record Release(String key, String branchUuid, String packageUrl, String packageManager, String packageName, String version, | ||
String licenseExpression, Boolean known, Boolean knownPackage, Boolean newlyIntroduced, Boolean directSummary, | ||
String scopeSummary, Boolean productionScopeSummary, List<String> dependencyFilePaths) { | ||
} | ||
|
||
public record Assignee(String login, String name, String avatar, Boolean active) { | ||
} | ||
|
||
public record Branch(String uuid, String key, Boolean isPullRequest, String projectKey, String projectName) { | ||
} | ||
|
||
public record Page(Integer pageIndex, Integer pageSize, Integer total) { | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/org/sonarsource/sonarqube/mcp/serverapi/sca/response/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* SonarQube MCP Server | ||
* Copyright (C) 2025 SonarSource | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the Sonar Source-Available License for more details. | ||
* | ||
* You should have received a copy of the Sonar Source-Available License | ||
* along with this program; if not, see https://sonarsource.com/license/ssal/ | ||
*/ | ||
@ParametersAreNonnullByDefault | ||
package org.sonarsource.sonarqube.mcp.serverapi.sca.response; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; |
40 changes: 40 additions & 0 deletions
40
src/main/java/org/sonarsource/sonarqube/mcp/serverapi/settings/SettingsApi.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* SonarQube MCP Server | ||
* Copyright (C) 2025 SonarSource | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the Sonar Source-Available License for more details. | ||
* | ||
* You should have received a copy of the Sonar Source-Available License | ||
* along with this program; if not, see https://sonarsource.com/license/ssal/ | ||
*/ | ||
package org.sonarsource.sonarqube.mcp.serverapi.settings; | ||
|
||
import com.google.gson.Gson; | ||
import org.sonarsource.sonarqube.mcp.serverapi.ServerApiHelper; | ||
import org.sonarsource.sonarqube.mcp.serverapi.settings.response.ValuesResponse; | ||
|
||
public class SettingsApi { | ||
|
||
public static final String SETTINGS_PATH = "/api/settings/values"; | ||
|
||
private final ServerApiHelper helper; | ||
|
||
public SettingsApi(ServerApiHelper helper) { | ||
this.helper = helper; | ||
} | ||
|
||
public ValuesResponse getSettings() { | ||
try (var response = helper.get(SETTINGS_PATH)) { | ||
var responseStr = response.bodyAsString(); | ||
return new Gson().fromJson(responseStr, ValuesResponse.class); | ||
} | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/org/sonarsource/sonarqube/mcp/serverapi/settings/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* SonarQube MCP Server | ||
* Copyright (C) 2025 SonarSource | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the Sonar Source-Available License for more details. | ||
* | ||
* You should have received a copy of the Sonar Source-Available License | ||
* along with this program; if not, see https://sonarsource.com/license/ssal/ | ||
*/ | ||
@ParametersAreNonnullByDefault | ||
package org.sonarsource.sonarqube.mcp.serverapi.settings; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; |
64 changes: 64 additions & 0 deletions
64
src/main/java/org/sonarsource/sonarqube/mcp/serverapi/settings/response/ValuesResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* SonarQube MCP Server | ||
* Copyright (C) 2025 SonarSource | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the Sonar Source-Available License for more details. | ||
* | ||
* You should have received a copy of the Sonar Source-Available License | ||
* along with this program; if not, see https://sonarsource.com/license/ssal/ | ||
*/ | ||
package org.sonarsource.sonarqube.mcp.serverapi.settings.response; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import javax.annotation.Nullable; | ||
|
||
public record ValuesResponse( | ||
List<Setting> settings, | ||
@Nullable List<String> setSecuredSettings | ||
) { | ||
|
||
public record Setting( | ||
String key, | ||
@Nullable String value, | ||
@Nullable List<String> values, | ||
@Nullable List<Map<String, Object>> fieldValues, | ||
boolean inherited | ||
) {} | ||
|
||
/** | ||
* Helper method to get a specific setting value by key | ||
* @param key the setting key to look for | ||
* @return the setting value if found, null otherwise | ||
*/ | ||
public String getSettingValue(String key) { | ||
if (settings == null) { | ||
return null; | ||
} | ||
|
||
return settings.stream() | ||
.filter(setting -> key.equals(setting.key())) | ||
.map(Setting::value) | ||
.filter(Objects::nonNull) | ||
.findFirst() | ||
.orElse(null); | ||
} | ||
|
||
/** | ||
* Helper method to check if a boolean setting is enabled | ||
* @param key the setting key to check | ||
* @return true if the setting exists and is set to "true", false otherwise | ||
*/ | ||
public boolean isBooleanSettingEnabled(String key) { | ||
return "true".equalsIgnoreCase(getSettingValue(key)); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/org/sonarsource/sonarqube/mcp/serverapi/settings/response/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* SonarQube MCP Server | ||
* Copyright (C) 2025 SonarSource | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the Sonar Source-Available License for more details. | ||
* | ||
* You should have received a copy of the Sonar Source-Available License | ||
* along with this program; if not, see https://sonarsource.com/license/ssal/ | ||
*/ | ||
@ParametersAreNonnullByDefault | ||
package org.sonarsource.sonarqube.mcp.serverapi.settings.response; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.