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
66 changes: 49 additions & 17 deletions eng/common/mcp/azure-sdk-mcp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,51 @@ $tempInstallDirectory = Join-Path $tmp "azsdk-install-$($guid)"

# If already installed, use first class version mechanism
$azsdkCmd = Get-Command -ErrorAction Ignore $packageName
# Also check the default install directory (~/bin) in case it's not on PATH
if (!$azsdkCmd -and !$InstallDirectory) {
$existingExe = Join-Path $toolInstallDirectory ($IsWindows ? "$packageName.exe" : $packageName)
if (Test-Path -PathType Leaf $existingExe) {
$azsdkCmd = Get-Command -ErrorAction Ignore $existingExe
}
}
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 -and $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
try {
$ErrorActionPreference = "Stop"
$upgrade = & $azsdkCmd.Path upgrade --check --output json | out-string
if (!$LASTEXITCODE) {
$ErrorActionPreference = 'Ignore'
$localVersion = $upgrade | ConvertFrom-Json -AsHashtable
$ErrorActionPreference = 'Stop'
if ($localVersion -and $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
}
if ($localVersion) {
log "Version not up to date at " + $localVersion.old_version
} else {
log "Failed to parse version:"
log $upgrade
}
exit 0
} elseif ($Run) {
# Upgrade check failed (e.g. network error, rate limit, timeout),
# but the binary already exists — fall back to running it as-is
# rather than attempting a fresh install that will likely also fail.
log -warn "Upgrade check failed, falling back to existing installation at '$($azsdkCmd.Path)'"
$proc = Start-Process -PassThru -WorkingDirectory $RunDirectory -FilePath $azsdkCmd.Path -ArgumentList 'mcp' -NoNewWindow -Wait
exit $proc.ExitCode
}
if ($localVersion) {
log "Version not up to date at " + $localVersion.old_version
} else {
log "Failed to parse version:"
log $upgrade
}
catch {
if ($Run) {
log -warn "Upgrade check error: $($_.Exception.Message). Falling back to existing installation."
$proc = Start-Process -PassThru -WorkingDirectory $RunDirectory -FilePath $azsdkCmd.Path -ArgumentList 'mcp' -NoNewWindow -Wait
exit $proc.ExitCode
}
throw
}
}

Expand All @@ -147,6 +171,14 @@ if ($mcpMode) {
}
catch {
log -err $_
# If install failed but an existing binary is available, fall back to it
# instead of exiting (which causes the MCP client to respawn in a loop).
$existingExe = Join-Path $toolInstallDirectory ($IsWindows ? "$packageName.exe" : $packageName)
if ($Run -and (Test-Path -PathType Leaf $existingExe)) {
log -warn "Installation failed, falling back to existing installation at '$existingExe'"
$proc = Start-Process -PassThru -WorkingDirectory $RunDirectory -FilePath $existingExe -ArgumentList 'mcp' -NoNewWindow -Wait
exit $proc.ExitCode
}
exit 1
}
}
Expand Down
Loading