-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.cmd
More file actions
31 lines (23 loc) · 3.95 KB
/
Copy pathsetup.cmd
File metadata and controls
31 lines (23 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
@echo off
REM Setup script for Codex MCP config
REM 1. Ensures CODEX_HOME is set (so Codex finds config on Windows)
REM 2. Adds MCP server config to ~/.codex/config.toml (without touching existing config)
set "CODEX_CONFIG=%USERPROFILE%\.codex\config.toml"
echo.
echo Codex Orchestrator Setup
echo ========================
echo.
REM === Step 1: Ensure CODEX_HOME ===
echo [1/2] Ensuring CODEX_HOME...
powershell -NoProfile -Command "$codexHome = '%USERPROFILE%\.codex'; $current = [Environment]::GetEnvironmentVariable('CODEX_HOME', 'User'); if ([string]::IsNullOrWhiteSpace($current)) { [Environment]::SetEnvironmentVariable('CODEX_HOME', $codexHome, 'User'); Write-Host ' Set CODEX_HOME for current user.' -ForegroundColor Green } else { Write-Host ' CODEX_HOME already set.' }"
echo.
REM === Step 2: Add MCP config ===
echo [2/2] Configuring MCP server in %CODEX_CONFIG%...
powershell -NoProfile -Command "$configPath = '%CODEX_CONFIG%'; $configDir = Split-Path $configPath -Parent; if (-not (Test-Path $configDir)) { New-Item -ItemType Directory -Path $configDir -Force | Out-Null }; if (-not (Test-Path $configPath)) { New-Item -ItemType File -Path $configPath -Force | Out-Null }; $content = Get-Content $configPath -Raw -ErrorAction SilentlyContinue; $nl = [Environment]::NewLine; $forkRepo = 'https://github.com/Flewrider/codex-mcp-server.git'; $forkBranch = 'fix-session-init'; $forkDir = Join-Path $env:USERPROFILE '.codex\\codex-mcp-server'; $merged = $false; try { $pr = Invoke-RestMethod -Uri 'https://api.github.com/repos/tuannvm/codex-mcp-server/pulls/94' -Headers @{ 'User-Agent' = 'codex-orchestrator-setup' }; if ($pr.merged_at) { $merged = $true } } catch { Write-Host ' Could not check PR status; using forked server.' -ForegroundColor Yellow }; if (-not $merged) { Write-Host ' Using forked codex-mcp-server (patched).' -ForegroundColor Yellow; if (-not (Get-Command git -ErrorAction SilentlyContinue)) { throw 'git not found. Install Git or merge PR #94 and rerun setup.' } if (-not (Test-Path $forkDir)) { git clone $forkRepo $forkDir | Out-Null } Push-Location $forkDir; git fetch origin $forkBranch | Out-Null; git checkout $forkBranch | Out-Null; git pull origin $forkBranch | Out-Null; if (-not (Get-Command npm -ErrorAction SilentlyContinue)) { throw 'npm not found. Install Node.js to build the patched server.' } npm install | Out-Null; npm run build | Out-Null; Pop-Location; } $serverPath = Join-Path $forkDir 'dist\\index.js'; $serverPathToml = $serverPath -replace '[\\\\]', '/'; if ($merged) { $mcpBlock = \"# Codex Orchestrator - MCP worker configuration${nl}[mcp_servers.codex_worker]${nl}command = `\"npx`\"${nl}args = [`\"-y`\", `\"codex-mcp-server`\"]${nl}startup_timeout_sec = 30${nl}tool_timeout_sec = 300${nl}\" } else { $mcpBlock = \"# Codex Orchestrator - MCP worker configuration${nl}[mcp_servers.codex_worker]${nl}command = `\"node`\"${nl}args = [`\"$serverPathToml`\"]${nl}startup_timeout_sec = 30${nl}tool_timeout_sec = 300${nl}\" } $pattern = '(?ms)^\\[mcp_servers\\.codex_worker\\]\\R.*?(?=^\\[[A-Za-z0-9_.-]+\\]|\\z)'; $lines = $content -split '\r?\n'; $clean = New-Object System.Collections.Generic.List[string]; for ($i = 0; $i -lt $lines.Length; $i++) { $line = $lines[$i]; $trimmed = $line.Trim(); $isStrayPath = $trimmed.StartsWith('[') -and $trimmed.EndsWith(']') -and ($line -match 'codex-mcp-server') -and ($line -match 'index\.js'); if ($isStrayPath) { if ($i + 2 -lt $lines.Length -and $lines[$i + 1] -match '^startup_timeout_sec' -and $lines[$i + 2] -match '^tool_timeout_sec') { $i += 2 } continue } $clean.Add($line) } $content = ($clean -join $nl); if ($content -match '\\[mcp_servers\\.codex_worker\\]') { $content = [Regex]::Replace($content, $pattern, ($mcpBlock + $nl)); Set-Content -Path $configPath -Value $content } else { Add-Content -Path $configPath -Value ($nl + $mcpBlock) -NoNewline } Write-Host ' MCP server configured.' -ForegroundColor Green"
echo.
echo ========================
echo Setup complete!
echo.
echo Then run: codex
echo.
pause