153 lines
4.0 KiB
PowerShell
153 lines
4.0 KiB
PowerShell
[CmdletBinding()]
|
|
param()
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$projectName = "webaccess-mcp"
|
|
$environmentPath = Join-Path $PSScriptRoot ".env"
|
|
$healthUrl = "http://127.0.0.1:28081/health"
|
|
|
|
function Invoke-Podman {
|
|
param(
|
|
[Parameter(Mandatory)]
|
|
[string[]] $Arguments,
|
|
|
|
[switch] $DiscardOutput
|
|
)
|
|
|
|
$previousErrorActionPreference = $ErrorActionPreference
|
|
|
|
try {
|
|
$ErrorActionPreference = "Continue"
|
|
|
|
if ($DiscardOutput) {
|
|
& podman @Arguments *> $null
|
|
}
|
|
else {
|
|
& podman @Arguments
|
|
}
|
|
|
|
$script:PodmanExitCode = $LASTEXITCODE
|
|
}
|
|
finally {
|
|
$ErrorActionPreference = $previousErrorActionPreference
|
|
}
|
|
}
|
|
|
|
function New-HexSecret {
|
|
$bytes = New-Object byte[] 32
|
|
$generator = [System.Security.Cryptography.RandomNumberGenerator]::Create()
|
|
|
|
try {
|
|
$generator.GetBytes($bytes)
|
|
}
|
|
finally {
|
|
$generator.Dispose()
|
|
}
|
|
|
|
return -join ($bytes | ForEach-Object { $_.ToString("x2") })
|
|
}
|
|
|
|
if (-not (Get-Command "podman" -ErrorAction SilentlyContinue)) {
|
|
throw "Podman is not installed or is not available in PATH."
|
|
}
|
|
|
|
Invoke-Podman -Arguments @("info") -DiscardOutput
|
|
if ($script:PodmanExitCode -ne 0) {
|
|
throw "Podman is not running. Start the Podman machine in Podman Desktop and try again."
|
|
}
|
|
|
|
Invoke-Podman -Arguments @("compose", "version") -DiscardOutput
|
|
if ($script:PodmanExitCode -ne 0) {
|
|
throw "Podman Compose is not installed. Install it from Podman Desktop Settings > Resources."
|
|
}
|
|
|
|
if (-not (Test-Path -LiteralPath $environmentPath -PathType Leaf)) {
|
|
@"
|
|
WEBACCESS_POSTGRES_PASSWORD=$(New-HexSecret)
|
|
SEARXNG_SECRET=$(New-HexSecret)
|
|
"@ | Set-Content -LiteralPath $environmentPath -Encoding Ascii
|
|
|
|
Write-Host "Created deploy\.env with new installation secrets."
|
|
}
|
|
|
|
Push-Location $PSScriptRoot
|
|
|
|
try {
|
|
Write-Host "Building and starting PostgreSQL, SearXNG, and WebAccess.MCP..."
|
|
Invoke-Podman -Arguments @(
|
|
"compose",
|
|
"--project-name",
|
|
$projectName,
|
|
"up",
|
|
"--detach",
|
|
"--build")
|
|
|
|
if ($script:PodmanExitCode -ne 0) {
|
|
throw "Podman Compose failed with exit code $script:PodmanExitCode."
|
|
}
|
|
|
|
Write-Host ""
|
|
Invoke-Podman -Arguments @("compose", "--project-name", $projectName, "ps")
|
|
|
|
if ($script:PodmanExitCode -ne 0) {
|
|
throw "The stack started, but its status could not be displayed."
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "Waiting for WebAccess.MCP to become ready..."
|
|
$isReady = $false
|
|
|
|
for ($attempt = 1; $attempt -le 30; $attempt++) {
|
|
try {
|
|
$response = Invoke-RestMethod `
|
|
-Uri $healthUrl `
|
|
-Method Get `
|
|
-TimeoutSec 3
|
|
|
|
if ($response.status -eq "healthy") {
|
|
$isReady = $true
|
|
break
|
|
}
|
|
}
|
|
catch {
|
|
if ($attempt -lt 30) {
|
|
Start-Sleep -Seconds 2
|
|
}
|
|
}
|
|
}
|
|
|
|
if (-not $isReady) {
|
|
Write-Host ""
|
|
Write-Host "WebAccess.MCP did not become reachable. Current status:"
|
|
Invoke-Podman -Arguments @("compose", "--project-name", $projectName, "ps")
|
|
Write-Host ""
|
|
Write-Host "WebAccess.MCP logs:"
|
|
Invoke-Podman -Arguments @(
|
|
"compose",
|
|
"--project-name",
|
|
$projectName,
|
|
"logs",
|
|
"--tail",
|
|
"200",
|
|
"webaccess")
|
|
|
|
throw "WebAccess.MCP did not pass its readiness check at $healthUrl."
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "WebAccess.MCP health check passed at $healthUrl"
|
|
Write-Host "WebAccess.MCP is available at http://127.0.0.1:28081/mcp"
|
|
Write-Host "SearXNG diagnostics are available at http://127.0.0.1:28080/"
|
|
Write-Host ""
|
|
Write-Host "Add this entry inside the mcpServers object in LM Studio's mcp.json:"
|
|
Write-Host ""
|
|
Write-Host ' "webaccess": {'
|
|
Write-Host ' "url": "http://127.0.0.1:28081/mcp"'
|
|
Write-Host ' }'
|
|
Write-Host ""
|
|
Write-Host "Save mcp.json, then click Refresh in LM Studio."
|
|
}
|
|
finally {
|
|
Pop-Location
|
|
}
|