Files
HL_MES_manager_ai/ai-mcp-service/start.ps1

26 lines
820 B
PowerShell

$ErrorActionPreference = 'Stop'
$serviceDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$port = if ($env:PORT) { [int]$env:PORT } else { 8787 }
$url = "http://127.0.0.1:$port/health"
try {
$health = Invoke-RestMethod -Uri $url -Method Get -TimeoutSec 2
Write-Host "AI MCP service is already running: $url"
$health | ConvertTo-Json -Depth 5
exit 0
} catch {
Write-Host "Starting AI MCP service on $url ..."
}
Start-Process -FilePath "node" -ArgumentList "server.js" -WorkingDirectory $serviceDir -WindowStyle Hidden
Start-Sleep -Seconds 2
try {
$health = Invoke-RestMethod -Uri $url -Method Get -TimeoutSec 5
Write-Host "AI MCP service started: $url"
$health | ConvertTo-Json -Depth 5
} catch {
Write-Error "AI MCP service failed to start. Run 'npm start' in this directory to see details."
}