Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions eng/common/mcp/azure-sdk-mcp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#Requires -PSEdition Core

param(
[string]$FileName = 'Azure.Sdk.Tools.Cli',
[string]$Package = 'azsdk',
[string]$Version, # Default to latest
[string]$InstallDirectory = '',
[string]$Repository = 'Azure/azure-sdk-tools',
Expand All @@ -15,11 +13,14 @@ param(
[switch]$UpdatePathInProfile
)

$ErrorActionPreference = "Stop"
$ErrorActionPreference = 'Stop'
. (Join-Path $PSScriptRoot '..' 'scripts' 'Helpers' 'AzSdkTool-Helpers.ps1')

$toolInstallDirectory = $InstallDirectory ? $InstallDirectory : (Get-CommonInstallDirectory)
Comment thread
benbp marked this conversation as resolved.

$packageName = 'azsdk'
$packageFileName = 'Azure.Sdk.Tools.Cli'

$mcpMode = $Run

# Log to console or MCP client json-rpc
Expand Down Expand Up @@ -103,14 +104,35 @@ $tmp = $env:TEMP ? $env:TEMP : [System.IO.Path]::GetTempPath()
$guid = [System.Guid]::NewGuid()
$tempInstallDirectory = Join-Path $tmp "azsdk-install-$($guid)"

# If already installed, use first class version mechanism
$azsdkCmd = Get-Command -ErrorAction SilentlyContinue $packageName
if ($azsdkCmd -and !$InstallDirectory) {
$ErrorActionPreference = "Stop"
$upgrade = & $packageName upgrade --check --output json | out-string
if (!$LASTEXITCODE) {
$ErrorActionPreference = 'Ignore'
$localVersion = $upgrade | ConvertFrom-Json -AsHashtable
$ErrorActionPreference = 'Stop'
if ($localVersion.old_version -and $localVersion.old_version -eq ($Version ? $Version : $localVersion.new_version)) {
log "Version up to date at $($localVersion.old_version)"
if ($Run) {
$proc = Start-Process -PassThru -WorkingDirectory $RunDirectory -FilePath $azsdkCmd.Path -ArgumentList 'mcp' -NoNewWindow -Wait
exit $proc.ExitCode
}
exit 0
}
Comment thread
benbp marked this conversation as resolved.
log "Version not up to date at " + $localVersion.old_version
}
}

if ($mcpMode) {
try {
# Swallow all output and re-log so we can wrap any
# output from the inner function as json-rpc
$tempExe = Install-Standalone-Tool `
-Version $Version `
-FileName $FileName `
-Package $Package `
-FileName $packageFileName `
-Package $packageName `
-Directory $tempInstallDirectory `
-Repository $Repository `
*>&1
Expand All @@ -126,8 +148,8 @@ if ($mcpMode) {
else {
$tempExe = Install-Standalone-Tool `
-Version $Version `
-FileName $FileName `
-Package $Package `
-FileName $packageFileName `
-Package $packageName `
-Directory $tempInstallDirectory `
-Repository $Repository `

Expand Down Expand Up @@ -164,7 +186,7 @@ if (Test-Path $tempInstallDirectory) {
}

if ($updateSucceeded) {
log "Executable $package is installed at $exeDestination"
log "Executable $packageName is installed at $exeDestination"
}
if (!$UpdatePathInProfile) {
log -warn "To add the tool to PATH for new shell sessions, re-run with -UpdatePathInProfile to modify the shell profile file."
Expand All @@ -175,5 +197,6 @@ else {
}

if ($Run) {
Start-Process -WorkingDirectory $RunDirectory -FilePath $exeDestination -ArgumentList 'start' -NoNewWindow -Wait
$proc = Start-Process -PassThru -WorkingDirectory $RunDirectory -FilePath $exeDestination -ArgumentList 'mcp' -NoNewWindow -Wait
exit $proc.ExitCode
}
Loading