mcpo_install.ps1•9.15 kB
#Requires -Version 5.1
<#
.SYNOPSIS
Installiert und startet den MCPO (MCP over HTTP) Server fuer Cursor-Tools.
.DESCRIPTION
Dieses Script:
1. Prueft Voraussetzungen (Podman, Node.js)
2. Erstellt .env Datei falls nicht vorhanden
3. Installiert Node.js Dependencies
4. Startet Podman-Compose als Daemon
5. Prueft, ob der Service laeuft
.PARAMETER WorkspacePath
Pfad zum Workspace, der durchsucht werden soll (default: D:\workspace\pvs)
.PARAMETER Port
Port fuer den MCPO Server (default: 8000)
.EXAMPLE
.\mcpo_install.ps1
.EXAMPLE
.\mcpo_install.ps1 -WorkspacePath "D:\workspace\mein-projekt" -Port 8001
#>
# UTF-8 Encoding sicherstellen
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
param(
[string]$WorkspacePath = "D:\workspace\pvs",
[int]$Port = 8000
)
$ErrorActionPreference = "Stop"
Write-Host "MCPO Installation gestartet..." -ForegroundColor Cyan
# 1. Voraussetzungen pruefen
Write-Host "`nPruefe Voraussetzungen..." -ForegroundColor Yellow
# Podman pruefen
$podmanVersion = $null
try {
$podmanVersion = & podman --version 2>&1
if ($LASTEXITCODE -eq 0 -and $podmanVersion) {
Write-Host "OK Podman gefunden: $podmanVersion" -ForegroundColor Green
} else {
throw "Podman nicht gefunden"
}
} catch {
Write-Host "FEHLER Podman nicht gefunden!" -ForegroundColor Red
Write-Host " Bitte installiere Podman Desktop: https://podman-desktop.io/" -ForegroundColor Yellow
exit 1
}
# Podman-Compose pruefen
$composeVersion = $null
try {
$composeVersion = & podman-compose --version 2>&1
if ($LASTEXITCODE -eq 0 -and $composeVersion) {
Write-Host "OK Podman-Compose gefunden: $composeVersion" -ForegroundColor Green
} else {
throw "Podman-Compose nicht gefunden"
}
} catch {
Write-Host "FEHLER Podman-Compose nicht gefunden!" -ForegroundColor Red
Write-Host " Installiere mit: pip install podman-compose" -ForegroundColor Yellow
exit 1
}
# Node.js pruefen (fuer lokale Entwicklung)
try {
$nodeVersion = & node --version 2>&1
if ($LASTEXITCODE -eq 0 -and $nodeVersion) {
Write-Host "OK Node.js gefunden: $nodeVersion" -ForegroundColor Green
} else {
Write-Host "WARNUNG Node.js nicht gefunden (optional fuer lokale Entwicklung)" -ForegroundColor Yellow
}
} catch {
Write-Host "WARNUNG Node.js nicht gefunden (optional fuer lokale Entwicklung)" -ForegroundColor Yellow
}
# 2. .env Datei erstellen falls nicht vorhanden
Write-Host "`nPruefe .env Datei..." -ForegroundColor Yellow
if (-not (Test-Path ".env")) {
Write-Host " .env nicht gefunden, erstelle aus .env.example..." -ForegroundColor Yellow
if (Test-Path ".env.example") {
Copy-Item ".env.example" ".env" -Force
Write-Host "OK .env erstellt" -ForegroundColor Green
} else {
Write-Host "FEHLER .env.example nicht gefunden!" -ForegroundColor Red
exit 1
}
# API-Key generieren
$apiKey = -join ((48..57) + (65..90) + (97..122) | Get-Random -Count 32 | ForEach-Object {[char]$_})
# .env aktualisieren (UTF-8 Encoding)
$envContent = Get-Content ".env" -Raw -Encoding UTF8
$envContent = $envContent -replace "MCPO_API_KEY=.*", "MCPO_API_KEY=$apiKey"
$envContent = $envContent -replace "WORKSPACE_PATH=.*", "WORKSPACE_PATH=$WorkspacePath"
$envContent = $envContent -replace "MCPO_PORT=.*", "MCPO_PORT=$Port"
Set-Content ".env" -Value $envContent -NoNewline -Encoding UTF8
Write-Host "OK API-Key generiert und .env aktualisiert" -ForegroundColor Green
Write-Host " Workspace: $WorkspacePath" -ForegroundColor Gray
Write-Host " Port: $Port" -ForegroundColor Gray
} else {
Write-Host "OK .env bereits vorhanden" -ForegroundColor Green
}
# Workspace-Pfad pruefen
if (-not (Test-Path $WorkspacePath)) {
Write-Host "WARNUNG Workspace-Pfad existiert nicht: $WorkspacePath" -ForegroundColor Yellow
Write-Host " Bitte in .env anpassen oder Verzeichnis erstellen" -ForegroundColor Yellow
}
# 3. Node.js Dependencies installieren (optional, fuer lokale Entwicklung)
if (Get-Command node -ErrorAction SilentlyContinue) {
Write-Host "`nInstalliere Node.js Dependencies..." -ForegroundColor Yellow
if (Test-Path "package.json") {
if (-not (Test-Path "node_modules")) {
& npm install
if ($LASTEXITCODE -eq 0) {
Write-Host "OK Dependencies installiert" -ForegroundColor Green
} else {
Write-Host "WARNUNG npm install fehlgeschlagen" -ForegroundColor Yellow
}
} else {
Write-Host "OK node_modules bereits vorhanden" -ForegroundColor Green
}
}
}
# 4. mcpo-entrypoint.sh ausfuehrbar machen (falls auf WSL/Linux)
if (Get-Command wsl -ErrorAction SilentlyContinue) {
Write-Host "`nSetze Script-Rechte (WSL)..." -ForegroundColor Yellow
& wsl chmod +x mcpo-entrypoint.sh 2>&1 | Out-Null
}
# 5. Pruefe ob Container bereits laufen
Write-Host "`nPruefe laufende Container..." -ForegroundColor Yellow
$runningContainers = & podman ps --filter "name=mcpo" --format "{{.Names}}" 2>&1
if ($LASTEXITCODE -eq 0 -and $runningContainers) {
Write-Host "WARNUNG Container laufen bereits:" -ForegroundColor Yellow
$runningContainers | ForEach-Object { Write-Host " - $_" -ForegroundColor Gray }
$response = Read-Host " Container stoppen und neu starten? (j/N)"
if ($response -eq "j" -or $response -eq "J" -or $response -eq "y" -or $response -eq "Y") {
Write-Host " Stoppe Container..." -ForegroundColor Yellow
& podman-compose down 2>&1 | Out-Null
Start-Sleep -Seconds 2
} else {
Write-Host " Ueberspringe Start" -ForegroundColor Yellow
exit 0
}
}
# 6. Podman-Compose starten
Write-Host "`nStarte Podman-Compose..." -ForegroundColor Yellow
try {
# Lade .env Variablen
if (Test-Path ".env") {
Get-Content ".env" -Encoding UTF8 | ForEach-Object {
if ($_ -match '^([^#][^=]+)=(.*)$') {
$key = $matches[1].Trim()
$value = $matches[2].Trim()
[Environment]::SetEnvironmentVariable($key, $value, "Process")
}
}
}
# Starte als Daemon
& podman-compose up -d
if ($LASTEXITCODE -eq 0) {
Write-Host "OK Podman-Compose gestartet" -ForegroundColor Green
} else {
throw "Podman-Compose start fehlgeschlagen (Exit Code: $LASTEXITCODE)"
}
} catch {
Write-Host "FEHLER Fehler beim Starten von Podman-Compose!" -ForegroundColor Red
Write-Host " Fehler: $_" -ForegroundColor Red
exit 1
}
# 7. Warte kurz und pruefe Status
Write-Host "`nWarte auf Container-Start..." -ForegroundColor Yellow
Start-Sleep -Seconds 5
$containers = & podman ps --filter "name=mcpo" --format "{{.Names}} - {{.Status}}" 2>&1
if ($LASTEXITCODE -eq 0 -and $containers) {
Write-Host "`nOK Container laufen:" -ForegroundColor Green
$containers | ForEach-Object { Write-Host " $_" -ForegroundColor Gray }
} else {
Write-Host "`nWARNUNG Keine Container gefunden - pruefe Logs:" -ForegroundColor Yellow
Write-Host " podman-compose logs" -ForegroundColor Gray
}
# 8. Health Check
Write-Host "`nPruefe Health Check..." -ForegroundColor Yellow
$maxRetries = 6
$retry = 0
$healthy = $false
while ($retry -lt $maxRetries -and -not $healthy) {
try {
$response = Invoke-WebRequest -Uri "http://localhost:$Port/health" -TimeoutSec 5 -ErrorAction Stop
if ($response.StatusCode -eq 200) {
$healthy = $true
Write-Host "OK MCPO Server ist erreichbar!" -ForegroundColor Green
}
} catch {
$retry++
if ($retry -lt $maxRetries) {
Write-Host " Versuch $retry/$maxRetries..." -ForegroundColor Gray
Start-Sleep -Seconds 5
}
}
}
if (-not $healthy) {
Write-Host "WARNUNG Health Check fehlgeschlagen - Server startet moeglicherweise noch" -ForegroundColor Yellow
Write-Host " Pruefe Logs: podman-compose logs -f" -ForegroundColor Gray
}
# 9. Zusammenfassung
Write-Host "`n" + ("="*60) -ForegroundColor Cyan
Write-Host "Installation abgeschlossen!" -ForegroundColor Cyan
Write-Host ("="*60) -ForegroundColor Cyan
Write-Host ""
Write-Host "API Endpoints:" -ForegroundColor Yellow
Write-Host " Base URL: http://localhost:$Port" -ForegroundColor White
Write-Host " OpenAPI: http://localhost:$Port/docs" -ForegroundColor White
Write-Host " Health: http://localhost:$Port/health" -ForegroundColor White
Write-Host ""
Write-Host "Nuetzliche Befehle:" -ForegroundColor Yellow
Write-Host " Logs ansehen: podman-compose logs -f" -ForegroundColor White
Write-Host " Status pruefen: podman-compose ps" -ForegroundColor White
Write-Host " Stoppen: podman-compose down" -ForegroundColor White
Write-Host " Neustarten: podman-compose restart" -ForegroundColor White
Write-Host ""
Write-Host "API-Key findest du in .env (MCPO_API_KEY)" -ForegroundColor Yellow
Write-Host ""