param( [switch]$Install, [string]$ApiKey = "termi-mcp-local-dev-key", [string]$BackendApiBase = "http://127.0.0.1:5150/api", [int]$Port = 5151 ) $ErrorActionPreference = "Stop" $repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path $mcpDir = Join-Path $repoRoot "mcp-server" if (-not (Test-Path $mcpDir)) { throw "MCP server directory not found: $mcpDir" } Push-Location $mcpDir try { if ($Install -or -not (Test-Path (Join-Path $mcpDir "node_modules"))) { Write-Host "[mcp] Installing dependencies..." -ForegroundColor Cyan npm install if ($LASTEXITCODE -ne 0) { throw "npm install failed" } } $env:TERMI_MCP_API_KEY = $ApiKey $env:TERMI_BACKEND_API_BASE = $BackendApiBase $env:TERMI_MCP_PORT = "$Port" Write-Host "[mcp] Backend API base set to $BackendApiBase" -ForegroundColor Cyan Write-Host "[mcp] Starting MCP server on port $Port..." -ForegroundColor Green npm run start if ($LASTEXITCODE -ne 0) { throw "npm run start failed" } } finally { Pop-Location }