$ErrorActionPreference = 'Stop' $port = if ($env:PORT) { [int]$env:PORT } else { 8787 } $connections = Get-NetTCPConnection -LocalAddress 127.0.0.1 -LocalPort $port -ErrorAction SilentlyContinue if (!$connections) { Write-Host "AI MCP service is not running on 127.0.0.1:$port" exit 0 } $processIds = $connections | Select-Object -ExpandProperty OwningProcess -Unique foreach ($processId in $processIds) { if ($processId -eq 0) { continue } $process = Get-Process -Id $processId -ErrorAction SilentlyContinue if ($process -and $process.ProcessName -eq 'node') { Stop-Process -Id $processId -Force Write-Host "Stopped AI MCP service process $processId" } else { Write-Host "Port $port is owned by process $processId, but it is not node. Skipped." } }