diff --git a/eng/common/mcp/azure-sdk-mcp.ps1 b/eng/common/mcp/azure-sdk-mcp.ps1 index b90d85b8cd..6a3c23ee6e 100755 --- a/eng/common/mcp/azure-sdk-mcp.ps1 +++ b/eng/common/mcp/azure-sdk-mcp.ps1 @@ -138,9 +138,34 @@ if (-not (Test-Path $toolInstallDirectory)) { } $exeName = Split-Path $tempExe -Leaf $exeDestination = Join-Path $toolInstallDirectory $exeName -Copy-Item -Path $tempExe -Destination $exeDestination -Force -log "Package $package is installed at $exeDestination" +# Try to copy the new version +$updateSucceeded = $false +try { + Copy-Item -Path $tempExe -Destination $exeDestination -Force + $updateSucceeded = $true +} +catch { + if ($Run -and (Test-Path $exeDestination)) { + # In MCP mode and the executable exists, warn and fall back to the existing installed version + log -warn "Could not update '$exeDestination': $($_.Exception.Message)" + log -warn "Falling back to the currently installed version." + } + else { + # In update-only mode or the executable does not exist, exit with error + log -err "Could not install or update '$exeDestination': $($_.Exception.Message)" + exit 1 + } +} + +# Clean up temp directory +if (Test-Path $tempInstallDirectory) { + Remove-Item -Path $tempInstallDirectory -Recurse -Force -ErrorAction SilentlyContinue +} + +if ($updateSucceeded) { + log "Executable $package 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." }