$connections = Get-NetTCPConnection -LocalPort 3100 -State Listen -ErrorAction SilentlyContinue
if (-not $connections) {
  Write-Output "AI MCP service is not running on port 3100."
  exit 0
}

$connections | ForEach-Object {
  $pidValue = $_.OwningProcess
  if ($pidValue) {
    Stop-Process -Id $pidValue -Force
    Write-Output "Stopped AI MCP process $pidValue."
  }
}
