# Installs the MCP Canary CLI (canary) on Windows. # # irm https://mcpcanary.com/install.ps1 | iex # # Never asks a question and never needs admin rights. Adds the install directory to the user PATH. # Environment (all optional): # CANARY_VERSION release tag to install, for example v0.1.0 (default: latest) # CANARY_INSTALL_DIR target directory (default: %LOCALAPPDATA%\Programs\McpCanary) # CANARY_REPO GitHub owner/repo with the releases (default: xakpc-dev-labs/canary) # CANARY_DOWNLOAD_URL base URL that holds the assets and checksums.txt (mirrors, tests) & { $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' # the progress bar makes Invoke-WebRequest very slow $repo = if ($env:CANARY_REPO) { $env:CANARY_REPO } else { 'xakpc-dev-labs/canary' } $version = if ($env:CANARY_VERSION) { $env:CANARY_VERSION } else { 'latest' } $dir = if ($env:CANARY_INSTALL_DIR) { $env:CANARY_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA 'Programs\McpCanary' } $arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture # Windows on Arm runs the x64 build through emulation; there is no native arm64 build yet. if ($arch -ne 'X64' -and $arch -ne 'Arm64') { throw "canary install: unsupported CPU '$arch'." } $asset = 'canary_windows_x64.zip' $base = if ($env:CANARY_DOWNLOAD_URL) { $env:CANARY_DOWNLOAD_URL.TrimEnd('/') } elseif ($version -eq 'latest') { "https://github.com/$repo/releases/latest/download" } else { "https://github.com/$repo/releases/download/$version" } $tmp = Join-Path ([System.IO.Path]::GetTempPath()) ("canary-" + [guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Path $tmp | Out-Null try { Invoke-WebRequest -UseBasicParsing -Uri "$base/$asset" -OutFile (Join-Path $tmp $asset) Invoke-WebRequest -UseBasicParsing -Uri "$base/checksums.txt" -OutFile (Join-Path $tmp 'checksums.txt') $line = Get-Content (Join-Path $tmp 'checksums.txt') | Where-Object { ($_ -split '\s+')[1] -in @($asset, "*$asset") } | Select-Object -First 1 if (-not $line) { throw "canary install: checksums.txt has no entry for $asset." } $expected = ($line -split '\s+')[0].ToLowerInvariant() $actual = (Get-FileHash -Algorithm SHA256 (Join-Path $tmp $asset)).Hash.ToLowerInvariant() if ($expected -ne $actual) { throw "canary install: checksum mismatch for $asset (expected $expected, got $actual)." } Expand-Archive -Path (Join-Path $tmp $asset) -DestinationPath $tmp -Force New-Item -ItemType Directory -Path $dir -Force | Out-Null Copy-Item (Join-Path $tmp 'canary.exe') (Join-Path $dir 'canary.exe') -Force } finally { Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue } $exe = Join-Path $dir 'canary.exe' $installed = & $exe --version Write-Output "canary $installed installed to $exe" # Read and write the raw registry value: [Environment]::SetEnvironmentVariable would expand entries # like %USERPROFILE%\bin and store the user PATH as a plain string. $key = Get-Item 'HKCU:\Environment' $userPath = $key.GetValue('Path', '', 'DoNotExpandEnvironmentNames') if (-not (($userPath -split ';') -contains $dir)) { $newPath = (@($userPath.TrimEnd(';'), $dir) | Where-Object { $_ }) -join ';' Set-ItemProperty -Path 'HKCU:\Environment' -Name 'Path' -Value $newPath -Type ExpandString # Tell Explorer and new terminals that the environment changed. Add-Type -Namespace CanaryInstall -Name Native -MemberDefinition '[DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint msg, UIntPtr wParam, string lParam, uint flags, uint timeout, out UIntPtr result);' $result = [UIntPtr]::Zero [void][CanaryInstall.Native]::SendMessageTimeout([IntPtr]0xffff, 0x1A, [UIntPtr]::Zero, 'Environment', 2, 5000, [ref]$result) Write-Output "Added $dir to the user PATH." } # $env:Path belongs to the process, so this PowerShell session finds canary at once (irm | iex runs in it). if (-not (($env:Path -split ';') -contains $dir)) { $env:Path = "$dir;$env:Path" } Write-Output 'Next: canary inspect ' }