From 20ff59e2e1a55ab69e07ef8d069e524b98d7803d Mon Sep 17 00:00:00 2001 From: Ben Broderick Phillips Date: Tue, 24 Mar 2026 18:50:22 -0700 Subject: [PATCH 1/4] Only install azsdk when there is a new version --- eng/common/mcp/azure-sdk-mcp.ps1 | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/eng/common/mcp/azure-sdk-mcp.ps1 b/eng/common/mcp/azure-sdk-mcp.ps1 index 6a3c23ee6eaf..ba405a66cdfb 100755 --- a/eng/common/mcp/azure-sdk-mcp.ps1 +++ b/eng/common/mcp/azure-sdk-mcp.ps1 @@ -103,6 +103,24 @@ $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 'azsdk' +if ($azsdkCmd) { + $upgrade = azsdk upgrade --check --output json | out-string + if (!$LASTEXITCODE) { + $localVersion = $upgrade | ConvertFrom-Json -AsHashtable + if ($localVersion.old_version -eq $localVersion.new_version) { + log "Version up to date at $($localVersion.old_version)" + if ($Run) { + $proc = Start-Process -PassThru -WorkingDirectory $RunDirectory -FilePath $azsdkCmd.Source -ArgumentList 'mcp' -NoNewWindow -Wait + exit $proc.ExitCode + } + exit 0 + } + log "Version not up to date at " + $localVersion.old_version + } +} + if ($mcpMode) { try { # Swallow all output and re-log so we can wrap any @@ -175,5 +193,5 @@ else { } if ($Run) { - Start-Process -WorkingDirectory $RunDirectory -FilePath $exeDestination -ArgumentList 'start' -NoNewWindow -Wait + Start-Process -WorkingDirectory $RunDirectory -FilePath $exeDestination -ArgumentList 'mcp' -NoNewWindow -Wait } From ddc21a2e6505d271b889581e5de54a124b76b443 Mon Sep 17 00:00:00 2001 From: Ben Broderick Phillips Date: Tue, 24 Mar 2026 19:01:05 -0700 Subject: [PATCH 2/4] Use get-command path property instead of source --- eng/common/mcp/azure-sdk-mcp.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/mcp/azure-sdk-mcp.ps1 b/eng/common/mcp/azure-sdk-mcp.ps1 index ba405a66cdfb..5e102d0fa2fa 100755 --- a/eng/common/mcp/azure-sdk-mcp.ps1 +++ b/eng/common/mcp/azure-sdk-mcp.ps1 @@ -112,7 +112,7 @@ if ($azsdkCmd) { if ($localVersion.old_version -eq $localVersion.new_version) { log "Version up to date at $($localVersion.old_version)" if ($Run) { - $proc = Start-Process -PassThru -WorkingDirectory $RunDirectory -FilePath $azsdkCmd.Source -ArgumentList 'mcp' -NoNewWindow -Wait + $proc = Start-Process -PassThru -WorkingDirectory $RunDirectory -FilePath $azsdkCmd.Path -ArgumentList 'mcp' -NoNewWindow -Wait exit $proc.ExitCode } exit 0 From ce01c089eb70bf8ab1ee4aeef19c67310a884775 Mon Sep 17 00:00:00 2001 From: Ben Broderick Phillips Date: Tue, 24 Mar 2026 19:04:02 -0700 Subject: [PATCH 3/4] Only use pre-install bypass when version and install directory are not set --- eng/common/mcp/azure-sdk-mcp.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/mcp/azure-sdk-mcp.ps1 b/eng/common/mcp/azure-sdk-mcp.ps1 index 5e102d0fa2fa..a65aa18d30c4 100755 --- a/eng/common/mcp/azure-sdk-mcp.ps1 +++ b/eng/common/mcp/azure-sdk-mcp.ps1 @@ -105,7 +105,7 @@ $tempInstallDirectory = Join-Path $tmp "azsdk-install-$($guid)" # If already installed, use first class version mechanism $azsdkCmd = Get-Command -ErrorAction SilentlyContinue 'azsdk' -if ($azsdkCmd) { +if ($azsdkCmd -and !$Version -and !$InstallDirectory) { $upgrade = azsdk upgrade --check --output json | out-string if (!$LASTEXITCODE) { $localVersion = $upgrade | ConvertFrom-Json -AsHashtable From 5107409b446ac4a1da3247a782343110e97148bd Mon Sep 17 00:00:00 2001 From: Ben Broderick Phillips Date: Wed, 25 Mar 2026 14:13:07 -0700 Subject: [PATCH 4/4] More logic improvements around version install specification --- eng/common/mcp/azure-sdk-mcp.ps1 | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/eng/common/mcp/azure-sdk-mcp.ps1 b/eng/common/mcp/azure-sdk-mcp.ps1 index a65aa18d30c4..3026895afe6d 100755 --- a/eng/common/mcp/azure-sdk-mcp.ps1 +++ b/eng/common/mcp/azure-sdk-mcp.ps1 @@ -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', @@ -15,11 +13,14 @@ param( [switch]$UpdatePathInProfile ) -$ErrorActionPreference = "Stop" +$ErrorActionPreference = 'Stop' . (Join-Path $PSScriptRoot '..' 'scripts' 'Helpers' 'AzSdkTool-Helpers.ps1') $toolInstallDirectory = $InstallDirectory ? $InstallDirectory : (Get-CommonInstallDirectory) +$packageName = 'azsdk' +$packageFileName = 'Azure.Sdk.Tools.Cli' + $mcpMode = $Run # Log to console or MCP client json-rpc @@ -104,12 +105,15 @@ $guid = [System.Guid]::NewGuid() $tempInstallDirectory = Join-Path $tmp "azsdk-install-$($guid)" # If already installed, use first class version mechanism -$azsdkCmd = Get-Command -ErrorAction SilentlyContinue 'azsdk' -if ($azsdkCmd -and !$Version -and !$InstallDirectory) { - $upgrade = azsdk upgrade --check --output json | out-string +$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 - if ($localVersion.old_version -eq $localVersion.new_version) { + $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 @@ -127,8 +131,8 @@ if ($mcpMode) { # 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 @@ -144,8 +148,8 @@ if ($mcpMode) { else { $tempExe = Install-Standalone-Tool ` -Version $Version ` - -FileName $FileName ` - -Package $Package ` + -FileName $packageFileName ` + -Package $packageName ` -Directory $tempInstallDirectory ` -Repository $Repository ` @@ -182,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." @@ -193,5 +197,6 @@ else { } if ($Run) { - Start-Process -WorkingDirectory $RunDirectory -FilePath $exeDestination -ArgumentList 'mcp' -NoNewWindow -Wait + $proc = Start-Process -PassThru -WorkingDirectory $RunDirectory -FilePath $exeDestination -ArgumentList 'mcp' -NoNewWindow -Wait + exit $proc.ExitCode }