-
Notifications
You must be signed in to change notification settings - Fork 176
Azure MCP support for GitHub Copilot #11066
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 all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0416651
Azure MCP for GitHub Copilot
srnagar d338386
minor updates
srnagar 005cbc5
Use aka.ms link and add registry key to opt-out of Azure MCP
srnagar da036ba
Merge remote-tracking branch 'upstream/develop' into az-mcp
srnagar 9e686f2
check download file integrity
srnagar b3cfb3c
use lombok
srnagar 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
20 changes: 20 additions & 0 deletions
20
...insAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-azuremcp/build.gradle.kts
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 @@ | ||
dependencies { | ||
implementation(project(":azure-intellij-plugin-lib")) | ||
implementation(project(":azure-intellij-plugin-lib-java")) | ||
implementation("com.microsoft.azure:azure-toolkit-common-lib") | ||
implementation("com.microsoft.azure:azure-toolkit-ide-common-lib") | ||
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1") | ||
testImplementation("org.mockito:mockito-core:3.9.0") | ||
|
||
intellijPlatform { | ||
// Plugin Dependencies. Uses `platformBundledPlugins` property from the gradle.properties file for bundled IntelliJ Platform plugins. | ||
bundledPlugin("com.intellij.java") | ||
bundledPlugin("org.jetbrains.idea.maven") | ||
bundledPlugin("org.jetbrains.idea.maven.model") | ||
bundledPlugin("com.intellij.gradle") | ||
} | ||
|
||
tasks.named("test", Test::class) { | ||
useJUnitPlatform() | ||
} | ||
} |
192 changes: 192 additions & 0 deletions
192
...p/src/main/java/com/microsoft/azure/toolkit/intellij/azuremcp/AzureMcpPackageManager.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,192 @@ | ||
package com.microsoft.azure.toolkit.intellij.azuremcp; | ||
|
||
import com.intellij.openapi.application.PathManager; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.codec.digest.DigestUtils; | ||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; | ||
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; | ||
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.commons.lang3.SystemUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.annotation.Nullable; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.StandardOpenOption; | ||
import java.util.Optional; | ||
|
||
@Slf4j | ||
public class AzureMcpPackageManager { | ||
private final GithubClient gitHubClient; | ||
private final String platform; | ||
|
||
public AzureMcpPackageManager() { | ||
this.gitHubClient = new GithubClient(); | ||
this.platform = getPlatformIdentifier(); | ||
} | ||
|
||
@Nullable | ||
public synchronized File getAzureMcpExecutable() { | ||
try { | ||
final GithubRelease latestRelease = gitHubClient.getLatestAzureMcpRelease(); | ||
if (latestRelease != null && latestRelease.getAssets() != null) { | ||
final String tagName = latestRelease.getTagName(); | ||
log.info("Latest version of Azure MCP: " + tagName); | ||
|
||
final Optional<GithubAsset> githubAsset = latestRelease.getAssets() | ||
.stream() | ||
.filter(asset -> asset.getName().contains(platform)) | ||
.findFirst(); | ||
|
||
if (githubAsset.isPresent()) { | ||
final GithubAsset asset = githubAsset.get(); | ||
log.info("Azure MCP package for current platform: " + asset.getName()); | ||
final long startTime = System.currentTimeMillis(); | ||
final String azMcpDir = PathManager.getPluginsPath() + "/azure-toolkit-for-intellij/azmcp"; | ||
final File azMcpDirFile = new File(azMcpDir); | ||
if (azMcpDirFile.exists() || azMcpDirFile.mkdirs()) { | ||
final Path versionFile = Path.of(azMcpDir + "/version.txt"); | ||
|
||
final File extractedDir = new File(azMcpDirFile, "/azmcp_package_" + tagName); | ||
extractedDir.mkdirs(); | ||
final String executablePath = extractedDir.getAbsolutePath() + getExecutableRelativePath(); | ||
final File azMcpExe = new File(executablePath); | ||
if (!azMcpExe.exists()) { | ||
Files.writeString(versionFile, tagName, StandardOpenOption.CREATE, StandardOpenOption.WRITE); | ||
final File azMcpTgz = new File(azMcpDir, "azmcp_" + tagName + ".tgz"); | ||
log.info("Downloading Azure MCP Server to: " + azMcpTgz.getAbsolutePath()); | ||
final boolean downloaded = gitHubClient.downloadToFile(asset.getBrowserDownloadUrl(), azMcpTgz); | ||
if (downloaded && digestMatches(azMcpTgz, asset.getDigest())) { | ||
log.info("Downloaded Azure MCP Server successfully in " + (System.currentTimeMillis() - startTime) + " ms"); | ||
log.info("Extracting Azure MCP Server to: " + extractedDir.getAbsolutePath()); | ||
extractTarGz(azMcpTgz, extractedDir); | ||
log.info("Azure MCP Server extracted successfully to: " + extractedDir.getAbsolutePath()); | ||
} | ||
} | ||
|
||
if (azMcpExe.exists() && (azMcpExe.canExecute() || azMcpExe.setExecutable(true))) { | ||
log.info("Azure MCP Server executable found at: " + azMcpExe.getAbsolutePath()); | ||
return azMcpExe; | ||
} | ||
} | ||
} | ||
} | ||
} catch (final IOException e) { | ||
System.err.println("Error reading Azure MCP Server version: " + e.getMessage()); | ||
} | ||
return null; | ||
} | ||
|
||
private boolean digestMatches(File azMcpTgz, String expectedDigest) { | ||
try { | ||
// GitHub releases API computes the SHA-256 digest of the file contents. | ||
// https://github.blog/changelog/2025-06-03-releases-now-expose-digests-for-release-assets/ | ||
final String downloadFileDigest = DigestUtils.sha256Hex(new FileInputStream(azMcpTgz)); | ||
return StringUtils.equalsIgnoreCase("sha256:" + downloadFileDigest, expectedDigest); | ||
} catch (final Exception e) { | ||
log.error("Failed to calculate file digest", e); | ||
return false; | ||
} | ||
} | ||
|
||
public synchronized void cleanup() { | ||
try { | ||
final String azMcpDir = PathManager.getPluginsPath() + "/azure-toolkit-for-intellij/azmcp"; | ||
final File azMcpDirFile = new File(azMcpDir); | ||
if (!azMcpDirFile.exists()) { | ||
return; | ||
} | ||
|
||
final Path versionFile = Path.of(azMcpDir + "/version.txt"); | ||
String currentVersion = null; | ||
if (versionFile.toFile().exists()) { | ||
currentVersion = new String(Files.readAllBytes(versionFile)); | ||
} | ||
|
||
final Path currentPackage = Path.of(azMcpDir + "/azmcp_package_" + currentVersion).toAbsolutePath(); | ||
Files.list(Path.of(azMcpDir)) | ||
.filter(path -> !path.equals(currentPackage)) | ||
.filter(path -> !path.equals(versionFile)) | ||
.forEach(path -> { | ||
delete(path); | ||
}); | ||
|
||
} catch (final Exception exception) { | ||
System.err.println("Error cleaning up Azure MCP Server: " + exception.getMessage()); | ||
} | ||
} | ||
|
||
private static void delete(Path path) { | ||
try { | ||
if (path.toFile().isDirectory()) { | ||
Files.list(path).forEach(AzureMcpPackageManager::delete); | ||
} | ||
Files.delete(path); | ||
} catch (final IOException e) { | ||
System.err.println("Error deleting file: " + path.toString()); | ||
} | ||
} | ||
|
||
private @NotNull String getExecutableRelativePath() { | ||
String executablePath = "/package/dist/azmcp"; | ||
if (SystemUtils.IS_OS_WINDOWS) { | ||
executablePath += ".exe"; | ||
} | ||
return executablePath; | ||
} | ||
|
||
private void extractTarGz(File tarGzFile, File destDir) throws IOException { | ||
try (final TarArchiveInputStream tarIn = new TarArchiveInputStream( | ||
new GzipCompressorInputStream( | ||
new FileInputStream(tarGzFile)))) { | ||
TarArchiveEntry entry; | ||
while ((entry = tarIn.getNextTarEntry()) != null) { | ||
final File outputFile = new File(destDir, entry.getName()); | ||
if (entry.isDirectory()) { | ||
if (!outputFile.exists()) { | ||
outputFile.mkdirs(); | ||
} | ||
} else { | ||
outputFile.getParentFile().mkdirs(); | ||
try (final FileOutputStream fos = new FileOutputStream(outputFile)) { | ||
tarIn.transferTo(fos); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static String getPlatformIdentifier() { | ||
// Operating System detection | ||
String os = null; | ||
if (SystemUtils.IS_OS_WINDOWS) { | ||
os = "win32"; | ||
} else if (SystemUtils.IS_OS_LINUX) { | ||
os = "linux"; | ||
} else if (SystemUtils.IS_OS_MAC) { | ||
os = "darwin"; | ||
} else { | ||
throw new RuntimeException("Unsupported OS " + SystemUtils.OS_NAME); | ||
} | ||
final String arch = getArch(); | ||
return os + "-" + arch; | ||
} | ||
|
||
private static String getArch() { | ||
final String arch = SystemUtils.OS_ARCH.toLowerCase(); | ||
if (arch.contains("amd64") || arch.contains("x86_64") || arch.contains("x64")) { | ||
return "x64"; | ||
} | ||
if (arch.contains("aarch64") || arch.contains("arm64")) { | ||
return "arm64"; | ||
} | ||
throw new RuntimeException("Unsupported architecture: " + arch); | ||
} | ||
|
||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...gin-azuremcp/src/main/java/com/microsoft/azure/toolkit/intellij/azuremcp/GithubAsset.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,37 @@ | ||
package com.microsoft.azure.toolkit.intellij.azuremcp; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class GithubAsset { | ||
srnagar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@JsonProperty("url") | ||
private String url; | ||
@JsonProperty("browser_download_url") | ||
private String browserDownloadUrl; | ||
@JsonProperty("id") | ||
private long id; | ||
@JsonProperty("node_id") | ||
private String nodeId; | ||
@JsonProperty("name") | ||
private String name; | ||
@JsonProperty("label") | ||
private String label; | ||
@JsonProperty("state") | ||
private String state; | ||
@JsonProperty("content_type") | ||
private String contentType; | ||
@JsonProperty("size") | ||
private long size; | ||
@JsonProperty("digest") | ||
private String digest; | ||
@JsonProperty("download_count") | ||
private int downloadCount; | ||
@JsonProperty("created_at") | ||
private String createdAt; | ||
@JsonProperty("updated_at") | ||
private String updatedAt; | ||
@JsonProperty("uploader") | ||
private GithubUser uploader; | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
...in-azuremcp/src/main/java/com/microsoft/azure/toolkit/intellij/azuremcp/GithubClient.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,58 @@ | ||
package com.microsoft.azure.toolkit.intellij.azuremcp; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
import org.apache.http.client.methods.HttpUriRequest; | ||
import org.apache.http.client.methods.RequestBuilder; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClients; | ||
|
||
import java.io.Closeable; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class GithubClient implements Closeable { | ||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper() | ||
.configure(JsonParser.Feature.ALLOW_COMMENTS, true) | ||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) | ||
.setSerializationInclusion(JsonInclude.Include.NON_NULL) | ||
.enable(SerializationFeature.INDENT_OUTPUT); | ||
private static final String AZURE_MCP_RELEASE_URL = "https://aka.ms/azmcp/releases"; | ||
private static final TypeReference<List<GithubRelease>> GITHUB_RELEASE_LIST_TYPE = new TypeReference<>() { | ||
}; | ||
|
||
private final CloseableHttpClient httpClient = HttpClients.createDefault(); | ||
|
||
public GithubRelease getLatestAzureMcpRelease() { | ||
final HttpUriRequest request = RequestBuilder.get().setUri(AZURE_MCP_RELEASE_URL).build(); | ||
try (final CloseableHttpResponse response = httpClient.execute(request)) { | ||
final List<GithubRelease> releases = OBJECT_MAPPER.readValue(response.getEntity().getContent(), GITHUB_RELEASE_LIST_TYPE); | ||
return releases.stream().findFirst().orElse(null); | ||
} catch (final IOException exception) { | ||
return null; | ||
} | ||
} | ||
|
||
public boolean downloadToFile(String downloadUrl, File downloadFile) { | ||
final HttpUriRequest downloadRequest = RequestBuilder.get().setUri(downloadUrl).build(); | ||
try (final CloseableHttpResponse downloadResponse = httpClient.execute(downloadRequest); | ||
final FileOutputStream fos = new FileOutputStream(downloadFile)) { | ||
downloadResponse.getEntity().getContent().transferTo(fos); | ||
return true; | ||
} catch (final IOException exception) { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
this.httpClient.close(); | ||
} | ||
} |
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.