|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + One-shot installer for the TestOps MCP server (per-user / stdio mode). |
| 4 | +
|
| 5 | +.DESCRIPTION |
| 6 | + Downloads the right binary for your OS/arch from GitHub Releases, asks for your |
| 7 | + Allure TestOps URL + API token, and registers the server in BOTH: |
| 8 | + * Claude Desktop (claude_desktop_config.json) |
| 9 | + * Claude Code (via `claude mcp add -s user`, if the CLI is installed) |
| 10 | +
|
| 11 | + Re-running the script is safe — it overwrites the existing "testops" entry. |
| 12 | +
|
| 13 | +.EXAMPLE |
| 14 | + # Interactive (asks for URL + token): |
| 15 | + powershell -ExecutionPolicy Bypass -File .\install.ps1 |
| 16 | +
|
| 17 | +.EXAMPLE |
| 18 | + # Non-interactive: |
| 19 | + powershell -ExecutionPolicy Bypass -File .\install.ps1 ` |
| 20 | + -AllureBaseUrl https://your-testops.com -AllureToken xxxxxxxx |
| 21 | +#> |
| 22 | +[CmdletBinding()] |
| 23 | +param( |
| 24 | + [string]$AllureBaseUrl = $env:ALLURE_BASE_URL, |
| 25 | + [string]$AllureToken = $env:ALLURE_TOKEN, |
| 26 | + [string]$Version = "latest", # e.g. v2.0.3 ; "latest" = newest release |
| 27 | + [string]$ServerName = "testops", |
| 28 | + [switch]$NoClaudeCode, |
| 29 | + [switch]$NoClaudeDesktop |
| 30 | +) |
| 31 | + |
| 32 | +$ErrorActionPreference = "Stop" |
| 33 | +$Repo = "MimoJanra/TestOpsMCP" |
| 34 | + |
| 35 | +# TestOps MCP supports older Windows that default to TLS 1.0/1.1. |
| 36 | +try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 } catch {} |
| 37 | + |
| 38 | +function Write-Step($msg) { Write-Host "`n==> $msg" -ForegroundColor Cyan } |
| 39 | +function Write-Ok($msg) { Write-Host " OK $msg" -ForegroundColor Green } |
| 40 | +function Write-Warn2($msg) { Write-Host " ! $msg" -ForegroundColor Yellow } |
| 41 | + |
| 42 | +function Update-DesktopConfig { |
| 43 | + param([string]$Path, [string]$Name, [string]$Command, [hashtable]$EnvVars) |
| 44 | + |
| 45 | + $dir = Split-Path -Parent $Path |
| 46 | + if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Force -Path $dir | Out-Null } |
| 47 | + |
| 48 | + if (Test-Path $Path) { |
| 49 | + Copy-Item $Path "$Path.bak" -Force |
| 50 | + $raw = Get-Content -Raw -Path $Path |
| 51 | + if ([string]::IsNullOrWhiteSpace($raw)) { |
| 52 | + $config = [pscustomobject]@{} |
| 53 | + } else { |
| 54 | + $config = $raw | ConvertFrom-Json |
| 55 | + } |
| 56 | + } else { |
| 57 | + $config = [pscustomobject]@{} |
| 58 | + } |
| 59 | + |
| 60 | + if (-not ($config.PSObject.Properties.Name -contains 'mcpServers')) { |
| 61 | + $config | Add-Member -NotePropertyName 'mcpServers' -NotePropertyValue ([pscustomobject]@{}) -Force |
| 62 | + } |
| 63 | + |
| 64 | + $envObj = [pscustomobject]@{} |
| 65 | + foreach ($k in $EnvVars.Keys) { |
| 66 | + $envObj | Add-Member -NotePropertyName $k -NotePropertyValue $EnvVars[$k] -Force |
| 67 | + } |
| 68 | + |
| 69 | + $serverEntry = [pscustomobject]@{ command = $Command; env = $envObj } |
| 70 | + $config.mcpServers | Add-Member -NotePropertyName $Name -NotePropertyValue $serverEntry -Force |
| 71 | + |
| 72 | + $json = $config | ConvertTo-Json -Depth 100 |
| 73 | + $utf8NoBom = New-Object System.Text.UTF8Encoding($false) |
| 74 | + [System.IO.File]::WriteAllText($Path, $json, $utf8NoBom) |
| 75 | +} |
| 76 | + |
| 77 | +Write-Host "TestOps MCP installer" -ForegroundColor White |
| 78 | + |
| 79 | +# --- 1. Detect platform --------------------------------------------------- |
| 80 | +Write-Step "Detecting platform" |
| 81 | +$arch = if ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64' -or $env:PROCESSOR_ARCHITEW6432 -eq 'ARM64') { 'arm64' } else { 'amd64' } |
| 82 | +$asset = "testops-mcp-windows-$arch.exe" |
| 83 | +Write-Ok "windows / $arch -> $asset" |
| 84 | + |
| 85 | +# --- 2. Download binary ---------------------------------------------------- |
| 86 | +Write-Step "Downloading binary ($Version)" |
| 87 | +if ($Version -eq "latest") { |
| 88 | + $url = "https://github.com/$Repo/releases/latest/download/$asset" |
| 89 | +} else { |
| 90 | + $url = "https://github.com/$Repo/releases/download/$Version/$asset" |
| 91 | +} |
| 92 | + |
| 93 | +$installDir = Join-Path $env:LOCALAPPDATA "TestOpsMCP" |
| 94 | +if (-not (Test-Path $installDir)) { New-Item -ItemType Directory -Force -Path $installDir | Out-Null } |
| 95 | +$binPath = Join-Path $installDir "testops-mcp.exe" |
| 96 | + |
| 97 | +try { |
| 98 | + Invoke-WebRequest -Uri $url -OutFile $binPath -UseBasicParsing |
| 99 | +} catch { |
| 100 | + throw "Download failed from $url`n$($_.Exception.Message)`nCheck the version tag or download manually from https://github.com/$Repo/releases" |
| 101 | +} |
| 102 | +if (-not (Test-Path $binPath) -or (Get-Item $binPath).Length -eq 0) { |
| 103 | + throw "Downloaded file is empty: $binPath" |
| 104 | +} |
| 105 | +Write-Ok "saved to $binPath" |
| 106 | + |
| 107 | +# --- 3. Collect Allure credentials ---------------------------------------- |
| 108 | +Write-Step "Allure TestOps credentials" |
| 109 | +if (-not $AllureBaseUrl) { |
| 110 | + $AllureBaseUrl = Read-Host "Allure TestOps URL (e.g. https://your-testops.com)" |
| 111 | +} |
| 112 | +$AllureBaseUrl = $AllureBaseUrl.Trim().TrimEnd('/') |
| 113 | +if ($AllureBaseUrl -notmatch '^https?://') { $AllureBaseUrl = "https://$AllureBaseUrl" } |
| 114 | + |
| 115 | +if (-not $AllureToken) { |
| 116 | + $sec = Read-Host "Allure API token (input hidden)" -AsSecureString |
| 117 | + $AllureToken = [Runtime.InteropServices.Marshal]::PtrToStringAuto( |
| 118 | + [Runtime.InteropServices.Marshal]::SecureStringToBSTR($sec)) |
| 119 | +} |
| 120 | +$AllureToken = $AllureToken.Trim() |
| 121 | +if (-not $AllureBaseUrl -or -not $AllureToken) { throw "Both URL and token are required." } |
| 122 | +Write-Ok "URL: $AllureBaseUrl" |
| 123 | + |
| 124 | +$envVars = @{ ALLURE_BASE_URL = $AllureBaseUrl; ALLURE_TOKEN = $AllureToken } |
| 125 | + |
| 126 | +# --- 4. Claude Desktop ----------------------------------------------------- |
| 127 | +if (-not $NoClaudeDesktop) { |
| 128 | + Write-Step "Configuring Claude Desktop" |
| 129 | + $desktopCfg = Join-Path $env:APPDATA "Claude\claude_desktop_config.json" |
| 130 | + Update-DesktopConfig -Path $desktopCfg -Name $ServerName -Command $binPath -EnvVars $envVars |
| 131 | + Write-Ok "updated $desktopCfg" |
| 132 | +} |
| 133 | + |
| 134 | +# --- 5. Claude Code (CLI) -------------------------------------------------- |
| 135 | +if (-not $NoClaudeCode) { |
| 136 | + Write-Step "Configuring Claude Code" |
| 137 | + $claude = Get-Command claude -ErrorAction SilentlyContinue |
| 138 | + if ($claude) { |
| 139 | + & claude mcp remove -s user $ServerName *> $null |
| 140 | + & claude mcp add -s user $ServerName $binPath ` |
| 141 | + -e "ALLURE_BASE_URL=$AllureBaseUrl" ` |
| 142 | + -e "ALLURE_TOKEN=$AllureToken" |
| 143 | + if ($LASTEXITCODE -eq 0) { Write-Ok "registered '$ServerName' in Claude Code (user scope)" } |
| 144 | + else { Write-Warn2 "claude CLI returned exit code $LASTEXITCODE" } |
| 145 | + } else { |
| 146 | + Write-Warn2 "claude CLI not found on PATH — skipped. Run this later if you use Claude Code:" |
| 147 | + Write-Host " claude mcp add -s user $ServerName `"$binPath`" -e ALLURE_BASE_URL=$AllureBaseUrl -e ALLURE_TOKEN=<token>" |
| 148 | + } |
| 149 | +} |
| 150 | + |
| 151 | +# --- Done ------------------------------------------------------------------ |
| 152 | +Write-Host "`nDone." -ForegroundColor Green |
| 153 | +Write-Host " * Claude Desktop: fully restart it (quit from the tray, not just close the window)." |
| 154 | +Write-Host " * Then ask Claude: `"List all projects in Allure`"" |
0 commit comments