bash
# MATLAB Toolkits Auto Update Checker (Unified)
# Can be run standalone (dir = script location) or called with -ScriptDir "D:\path"
param($ScriptDir)
$dir = if ($ScriptDir) { $ScriptDir.TrimEnd('\') } else { $PSScriptRoot }
$repos = @(
[PSCustomObject]@{
Name = 'MATLAB MCP Server'
Api = 'https://api.github.com/repos/matlab/matlab-mcp-server/releases/latest'
Page = 'https://github.com/matlab/matlab-mcp-server/releases/latest'
TagFile = '.matlab-mcp-server.version'
Assets = @(
[PSCustomObject]@{ Remote = 'matlab-mcp-server-windows-x64.exe'; Local = 'matlab-mcp-server-windows-x64.exe' }
[PSCustomObject]@{ Remote = 'MATLABMCPServerToolbox.mltbx'; Local = 'MATLABMCPServerToolbox.mltbx' }
)
},
[PSCustomObject]@{
Name = 'MATLAB Agentic Toolkit'
Api = 'https://api.github.com/repos/matlab/matlab-agentic-toolkit/releases/latest'
Page = 'https://github.com/matlab/matlab-agentic-toolkit/releases/latest'
TagFile = '.agentic-toolkit-tag'
Assets = @(
[PSCustomObject]@{ Remote = 'agenticToolkitInstaller.mltbx'; Local = 'agenticToolkitInstaller.mltbx' }
)
},
[PSCustomObject]@{
Name = 'Simulink Agentic Toolkit'
Api = 'https://api.github.com/repos/matlab/simulink-agentic-toolkit/releases/latest'
Page = 'https://github.com/matlab/simulink-agentic-toolkit/releases/latest'
TagFile = '.simulink-toolkit-tag'
Assets = @(
[PSCustomObject]@{ Remote = 'agenticToolkitInstaller.mltbx'; Local = 'simulink-agenticToolkitInstaller.mltbx' }
)
}
)
$updateCount = 0; $skipCount = 0; $failCount = 0
Write-Host ''
Write-Host '============================================'
Write-Host ' MATLAB Toolkits Auto Update Checker'
Write-Host ' ' (Get-Date -Format 'yyyy-MM-dd HH:mm:ss')
Write-Host (' Dir : ' + $dir)
Write-Host '============================================'
Write-Host ''
foreach ($repo in $repos) {
Write-Host ('>>> ' + $repo.Name) -ForegroundColor Cyan
try {
$rel = Invoke-RestMethod -Uri $repo.Api -UseBasicParsing
$newVer = $rel.tag_name
Write-Host (' Latest : ' + $newVer)
$tagPath = Join-Path $dir $repo.TagFile
$curVer = ''
if (Test-Path $tagPath) { $curVer = (Get-Content $tagPath -Raw).Trim() }
$anyLocal = $false
foreach ($a in $repo.Assets) {
if (Test-Path (Join-Path $dir $a.Local)) { $anyLocal = $true; break }
}
if (-not $anyLocal) {
Write-Host ' Local : no files, downloading directly...' -ForegroundColor Yellow
if ($rel.assets.Count -eq 0) {
Write-Host ' Warning : No assets in this release.' -ForegroundColor DarkYellow
Write-Host (' Manual : ' + $repo.Page)
$newVer | Out-File -FilePath $tagPath -Encoding utf8 -NoNewline
$skipCount++; Write-Host ''; continue
}
foreach ($a in $repo.Assets) {
$asset = $rel.assets | Where-Object { $_.name -eq $a.Remote }
$local = Join-Path $dir $a.Local
if (-not $asset) {
$names = ($rel.assets | ForEach-Object { $_.name }) -join ', '
Write-Host (' Miss : ' + $a.Remote + ' (available: ' + $names + ')') -ForegroundColor DarkYellow
continue
}
$sz = if ($asset.size -gt 1MB) { [math]::Round($asset.size/1MB,1).ToString()+' MB' } else { [math]::Round($asset.size/1KB,1).ToString()+' KB' }
Write-Host (' Asset : ' + $a.Remote + ' -> ' + $a.Local + ' (' + $sz + ')')
Write-Host ' Downloading...'
Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $local -UseBasicParsing
Write-Host (' Done : ' + $local) -ForegroundColor Green
}
$newVer | Out-File -FilePath $tagPath -Encoding utf8 -NoNewline
$updateCount++; Write-Host ''; continue
}
if ($curVer) { Write-Host (' Local : ' + $curVer) } else { Write-Host ' Local : (no record)' }
if ($curVer -eq $newVer) {
Write-Host ' Status : Up to date.' -ForegroundColor Green
$skipCount++; Write-Host ''; continue
}
if ($curVer) {
Write-Host (' Version : ' + $curVer + ' -> ' + $newVer) -ForegroundColor Yellow
} else {
Write-Host ' Status : First run, downloading...' -ForegroundColor Yellow
}
if ($rel.assets.Count -eq 0) {
Write-Host ' Warning : No assets in this release.' -ForegroundColor DarkYellow
Write-Host (' Manual : ' + $repo.Page)
$newVer | Out-File -FilePath $tagPath -Encoding utf8 -NoNewline
$skipCount++; Write-Host ''; continue
}
foreach ($a in $repo.Assets) {
$asset = $rel.assets | Where-Object { $_.name -eq $a.Remote }
$local = Join-Path $dir $a.Local
if (-not $asset) {
$names = ($rel.assets | ForEach-Object { $_.name }) -join ', '
Write-Host (' Miss : ' + $a.Remote + ' (available: ' + $names + ')') -ForegroundColor DarkYellow
continue
}
$sz = if ($asset.size -gt 1MB) { [math]::Round($asset.size/1MB,1).ToString()+' MB' } else { [math]::Round($asset.size/1KB,1).ToString()+' KB' }
Write-Host (' Asset : ' + $a.Remote + ' -> ' + $a.Local + ' (' + $sz + ')')
if (Test-Path $local) {
Move-Item $local ($local + '.bak') -Force
Write-Host (' Backup : ' + (Split-Path $local -Leaf) + '.bak') -ForegroundColor DarkGray
}
Write-Host ' Downloading...'
Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $local -UseBasicParsing
Write-Host (' Done : ' + $local) -ForegroundColor Green
}
$newVer | Out-File -FilePath $tagPath -Encoding utf8 -NoNewline
$updateCount++
} catch {
Write-Host (' ERROR : ' + $_.Exception.Message) -ForegroundColor Red
$failCount++
}
Write-Host ''
}
Write-Host '============================================'
Write-Host (' Updated : ' + $updateCount) -ForegroundColor $(if($updateCount -gt 0){'Green'}else{'Gray'})
Write-Host (' Skipped : ' + $skipCount)
if ($failCount -gt 0) { Write-Host (' Failed : ' + $failCount) -ForegroundColor Red }
Write-Host '============================================'
Write-Host ''
if ($failCount -gt 0) { exit 1 }
