FIxed multiple issues in run-server.ps1.Changed encoding to UTF8-BOM. Made Installing dependencies with uv safer on fail. Fixed syntax issue on line 1728.

This commit is contained in:
DarkNoon5891
2025-10-07 20:05:22 +01:00
parent 52245b91ea
commit caddffd864

View File

@@ -1,4 +1,4 @@
<# <#
.SYNOPSIS .SYNOPSIS
Installation, configuration, and launch script for Zen MCP server on Windows. Installation, configuration, and launch script for Zen MCP server on Windows.
@@ -152,7 +152,8 @@ function Test-Command {
try { try {
$null = Get-Command $Command -ErrorAction Stop $null = Get-Command $Command -ErrorAction Stop
return $true return $true
} catch { }
catch {
return $false return $false
} }
} }
@@ -169,7 +170,8 @@ function Remove-LockedDirectory {
# Try standard removal first # Try standard removal first
Remove-Item -Recurse -Force $Path -ErrorAction Stop Remove-Item -Recurse -Force $Path -ErrorAction Stop
return $true return $true
} catch { }
catch {
Write-Warning "Standard removal failed, trying alternative methods..." Write-Warning "Standard removal failed, trying alternative methods..."
# Method 1: Use takeown and icacls to force ownership # Method 1: Use takeown and icacls to force ownership
@@ -179,7 +181,8 @@ function Remove-LockedDirectory {
icacls "$Path" /grant administrators:F /T 2>$null | Out-Null icacls "$Path" /grant administrators:F /T 2>$null | Out-Null
Remove-Item -Recurse -Force $Path -ErrorAction Stop Remove-Item -Recurse -Force $Path -ErrorAction Stop
return $true return $true
} catch { }
catch {
Write-Warning "Ownership method failed" Write-Warning "Ownership method failed"
} }
@@ -196,7 +199,8 @@ function Remove-LockedDirectory {
Write-Warning "Environment renamed to $tempName and will be deleted on next reboot" Write-Warning "Environment renamed to $tempName and will be deleted on next reboot"
return $true return $true
} catch { }
catch {
Write-Warning "Rename method failed" Write-Warning "Rename method failed"
} }
@@ -238,7 +242,8 @@ function Manage-ConfigBackups {
try { try {
Remove-Item $backup.FullName -Force -ErrorAction Stop Remove-Item $backup.FullName -Force -ErrorAction Stop
Write-Info "Removed old backup: $($backup.Name)" Write-Info "Removed old backup: $($backup.Name)"
} catch { }
catch {
Write-Warning "Could not remove old backup: $($backup.Name)" Write-Warning "Could not remove old backup: $($backup.Name)"
} }
} }
@@ -248,7 +253,8 @@ function Manage-ConfigBackups {
Write-Success "Backup created: $(Split-Path $backupPath -Leaf)" Write-Success "Backup created: $(Split-Path $backupPath -Leaf)"
return $backupPath return $backupPath
} catch { }
catch {
Write-Warning "Failed to create backup: $_" Write-Warning "Failed to create backup: $_"
return $null return $null
} }
@@ -265,7 +271,8 @@ function Get-Version {
} }
} }
return "unknown" return "unknown"
} catch { }
catch {
return "unknown" return "unknown"
} }
} }
@@ -283,7 +290,8 @@ function Clear-PythonCache {
ForEach-Object { Remove-Item -Path $_ -Recurse -Force } ForEach-Object { Remove-Item -Path $_ -Recurse -Force }
Write-Success "Python cache cleared" Write-Success "Python cache cleared"
} catch { }
catch {
Write-Warning "Could not clear all cache files: $_" Write-Warning "Could not clear all cache files: $_"
} }
} }
@@ -295,7 +303,8 @@ function Get-AbsolutePath {
if (Test-Path $Path) { if (Test-Path $Path) {
# Use Resolve-Path for full resolution # Use Resolve-Path for full resolution
return Resolve-Path $Path return Resolve-Path $Path
} else { }
else {
# Use unresolved method # Use unresolved method
return $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) return $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path)
} }
@@ -312,7 +321,8 @@ function Test-PythonVersion {
return ($major -gt 3) -or ($major -eq 3 -and $minor -ge 10) return ($major -gt 3) -or ($major -eq 3 -and $minor -ge 10)
} }
return $false return $false
} catch { }
catch {
return $false return $false
} }
} }
@@ -339,7 +349,8 @@ function Find-Python {
$null = Invoke-Expression "$cmd --version" 2>$null $null = Invoke-Expression "$cmd --version" 2>$null
Write-Success "Found Python via py launcher: $cmd" Write-Success "Found Python via py launcher: $cmd"
return $cmd return $cmd
} catch { }
catch {
continue continue
} }
} }
@@ -360,7 +371,8 @@ function Cleanup-Docker {
try { try {
$null = docker info 2>$null $null = docker info 2>$null
} catch { }
catch {
return return
} }
@@ -388,7 +400,8 @@ function Cleanup-Docker {
docker stop $container 2>$null | Out-Null docker stop $container 2>$null | Out-Null
docker rm $container 2>$null | Out-Null docker rm $container 2>$null | Out-Null
} }
} catch { }
catch {
# Ignore errors # Ignore errors
} }
} }
@@ -406,7 +419,8 @@ function Cleanup-Docker {
Write-Info " Removing image: $image" Write-Info " Removing image: $image"
docker rmi $image 2>$null | Out-Null docker rmi $image 2>$null | Out-Null
} }
} catch { }
catch {
# Ignore errors # Ignore errors
} }
} }
@@ -424,7 +438,8 @@ function Cleanup-Docker {
Write-Info " Removing volume: $volume" Write-Info " Removing volume: $volume"
docker volume rm $volume 2>$null | Out-Null docker volume rm $volume 2>$null | Out-Null
} }
} catch { }
catch {
# Ignore errors # Ignore errors
} }
} }
@@ -493,7 +508,8 @@ function Initialize-Environment {
if ($Force) { if ($Force) {
Write-Warning "Removing existing environment..." Write-Warning "Removing existing environment..."
Remove-Item -Recurse -Force $VENV_PATH Remove-Item -Recurse -Force $VENV_PATH
} else { }
else {
Write-Success "Virtual environment already exists" Write-Success "Virtual environment already exists"
$pythonPath = "$VENV_PATH\Scripts\python.exe" $pythonPath = "$VENV_PATH\Scripts\python.exe"
if (Test-Path $pythonPath) { if (Test-Path $pythonPath) {
@@ -509,7 +525,8 @@ function Initialize-Environment {
Write-Success "Environment created with uv" Write-Success "Environment created with uv"
return Get-AbsolutePath "$VENV_PATH\Scripts\python.exe" return Get-AbsolutePath "$VENV_PATH\Scripts\python.exe"
} }
} catch { }
catch {
Write-Warning "uv failed, falling back to venv" Write-Warning "uv failed, falling back to venv"
} }
} }
@@ -533,11 +550,13 @@ function Initialize-Environment {
# Use the robust removal function # Use the robust removal function
if (Remove-LockedDirectory $VENV_PATH) { if (Remove-LockedDirectory $VENV_PATH) {
Write-Success "Existing environment removed" Write-Success "Existing environment removed"
} else { }
else {
throw "Unable to remove existing environment. Please restart your computer and try again." throw "Unable to remove existing environment. Please restart your computer and try again."
} }
} catch { }
catch {
Write-Error "Failed to remove existing environment: $_" Write-Error "Failed to remove existing environment: $_"
Write-Host "" Write-Host ""
Write-Host "Try these solutions:" -ForegroundColor Yellow Write-Host "Try these solutions:" -ForegroundColor Yellow
@@ -547,7 +566,8 @@ function Initialize-Environment {
Write-Host "4. Then run the script again" -ForegroundColor White Write-Host "4. Then run the script again" -ForegroundColor White
exit 1 exit 1
} }
} else { }
else {
Write-Success "Virtual environment already exists" Write-Success "Virtual environment already exists"
return Get-AbsolutePath "$VENV_PATH\Scripts\python.exe" return Get-AbsolutePath "$VENV_PATH\Scripts\python.exe"
} }
@@ -556,7 +576,8 @@ function Initialize-Environment {
Write-Info "Creating virtual environment with $pythonCmd..." Write-Info "Creating virtual environment with $pythonCmd..."
if ($pythonCmd.StartsWith("py ")) { if ($pythonCmd.StartsWith("py ")) {
Invoke-Expression "$pythonCmd -m venv $VENV_PATH" Invoke-Expression "$pythonCmd -m venv $VENV_PATH"
} else { }
else {
& $pythonCmd -m venv $VENV_PATH & $pythonCmd -m venv $VENV_PATH
} }
@@ -585,11 +606,13 @@ function Initialize-VirtualEnvironment {
# Use the robust removal function # Use the robust removal function
if (Remove-LockedDirectory $VENV_PATH) { if (Remove-LockedDirectory $VENV_PATH) {
Write-Success "Existing environment removed" Write-Success "Existing environment removed"
} else { }
else {
throw "Unable to remove existing environment. Please restart your computer and try again." throw "Unable to remove existing environment. Please restart your computer and try again."
} }
} catch { }
catch {
Write-Error "Failed to remove existing environment: $_" Write-Error "Failed to remove existing environment: $_"
Write-Host "" Write-Host ""
Write-Host "Try these solutions:" -ForegroundColor Yellow Write-Host "Try these solutions:" -ForegroundColor Yellow
@@ -599,7 +622,8 @@ function Initialize-VirtualEnvironment {
Write-Host "4. Then run the script again" -ForegroundColor White Write-Host "4. Then run the script again" -ForegroundColor White
exit 1 exit 1
} }
} else { }
else {
Write-Success "Virtual environment already exists" Write-Success "Virtual environment already exists"
return return
} }
@@ -622,7 +646,8 @@ function Initialize-VirtualEnvironment {
try { try {
if ($pythonCmd.StartsWith("py ")) { if ($pythonCmd.StartsWith("py ")) {
Invoke-Expression "$pythonCmd -m venv $VENV_PATH" Invoke-Expression "$pythonCmd -m venv $VENV_PATH"
} else { }
else {
& $pythonCmd -m venv $VENV_PATH & $pythonCmd -m venv $VENV_PATH
} }
@@ -631,7 +656,8 @@ function Initialize-VirtualEnvironment {
} }
Write-Success "Virtual environment created" Write-Success "Virtual environment created"
} catch { }
catch {
Write-Error "Failed to create virtual environment: $_" Write-Error "Failed to create virtual environment: $_"
exit 1 exit 1
} }
@@ -653,7 +679,8 @@ function Install-Dependencies {
if (Test-Path "requirements-dev.txt") { if (Test-Path "requirements-dev.txt") {
$requirementsFiles += "requirements-dev.txt" $requirementsFiles += "requirements-dev.txt"
Write-Info "Including development dependencies from requirements-dev.txt" Write-Info "Including development dependencies from requirements-dev.txt"
} else { }
else {
Write-Warning "Development dependencies requested but requirements-dev.txt not found" Write-Warning "Development dependencies requested but requirements-dev.txt not found"
} }
} }
@@ -665,14 +692,19 @@ function Install-Dependencies {
try { try {
foreach ($file in $requirementsFiles) { foreach ($file in $requirementsFiles) {
Write-Info "Installing from $file with uv..." Write-Info "Installing from $file with uv..."
uv pip install -r $file --python $PythonPath $uv = (Get-Command uv -ErrorAction Stop).Source
if ($LASTEXITCODE -ne 0) { $arguments = @('pip', 'install', '-r', $file, '--python', $PythonPath)
throw "uv failed to install $file" $proc = Start-Process -FilePath $uv -ArgumentList $arguments -NoNewWindow -Wait -PassThru
if ($proc.ExitCode -ne 0) {
throw "uv failed with exit code $($proc.ExitCode)"
} }
} }
Write-Success "Dependencies installed successfully with uv" Write-Success "Dependencies installed successfully with uv"
return return
} catch { }
catch {
Write-Warning "uv installation failed: $_. Falling back to pip" Write-Warning "uv installation failed: $_. Falling back to pip"
$useUv = $false $useUv = $false
} }
@@ -685,7 +717,8 @@ function Install-Dependencies {
try { try {
# Upgrade pip first # Upgrade pip first
& $pipCmd install --upgrade pip | Out-Null & $pipCmd install --upgrade pip | Out-Null
} catch { }
catch {
Write-Warning "Could not upgrade pip, continuing..." Write-Warning "Could not upgrade pip, continuing..."
} }
@@ -698,7 +731,8 @@ function Install-Dependencies {
} }
} }
Write-Success "Dependencies installed successfully with pip" Write-Success "Dependencies installed successfully with pip"
} catch { }
catch {
Write-Error "Failed to install dependencies with pip: $_" Write-Error "Failed to install dependencies with pip: $_"
exit 1 exit 1
} }
@@ -720,7 +754,8 @@ function Test-DockerRequirements {
try { try {
$null = docker version 2>$null $null = docker version 2>$null
Write-Success "Docker is installed and running" Write-Success "Docker is installed and running"
} catch { }
catch {
Write-Error "Docker is installed but not running. Please start Docker Desktop." Write-Error "Docker is installed but not running. Please start Docker Desktop."
return $false return $false
} }
@@ -731,11 +766,13 @@ function Test-DockerRequirements {
$null = docker compose version 2>$null $null = docker compose version 2>$null
Write-Success "Docker Compose (v2) is available" Write-Success "Docker Compose (v2) is available"
return $true return $true
} catch { }
catch {
Write-Error "Docker Compose not found. Please install Docker Compose." Write-Error "Docker Compose not found. Please install Docker Compose."
return $false return $false
} }
} else { }
else {
Write-Success "Docker Compose is available" Write-Success "Docker Compose is available"
return $true return $true
} }
@@ -754,7 +791,8 @@ function Build-DockerImage {
Write-Success "Docker image already exists. Use -Force to rebuild." Write-Success "Docker image already exists. Use -Force to rebuild."
return $true return $true
} }
} catch { }
catch {
# Continue if command fails # Continue if command fails
} }
@@ -762,7 +800,8 @@ function Build-DockerImage {
Write-Info "Forcing rebuild of Docker image..." Write-Info "Forcing rebuild of Docker image..."
try { try {
docker rmi zen-mcp-server:latest 2>$null docker rmi zen-mcp-server:latest 2>$null
} catch { }
catch {
Write-Warning "Could not remove existing image, continuing..." Write-Warning "Could not remove existing image, continuing..."
} }
} }
@@ -782,7 +821,8 @@ function Build-DockerImage {
Write-Success "Docker image built successfully" Write-Success "Docker image built successfully"
return $true return $true
} catch { }
catch {
Write-Error "Failed to build Docker image: $_" Write-Error "Failed to build Docker image: $_"
return $false return $false
} }
@@ -827,7 +867,8 @@ DEFAULT_THINKING_MODE_THINKDEEP=high
$defaultEnv | Out-File -FilePath ".env" -Encoding UTF8 $defaultEnv | Out-File -FilePath ".env" -Encoding UTF8
Write-Success "Default .env file created" Write-Success "Default .env file created"
Write-Warning "Please edit .env file with your actual API keys" Write-Warning "Please edit .env file with your actual API keys"
} else { }
else {
Write-Success ".env file exists" Write-Success ".env file exists"
} }
@@ -854,7 +895,8 @@ function Start-DockerServices {
Write-Info "Stopping any existing services..." Write-Info "Stopping any existing services..."
if (Test-Command "docker-compose") { if (Test-Command "docker-compose") {
docker-compose down 2>$null docker-compose down 2>$null
} else { }
else {
docker compose down 2>$null docker compose down 2>$null
} }
@@ -863,13 +905,16 @@ function Start-DockerServices {
if (Test-Command "docker-compose") { if (Test-Command "docker-compose") {
if ($Follow) { if ($Follow) {
docker-compose up --build docker-compose up --build
} else { }
else {
docker-compose up -d --build docker-compose up -d --build
} }
} else { }
else {
if ($Follow) { if ($Follow) {
docker compose up --build docker compose up --build
} else { }
else {
docker compose up -d --build docker compose up -d --build
} }
} }
@@ -889,7 +934,8 @@ function Start-DockerServices {
} }
return $true return $true
} catch { }
catch {
Write-Error "Failed to start Docker services: $_" Write-Error "Failed to start Docker services: $_"
return $false return $false
} }
@@ -902,11 +948,13 @@ function Get-DockerStatus {
if ($containerStatus) { if ($containerStatus) {
Write-Success "Container status: $containerStatus" Write-Success "Container status: $containerStatus"
return $true return $true
} else { }
else {
Write-Warning "Container not running" Write-Warning "Container not running"
return $false return $false
} }
} catch { }
catch {
Write-Warning "Could not get container status: $_" Write-Warning "Could not get container status: $_"
return $false return $false
} }
@@ -923,7 +971,8 @@ function Initialize-Logging {
if (!(Test-Path $LOG_DIR)) { if (!(Test-Path $LOG_DIR)) {
New-Item -ItemType Directory -Path $LOG_DIR -Force | Out-Null New-Item -ItemType Directory -Path $LOG_DIR -Force | Out-Null
Write-Success "Logs directory created" Write-Success "Logs directory created"
} else { }
else {
Write-Success "Logs directory already exists" Write-Success "Logs directory already exists"
} }
} }
@@ -944,13 +993,16 @@ function Test-Docker {
if (Test-Command "docker-compose") { if (Test-Command "docker-compose") {
Write-Success "Docker Compose is available" Write-Success "Docker Compose is available"
} else { }
else {
Write-Warning "Docker Compose not found. Install Docker Desktop for Windows." Write-Warning "Docker Compose not found. Install Docker Desktop for Windows."
} }
} catch { }
catch {
Write-Warning "Docker is installed but not running. Please start Docker Desktop." Write-Warning "Docker is installed but not running. Please start Docker Desktop."
} }
} else { }
else {
Write-Warning "Docker not found. Install Docker Desktop from https://docker.com" Write-Warning "Docker not found. Install Docker Desktop from https://docker.com"
} }
} }
@@ -1117,10 +1169,12 @@ function Get-ExistingMcpConfigType {
if ($zenConfig.args[0] -eq "run") { if ($zenConfig.args[0] -eq "run") {
$dockerType = "Docker Run" $dockerType = "Docker Run"
$details = "Docker run (dedicated container)" $details = "Docker run (dedicated container)"
} elseif ($zenConfig.args[0] -eq "exec") { }
elseif ($zenConfig.args[0] -eq "exec") {
$dockerType = "Docker Exec" $dockerType = "Docker Exec"
$details = "Docker exec (existing container)" $details = "Docker exec (existing container)"
} else { }
else {
$details = "Docker ($($zenConfig.args[0]))" $details = "Docker ($($zenConfig.args[0]))"
} }
} }
@@ -1133,15 +1187,18 @@ function Get-ExistingMcpConfigType {
Command = $zenConfig.command Command = $zenConfig.command
Args = $zenConfig.args Args = $zenConfig.args
} }
} elseif ($zenConfig.command -and $zenConfig.command.EndsWith("python.exe")) { }
elseif ($zenConfig.command -and $zenConfig.command.EndsWith("python.exe")) {
$pythonType = "Python" $pythonType = "Python"
$details = "Python virtual environment" $details = "Python virtual environment"
if ($zenConfig.command.Contains(".zen_venv")) { if ($zenConfig.command.Contains(".zen_venv")) {
$details = "Python (zen virtual environment)" $details = "Python (zen virtual environment)"
} elseif ($zenConfig.command.Contains("venv")) { }
elseif ($zenConfig.command.Contains("venv")) {
$details = "Python (virtual environment)" $details = "Python (virtual environment)"
} else { }
else {
$details = "Python (system installation)" $details = "Python (system installation)"
} }
@@ -1153,7 +1210,8 @@ function Get-ExistingMcpConfigType {
Command = $zenConfig.command Command = $zenConfig.command
Args = $zenConfig.args Args = $zenConfig.args
} }
} else { }
else {
return @{ return @{
Exists = $true Exists = $true
Type = "Unknown" Type = "Unknown"
@@ -1163,7 +1221,8 @@ function Get-ExistingMcpConfigType {
} }
} }
} catch { }
catch {
return @{ return @{
Exists = $false Exists = $false
Type = "Error" Type = "Error"
@@ -1189,7 +1248,8 @@ function Configure-McpClient {
$detected = $false $detected = $false
if ($Client.DetectionType -eq "Command" -and (Test-Command $Client.DetectionCommand)) { if ($Client.DetectionType -eq "Command" -and (Test-Command $Client.DetectionCommand)) {
$detected = $true $detected = $true
} elseif ($Client.DetectionType -eq "Path" -and (Test-Path ($Client.DetectionPath -as [string]))) { }
elseif ($Client.DetectionType -eq "Path" -and (Test-Path ($Client.DetectionPath -as [string]))) {
$detected = $true $detected = $true
} }
@@ -1284,7 +1344,8 @@ function Configure-McpClient {
if ($existingConfig.Type -eq $newConfigType) { if ($existingConfig.Type -eq $newConfigType) {
Write-Warning "Same configuration type ($($existingConfig.Type)) already exists" Write-Warning "Same configuration type ($($existingConfig.Type)) already exists"
$response = Read-Host "`nOverwrite existing $($existingConfig.Type) configuration? (y/N)" $response = Read-Host "`nOverwrite existing $($existingConfig.Type) configuration? (y/N)"
} else { }
else {
Write-Warning "Different configuration type detected" Write-Warning "Different configuration type detected"
Write-Info " Replacing: $($existingConfig.Type)$newConfigType" Write-Info " Replacing: $($existingConfig.Type)$newConfigType"
$response = Read-Host "`nReplace $($existingConfig.Type) with $newConfigType configuration? (y/N)" $response = Read-Host "`nReplace $($existingConfig.Type) with $newConfigType configuration? (y/N)"
@@ -1296,7 +1357,8 @@ function Configure-McpClient {
} }
Write-Info "Proceeding with configuration update..." Write-Info "Proceeding with configuration update..."
} else { }
else {
# User confirmation for new installation # User confirmation for new installation
$response = Read-Host "`nConfigure Zen MCP for $($Client.Name) (mode: $newConfigType)? (y/N)" $response = Read-Host "`nConfigure Zen MCP for $($Client.Name) (mode: $newConfigType)? (y/N)"
if ($response -ne 'y' -and $response -ne 'Y') { if ($response -ne 'y' -and $response -ne 'Y') {
@@ -1337,7 +1399,8 @@ function Configure-McpClient {
if (!$config.PSObject.Properties["servers"]) { if (!$config.PSObject.Properties["servers"]) {
$config | Add-Member -MemberType NoteProperty -Name "servers" -Value (New-Object PSObject) $config | Add-Member -MemberType NoteProperty -Name "servers" -Value (New-Object PSObject)
} }
} else { }
else {
# For other clients format: {"mcpServers": {...}} # For other clients format: {"mcpServers": {...}}
if (!$config.PSObject.Properties["mcpServers"]) { if (!$config.PSObject.Properties["mcpServers"]) {
$config | Add-Member -MemberType NoteProperty -Name "mcpServers" -Value (New-Object PSObject) $config | Add-Member -MemberType NoteProperty -Name "mcpServers" -Value (New-Object PSObject)
@@ -1359,7 +1422,8 @@ function Configure-McpClient {
$serverConfig = if ($UseDocker) { $serverConfig = if ($UseDocker) {
# Use docker run for all clients (more reliable than docker exec) # Use docker run for all clients (more reliable than docker exec)
Get-DockerMcpConfigRun $ServerPath Get-DockerMcpConfigRun $ServerPath
} else { }
else {
Get-PythonMcpConfig $PythonPath $ServerPath Get-PythonMcpConfig $PythonPath $ServerPath
} }
@@ -1384,7 +1448,8 @@ function Configure-McpClient {
Write-Host " Config: $configPath" -ForegroundColor Gray Write-Host " Config: $configPath" -ForegroundColor Gray
Write-Host " Restart $($Client.Name) to use the new MCP server" -ForegroundColor Gray Write-Host " Restart $($Client.Name) to use the new MCP server" -ForegroundColor Gray
} catch { }
catch {
Write-Error "Failed to update $($Client.Name) configuration: $_" Write-Error "Failed to update $($Client.Name) configuration: $_"
} }
} }
@@ -1427,11 +1492,13 @@ function Test-ClaudeCliIntegration {
$claudeConfig = claude config list 2>$null $claudeConfig = claude config list 2>$null
if ($claudeConfig -match "zen") { if ($claudeConfig -match "zen") {
Write-Success "Claude CLI already configured for zen server" Write-Success "Claude CLI already configured for zen server"
} else { }
else {
Write-Info "To add zen server to Claude CLI, run:" Write-Info "To add zen server to Claude CLI, run:"
Write-Host " claude config add-server zen $PythonPath $ServerPath" -ForegroundColor Cyan Write-Host " claude config add-server zen $PythonPath $ServerPath" -ForegroundColor Cyan
} }
} catch { }
catch {
Write-Info "To configure Claude CLI manually, run:" Write-Info "To configure Claude CLI manually, run:"
Write-Host " claude config add-server zen $PythonPath $ServerPath" -ForegroundColor Cyan Write-Host " claude config add-server zen $PythonPath $ServerPath" -ForegroundColor Cyan
} }
@@ -1510,7 +1577,8 @@ if exist ".zen_venv\Scripts\python.exe" (
Write-Host " Config: $geminiConfig" -ForegroundColor Gray Write-Host " Config: $geminiConfig" -ForegroundColor Gray
Write-Host " Restart Gemini CLI to use Zen MCP Server" -ForegroundColor Gray Write-Host " Restart Gemini CLI to use Zen MCP Server" -ForegroundColor Gray
} catch { }
catch {
Write-Error "Failed to update Gemini CLI config: $_" Write-Error "Failed to update Gemini CLI config: $_"
Write-Host "" Write-Host ""
Write-Host "Manual config location: $geminiConfig" Write-Host "Manual config location: $geminiConfig"
@@ -1523,6 +1591,9 @@ if exist ".zen_venv\Scripts\python.exe" (
} }
} }
} }
"@ -ForegroundColor Yellow
}
}
function Show-QwenManualConfig { function Show-QwenManualConfig {
param( param(
@@ -1554,7 +1625,8 @@ function Show-QwenManualConfig {
Write-Host " }" -ForegroundColor Yellow Write-Host " }" -ForegroundColor Yellow
Write-Host " }" -ForegroundColor Yellow Write-Host " }" -ForegroundColor Yellow
Write-Host "}" -ForegroundColor Yellow Write-Host "}" -ForegroundColor Yellow
} else { }
else {
Write-Host "{" -ForegroundColor Yellow Write-Host "{" -ForegroundColor Yellow
Write-Host " \"mcpServers\": {" -ForegroundColor Yellow Write-Host " \"mcpServers\": {" -ForegroundColor Yellow
Write-Host " \"zen\": {" -ForegroundColor Yellow Write-Host " \"zen\": {" -ForegroundColor Yellow
@@ -1604,7 +1676,8 @@ function Test-QwenCliIntegration {
$argsList = @() $argsList = @()
if ($argsValue -is [System.Collections.IEnumerable] -and $argsValue -isnot [string]) { if ($argsValue -is [System.Collections.IEnumerable] -and $argsValue -isnot [string]) {
$argsList = @($argsValue) $argsList = @($argsValue)
} elseif ($null -ne $argsValue) { }
elseif ($null -ne $argsValue) {
$argsList = @($argsValue) $argsList = @($argsValue)
} }
$argsMatches = ($argsList.Count -eq 1 -and $argsList[0] -eq $ServerPath) $argsMatches = ($argsList.Count -eq 1 -and $argsList[0] -eq $ServerPath)
@@ -1624,7 +1697,8 @@ function Test-QwenCliIntegration {
Write-Warning "Existing Qwen CLI configuration differs from the current setup." Write-Warning "Existing Qwen CLI configuration differs from the current setup."
} }
} }
} catch { }
catch {
$configStatus = "invalid" $configStatus = "invalid"
Write-Warning "Unable to parse Qwen CLI settings at $configPath ($_)." Write-Warning "Unable to parse Qwen CLI settings at $configPath ($_)."
$config = @{} $config = @{}
@@ -1720,14 +1794,13 @@ function Test-QwenCliIntegration {
Write-Success "Successfully configured Qwen CLI" Write-Success "Successfully configured Qwen CLI"
Write-Host " Config: $configPath" -ForegroundColor Gray Write-Host " Config: $configPath" -ForegroundColor Gray
Write-Host " Restart Qwen CLI to use Zen MCP Server" -ForegroundColor Gray Write-Host " Restart Qwen CLI to use Zen MCP Server" -ForegroundColor Gray
} catch { }
catch {
Write-Error "Failed to update Qwen CLI configuration: $_" Write-Error "Failed to update Qwen CLI configuration: $_"
Show-QwenManualConfig $PythonPath $ServerPath $scriptDir $configPath $envMap Show-QwenManualConfig $PythonPath $ServerPath $scriptDir $configPath $envMap
} }
} }
"@ -ForegroundColor Yellow
}
}
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# End MCP Client Configuration System # End MCP Client Configuration System
@@ -1793,7 +1866,8 @@ function Show-ConfigInstructions {
Write-Host "The MCP clients have been configured to use Docker containers." -ForegroundColor White Write-Host "The MCP clients have been configured to use Docker containers." -ForegroundColor White
Write-Host "Make sure the Docker container is running with: docker-compose up -d" -ForegroundColor Cyan Write-Host "Make sure the Docker container is running with: docker-compose up -d" -ForegroundColor Cyan
Write-Host "" Write-Host ""
} else { }
else {
Write-Host "Python Virtual Environment Configuration:" -ForegroundColor Yellow Write-Host "Python Virtual Environment Configuration:" -ForegroundColor Yellow
Write-Host "Python Path: $PythonPath" -ForegroundColor Cyan Write-Host "Python Path: $PythonPath" -ForegroundColor Cyan
Write-Host "Server Path: $ServerPath" -ForegroundColor Cyan Write-Host "Server Path: $ServerPath" -ForegroundColor Cyan
@@ -1828,7 +1902,8 @@ function Show-SetupInstructions {
if ($UseDocker) { if ($UseDocker) {
Write-Success "Zen MCP Server is configured for Docker deployment" Write-Success "Zen MCP Server is configured for Docker deployment"
Write-Host "Docker command: docker exec -i zen-mcp-server python server.py" -ForegroundColor Cyan Write-Host "Docker command: docker exec -i zen-mcp-server python server.py" -ForegroundColor Cyan
} else { }
else {
Write-Success "Zen MCP Server is configured for Python virtual environment" Write-Success "Zen MCP Server is configured for Python virtual environment"
Write-Host "Python: $PythonPath" -ForegroundColor Cyan Write-Host "Python: $PythonPath" -ForegroundColor Cyan
Write-Host "Server: $ServerPath" -ForegroundColor Cyan Write-Host "Server: $ServerPath" -ForegroundColor Cyan
@@ -1858,7 +1933,8 @@ function Start-Server {
try { try {
Write-Info "Launching server..." Write-Info "Launching server..."
& $pythonPath $serverPath & $pythonPath $serverPath
} catch { }
catch {
Write-Error "Failed to start server: $_" Write-Error "Failed to start server: $_"
} }
} }
@@ -1881,7 +1957,8 @@ function Follow-Logs {
Write-Host "Press Ctrl+C to stop following logs" Write-Host "Press Ctrl+C to stop following logs"
Write-Host "" Write-Host ""
Get-Content $logPath -Wait Get-Content $logPath -Wait
} catch { }
catch {
Write-Error "Failed to follow logs: $_" Write-Error "Failed to follow logs: $_"
} }
} }
@@ -1926,7 +2003,8 @@ DEFAULT_THINKING_MODE_THINKDEEP=high
Write-Success "Default .env file created" Write-Success "Default .env file created"
Write-Warning "Please edit .env file with your actual API keys" Write-Warning "Please edit .env file with your actual API keys"
} else { }
else {
Write-Success ".env file already exists" Write-Success ".env file already exists"
} }
} }
@@ -1950,7 +2028,8 @@ function Import-EnvFile {
} }
} }
Write-Success "Environment variables loaded from .env file" Write-Success "Environment variables loaded from .env file"
} catch { }
catch {
Write-Warning "Could not load .env file: $_" Write-Warning "Could not load .env file: $_"
} }
} }
@@ -2034,14 +2113,16 @@ function Invoke-PythonWorkflow {
try { try {
$pythonPath = Initialize-Environment $pythonPath = Initialize-Environment
} catch { }
catch {
Write-Error "Failed to setup Python environment: $_" Write-Error "Failed to setup Python environment: $_"
exit 1 exit 1
} }
try { try {
Install-Dependencies $pythonPath -InstallDevDependencies:$Dev Install-Dependencies $pythonPath -InstallDevDependencies:$Dev
} catch { }
catch {
Write-Error "Failed to install dependencies: $_" Write-Error "Failed to install dependencies: $_"
exit 1 exit 1
} }
@@ -2060,7 +2141,8 @@ function Invoke-PythonWorkflow {
if ($Follow) { if ($Follow) {
Follow-Logs Follow-Logs
} else { }
else {
Write-Host "To follow logs: .\run-server.ps1 -Follow" -ForegroundColor Yellow Write-Host "To follow logs: .\run-server.ps1 -Follow" -ForegroundColor Yellow
Write-Host "To show config: .\run-server.ps1 -Config" -ForegroundColor Yellow Write-Host "To show config: .\run-server.ps1 -Config" -ForegroundColor Yellow
Write-Host "To update: git pull, then run .\run-server.ps1 again" -ForegroundColor Yellow Write-Host "To update: git pull, then run .\run-server.ps1 again" -ForegroundColor Yellow
@@ -2115,13 +2197,15 @@ function Start-MainProcess {
} }
Initialize-DockerEnvironment Initialize-DockerEnvironment
Show-ConfigInstructions "" "" -UseDocker Show-ConfigInstructions "" "" -UseDocker
} else { }
else {
# Python virtual environment configuration mode # Python virtual environment configuration mode
$pythonPath = Initialize-Environment $pythonPath = Initialize-Environment
$serverPath = Get-AbsolutePath "server.py" $serverPath = Get-AbsolutePath "server.py"
Show-ConfigInstructions $pythonPath $serverPath Show-ConfigInstructions $pythonPath $serverPath
} }
} catch { }
catch {
Write-Error "Failed to setup environment for configuration: $_" Write-Error "Failed to setup environment for configuration: $_"
exit 1 exit 1
} }