#Requires -Version 5.1 # TheDeskMonitor-Demo-Setup.ps1 # MCP Connector setup script — Demo mode (dm_demo_public) # # This file is the committed source template for the demo PS1 artifact. # CI copies it to the dm-release artifact as TheDeskMonitor-Demo-Setup.ps1 # and deploys it to Downloads/connector/ on each production node. # # $mode is baked in at artifact creation time — this template = demo mode. # Real-client variant uses $mode = "real" and prompts for an API key. # # Usage (Windows — run from PowerShell): # Option A (avoids MOTW policy check): # powershell -ExecutionPolicy Bypass -File .\TheDeskMonitor-Demo-Setup.ps1 # Option B (unblock first, then run normally): # Unblock-File -Path .\TheDeskMonitor-Demo-Setup.ps1 # .\TheDeskMonitor-Demo-Setup.ps1 # # Usage (macOS / Linux): # pwsh ./TheDeskMonitor-Demo-Setup.ps1 # # DO NOT set Set-ExecutionPolicy Unrestricted at LocalMachine scope. # # Code signing: DEFERRED per BR-CODESIGN-DEFER-CERT-UNTIL-ARCH-PROVEN-FINAL (ledger: 36cbd2b6). # PM gate: authorized — BR-CONNECT-HELPER-COMPLETE-DEPLOY-ALL-SCENARIOS (ledger: 24efc1f6). param() Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' # ── Mode baked in by CI (demo = public demo key, rate-limited, read-only) ── $mode = "demo" $demoApiKey = "dm_demo_public" $mcpEndpoint = "https://api.thedeskmonitor.com/api/mcp/v1/" $productName = "TheDeskMonitor" $entryKey = "deskmonitor" Write-Host "" Write-Host "============================================================" -ForegroundColor Cyan Write-Host " TheDeskMonitor — MCP Connector Setup (Demo)" -ForegroundColor Cyan Write-Host "============================================================" -ForegroundColor Cyan Write-Host "" Write-Host " This script configures your AI desktop client to connect" -ForegroundColor White Write-Host " to TheDeskMonitor's MCP server using a read-only demo key." -ForegroundColor White Write-Host " No account is required for the demo." -ForegroundColor White Write-Host "" # ── Detect operating system and resolve config paths ──────────────────────── $configPaths = @{} if ($IsWindows -or (-not (Test-Path Variable:IsWindows))) { # Windows (PowerShell 5.1 does not define $IsWindows — assume Windows) $appData = $env:APPDATA if (-not $appData) { $appData = "$env:USERPROFILE\AppData\Roaming" } $configPaths["Claude Desktop"] = "$appData\Claude\claude_desktop_config.json" $configPaths["Cursor"] = "$appData\Cursor\User\globalStorage\cursor-mcp-settings.json" $configPaths["VS Code (Insiders)"]= "$appData\Code - Insiders\User\settings.json" $configPaths["VS Code"] = "$appData\Code\User\settings.json" $configPaths["Windsurf"] = "$appData\Windsurf\User\globalStorage\windsurf-mcp-settings.json" $configPaths["Gemini CLI"] = "$env:USERPROFILE\.gemini\settings.json" $configPaths["Cline"] = "$appData\Code\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json" $configPaths["Continue"] = "$appData\Code\User\globalStorage\continue.continue\config.json" $configPaths["Zed"] = "$env:LOCALAPPDATA\Zed\settings.json" } elseif ($IsMacOS) { $home = $env:HOME $configPaths["Claude Desktop"] = "$home/Library/Application Support/Claude/claude_desktop_config.json" $configPaths["Cursor"] = "$home/Library/Application Support/Cursor/User/globalStorage/cursor-mcp-settings.json" $configPaths["VS Code (Insiders)"]= "$home/Library/Application Support/Code - Insiders/User/settings.json" $configPaths["VS Code"] = "$home/Library/Application Support/Code/User/settings.json" $configPaths["Windsurf"] = "$home/Library/Application Support/Windsurf/User/globalStorage/windsurf-mcp-settings.json" $configPaths["Gemini CLI"] = "$home/.gemini/settings.json" $configPaths["Cline"] = "$home/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json" $configPaths["Continue"] = "$home/Library/Application Support/Code/User/globalStorage/continue.continue/config.json" $configPaths["Zed"] = "$home/.config/zed/settings.json" } else { # Linux $home = $env:HOME $xdgConfig = $env:XDG_CONFIG_HOME if (-not $xdgConfig) { $xdgConfig = "$home/.config" } $configPaths["Claude Desktop"] = "$xdgConfig/Claude/claude_desktop_config.json" $configPaths["Cursor"] = "$xdgConfig/Cursor/User/globalStorage/cursor-mcp-settings.json" $configPaths["VS Code (Insiders)"]= "$xdgConfig/Code - Insiders/User/settings.json" $configPaths["VS Code"] = "$xdgConfig/Code/User/settings.json" $configPaths["Windsurf"] = "$xdgConfig/Windsurf/User/globalStorage/windsurf-mcp-settings.json" $configPaths["Gemini CLI"] = "$home/.gemini/settings.json" $configPaths["Cline"] = "$xdgConfig/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json" $configPaths["Continue"] = "$xdgConfig/Code/User/globalStorage/continue.continue/config.json" $configPaths["Zed"] = "$home/.config/zed/settings.json" } # ── Detect installed clients ───────────────────────────────────────────────── $detected = [System.Collections.Generic.List[string]]::new() foreach ($client in $configPaths.Keys) { if (Test-Path $configPaths[$client]) { $detected.Add($client) } } if ($detected.Count -eq 0) { Write-Host " No supported AI desktop clients detected on this machine." -ForegroundColor Yellow Write-Host "" Write-Host " Supported clients: Claude Desktop, Cursor, VS Code, Windsurf," -ForegroundColor Gray Write-Host " Gemini CLI, Cline, Continue, Zed." -ForegroundColor Gray Write-Host "" Write-Host " Install one and re-run this script, or visit:" -ForegroundColor Gray Write-Host " https://thedeskmonitor.com/integrations to connect manually." -ForegroundColor Gray Write-Host "" exit 0 } Write-Host " Detected AI clients:" -ForegroundColor Green foreach ($client in $detected) { Write-Host " * $client" -ForegroundColor White } Write-Host "" # ── Determine MCP entry format per client ─────────────────────────────────── # Clients use different config shapes: # Stdio (Claude Desktop): mcpServers.deskmonitor.command = "npx" + args # Http (Cursor/Windsurf/Cline/etc): mcpServers.deskmonitor.url + transport/type + headers # VsCode (VS Code): mcp.servers.deskmonitor.url + type:"http" + headers # Zed (Zed editor): context_servers.deskmonitor.url + settings.headers function Get-McpEntry { param([string]$ClientName, [string]$ApiKey) switch -Wildcard ($ClientName) { "Claude Desktop" { return @{ rootKey = "mcpServers" entry = @{ command = "npx" args = @( "-y", "mcp-remote@latest", $mcpEndpoint, "--header", "Authorization: Bearer $ApiKey" ) } format = "stdio" } } "VS Code*" { return @{ rootKey = "mcp.servers" entry = @{ url = $mcpEndpoint type = "http" headers = @{ Authorization = "Bearer $ApiKey" } } format = "vscode" } } "Zed" { return @{ rootKey = "context_servers" entry = @{ url = $mcpEndpoint settings = @{ headers = @{ Authorization = "Bearer $ApiKey" } } } format = "zed" } } "Continue" { return @{ rootKey = "mcpServers" entry = @{ name = $entryKey url = $mcpEndpoint transport = "http" headers = @{ Authorization = "Bearer $ApiKey" } } format = "array" } } "Cline" { return @{ rootKey = "mcpServers" entry = @{ url = $mcpEndpoint headers = @{ Authorization = "Bearer $ApiKey" } disabled = $false autoApprove = @() } format = "object" } } default { # Cursor, Windsurf, Gemini CLI — standard http transport return @{ rootKey = "mcpServers" entry = @{ url = $mcpEndpoint transport = "http" headers = @{ Authorization = "Bearer $ApiKey" } } format = "object" } } } } # ── Merge entry into a config file (backup-first, atomic rename) ───────────── function Merge-McpConfig { param( [string]$ConfigPath, [string]$ClientName, [string]$ApiKey ) $mcpInfo = Get-McpEntry -ClientName $ClientName -ApiKey $ApiKey $entryDef = $mcpInfo.entry $rootKey = $mcpInfo.rootKey $format = $mcpInfo.format # Load or create config object $config = $null if (Test-Path $ConfigPath) { try { $raw = Get-Content $ConfigPath -Raw -Encoding UTF8 if ([string]::IsNullOrWhiteSpace($raw)) { $config = @{} } else { $config = $raw | ConvertFrom-Json -AsHashtable } } catch { Write-Host " WARN: Could not parse existing config at $ConfigPath — skipping $ClientName" -ForegroundColor Yellow Write-Host " Error: $_" -ForegroundColor DarkYellow return $false } } else { # Create parent directory if missing $parentDir = Split-Path $ConfigPath -Parent if (-not (Test-Path $parentDir)) { New-Item -ItemType Directory -Path $parentDir -Force | Out-Null } $config = @{} } # Check idempotency $alreadyPresent = $false try { if ($format -eq "vscode") { $alreadyPresent = $config.ContainsKey("mcp") -and $config["mcp"] -is [hashtable] -and $config["mcp"].ContainsKey("servers") -and $config["mcp"]["servers"] -is [hashtable] -and $config["mcp"]["servers"].ContainsKey($entryKey) } elseif ($format -eq "array") { $alreadyPresent = $config.ContainsKey($rootKey) -and ($config[$rootKey] | Where-Object { $_ -is [hashtable] -and $_["name"] -eq $entryKey }).Count -gt 0 } elseif ($format -eq "zed") { $alreadyPresent = $config.ContainsKey("context_servers") -and $config["context_servers"] -is [hashtable] -and $config["context_servers"].ContainsKey($entryKey) } else { $alreadyPresent = $config.ContainsKey($rootKey) -and $config[$rootKey] -is [hashtable] -and $config[$rootKey].ContainsKey($entryKey) } } catch { } if ($alreadyPresent) { Write-Host " Already configured — no changes made." -ForegroundColor Gray return $true } # Backup existing file before write if (Test-Path $ConfigPath) { $ts = (Get-Date).ToString("yyyyMMddHHmmssffff") $backupPath = "$ConfigPath.bak.$ts" Copy-Item $ConfigPath $backupPath -Force Write-Host " Backed up: $backupPath" -ForegroundColor DarkGray } # Inject entry if ($format -eq "vscode") { if (-not $config.ContainsKey("mcp")) { $config["mcp"] = @{} } if (-not ($config["mcp"] -is [hashtable])) { $config["mcp"] = @{} } if (-not $config["mcp"].ContainsKey("servers")) { $config["mcp"]["servers"] = @{} } if (-not ($config["mcp"]["servers"] -is [hashtable])) { $config["mcp"]["servers"] = @{} } $config["mcp"]["servers"][$entryKey] = $entryDef } elseif ($format -eq "array") { if (-not $config.ContainsKey($rootKey)) { $config[$rootKey] = @() } $arr = [System.Collections.Generic.List[object]]::new() if ($config[$rootKey] -is [array] -or $config[$rootKey] -is [System.Collections.IList]) { foreach ($item in $config[$rootKey]) { $arr.Add($item) } } # Remove stale entry by name if present $arr = $arr | Where-Object { -not ($_ -is [hashtable] -and $_["name"] -eq $entryKey) } $arr = [System.Collections.Generic.List[object]]($arr) $arr.Add($entryDef) $config[$rootKey] = $arr.ToArray() } elseif ($format -eq "zed") { if (-not $config.ContainsKey("context_servers")) { $config["context_servers"] = @{} } if (-not ($config["context_servers"] -is [hashtable])) { $config["context_servers"] = @{} } $config["context_servers"][$entryKey] = $entryDef } else { if (-not $config.ContainsKey($rootKey)) { $config[$rootKey] = @{} } if (-not ($config[$rootKey] -is [hashtable])) { $config[$rootKey] = @{} } $config[$rootKey][$entryKey] = $entryDef } # Atomic write: write to temp file, then rename $tempPath = "$ConfigPath.tmp.$(Get-Random)" try { $config | ConvertTo-Json -Depth 10 | Set-Content $tempPath -Encoding UTF8 -NoNewline Move-Item $tempPath $ConfigPath -Force } catch { # Clean up temp file on failure; original is untouched Remove-Item $tempPath -Force -ErrorAction SilentlyContinue throw } return $true } # ── Apply config to all detected clients ──────────────────────────────────── $apiKey = $demoApiKey $successCount = 0 $failCount = 0 Write-Host " Configuring detected clients with demo API key..." -ForegroundColor Cyan Write-Host "" foreach ($client in $detected) { $configPath = $configPaths[$client] Write-Host " [$client]" -ForegroundColor White Write-Host " Config: $configPath" -ForegroundColor DarkGray try { $ok = Merge-McpConfig -ConfigPath $configPath -ClientName $client -ApiKey $apiKey if ($ok) { Write-Host " Status: OK" -ForegroundColor Green $successCount++ } } catch { Write-Host " Status: FAILED — $_" -ForegroundColor Red $failCount++ } Write-Host "" } # ── Summary ────────────────────────────────────────────────────────────────── Write-Host "============================================================" -ForegroundColor Cyan if ($successCount -gt 0) { Write-Host " Setup complete! Configured $successCount client(s)." -ForegroundColor Green Write-Host "" Write-Host " What to do next:" -ForegroundColor White Write-Host " 1. Restart your AI client (close and reopen)" -ForegroundColor White Write-Host " 2. Look for 'TheDeskMonitor' in your AI client's MCP tools list" -ForegroundColor White Write-Host " 3. Ask your AI: 'What can TheDeskMonitor tell me about my team?'" -ForegroundColor White Write-Host "" Write-Host " Note: The demo key (dm_demo_public) is rate-limited and read-only." -ForegroundColor DarkGray Write-Host " To connect your real account, visit:" -ForegroundColor DarkGray Write-Host " https://thedeskmonitor.com/settings/api-keys" -ForegroundColor DarkGray } else { Write-Host " Setup encountered errors. Please check output above." -ForegroundColor Red } if ($failCount -gt 0) { Write-Host " $failCount client(s) failed to configure." -ForegroundColor Yellow } Write-Host "============================================================" -ForegroundColor Cyan Write-Host "" exit $(if ($failCount -gt 0 -and $successCount -eq 0) { 1 } else { 0 })