fix: replaced deprecated Codex web search configuration
This commit is contained in:
272
run-server.sh
272
run-server.sh
@@ -1676,132 +1676,62 @@ EOF
|
|||||||
|
|
||||||
# Check and update Codex CLI configuration
|
# Check and update Codex CLI configuration
|
||||||
check_codex_cli_integration() {
|
check_codex_cli_integration() {
|
||||||
# Check if Codex is installed
|
|
||||||
if ! command -v codex &> /dev/null; then
|
if ! command -v codex &> /dev/null; then
|
||||||
# Codex CLI not installed
|
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local codex_config="$HOME/.codex/config.toml"
|
local codex_config="$HOME/.codex/config.toml"
|
||||||
|
local codex_has_zen=false
|
||||||
# Check if zen is already configured
|
|
||||||
if [[ -f "$codex_config" ]] && grep -q '\[mcp_servers\.zen\]' "$codex_config" 2>/dev/null; then
|
if [[ -f "$codex_config" ]] && grep -q '\[mcp_servers\.zen\]' "$codex_config" 2>/dev/null; then
|
||||||
# Already configured
|
codex_has_zen=true
|
||||||
return 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ask user if they want to add Zen to Codex CLI
|
if [[ "$codex_has_zen" == false ]]; then
|
||||||
echo ""
|
|
||||||
read -p "Configure Zen for Codex CLI? (Y/n): " -n 1 -r
|
|
||||||
echo ""
|
|
||||||
if [[ $REPLY =~ ^[Nn]$ ]]; then
|
|
||||||
print_info "Skipping Codex CLI integration"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
print_info "Updating Codex CLI configuration..."
|
|
||||||
|
|
||||||
# Create config directory if it doesn't exist
|
|
||||||
mkdir -p "$(dirname "$codex_config")" 2>/dev/null || true
|
|
||||||
|
|
||||||
# Create backup if config exists
|
|
||||||
if [[ -f "$codex_config" ]]; then
|
|
||||||
cp "$codex_config" "${codex_config}.backup_$(date +%Y%m%d_%H%M%S)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Get environment variables using shared function
|
|
||||||
local env_vars=$(parse_env_variables)
|
|
||||||
|
|
||||||
# Write zen configuration to config.toml
|
|
||||||
{
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "[mcp_servers.zen]"
|
read -p "Configure Zen for Codex CLI? (Y/n): " -n 1 -r
|
||||||
echo "command = \"bash\""
|
|
||||||
echo "args = [\"-c\", \"for p in \$(which uvx 2>/dev/null) \$HOME/.local/bin/uvx /opt/homebrew/bin/uvx /usr/local/bin/uvx uvx; do [ -x \\\"\$p\\\" ] && exec \\\"\$p\\\" --from git+https://github.com/BeehiveInnovations/zen-mcp-server.git zen-mcp-server; done; echo 'uvx not found' >&2; exit 1\"]"
|
|
||||||
echo "tool_timeout_sec = 1200"
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "[mcp_servers.zen.env]"
|
if [[ $REPLY =~ ^[Nn]$ ]]; then
|
||||||
echo "PATH = \"/usr/local/bin:/usr/bin:/bin:/opt/homebrew/bin:\$HOME/.local/bin:\$HOME/.cargo/bin:\$HOME/bin\""
|
print_info "Skipping Codex CLI integration"
|
||||||
if [[ -n "$env_vars" ]]; then
|
return 0
|
||||||
# Convert KEY=VALUE format to TOML KEY = "VALUE" format
|
|
||||||
while IFS= read -r line; do
|
|
||||||
if [[ -n "$line" && "$line" =~ ^([^=]+)=(.*)$ ]]; then
|
|
||||||
local key="${BASH_REMATCH[1]}"
|
|
||||||
local value="${BASH_REMATCH[2]}"
|
|
||||||
# Escape backslashes first, then double quotes for TOML compatibility
|
|
||||||
local escaped_value
|
|
||||||
escaped_value=$(echo "$value" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g')
|
|
||||||
echo "$key = \"$escaped_value\""
|
|
||||||
fi
|
|
||||||
done <<< "$env_vars"
|
|
||||||
fi
|
fi
|
||||||
} >> "$codex_config"
|
|
||||||
|
|
||||||
if [[ $? -eq 0 ]]; then
|
print_info "Updating Codex CLI configuration..."
|
||||||
print_success "Successfully configured Codex CLI"
|
|
||||||
echo " Config: $codex_config"
|
|
||||||
echo " Restart Codex CLI to use Zen MCP Server"
|
|
||||||
|
|
||||||
if ! grep -Eq '^\s*web_search\s*=' "$codex_config" 2>/dev/null; then
|
mkdir -p "$(dirname "$codex_config")" 2>/dev/null || true
|
||||||
|
|
||||||
|
if [[ -f "$codex_config" ]]; then
|
||||||
|
cp "$codex_config" "${codex_config}.backup_$(date +%Y%m%d_%H%M%S)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
local env_vars=$(parse_env_variables)
|
||||||
|
|
||||||
|
{
|
||||||
echo ""
|
echo ""
|
||||||
print_info "Web search lets Codex pull fresh documentation for Zen's API lookup tooling."
|
echo "[mcp_servers.zen]"
|
||||||
read -p "Enable Codex CLI web search tool? (Y/n): " -n 1 -r
|
echo "command = \"bash\""
|
||||||
|
echo "args = [\"-c\", \"for p in \$(which uvx 2>/dev/null) \$HOME/.local/bin/uvx /opt/homebrew/bin/uvx /usr/local/bin/uvx uvx; do [ -x \\\"\$p\\\" ] && exec \\\"\$p\\\" --from git+https://github.com/BeehiveInnovations/zen-mcp-server.git zen-mcp-server; done; echo 'uvx not found' >&2; exit 1\"]"
|
||||||
|
echo "tool_timeout_sec = 1200"
|
||||||
echo ""
|
echo ""
|
||||||
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
|
echo "[mcp_servers.zen.env]"
|
||||||
if grep -Eq '^\s*\[tools\]' "$codex_config" 2>/dev/null; then
|
echo "PATH = \"/usr/local/bin:/usr/bin:/bin:/opt/homebrew/bin:\$HOME/.local/bin:\$HOME/.cargo/bin:\$HOME/bin\""
|
||||||
if ! python3 - "$codex_config" <<'PY'
|
if [[ -n "$env_vars" ]]; then
|
||||||
import sys
|
while IFS= read -r line; do
|
||||||
from pathlib import Path
|
if [[ -n "$line" && "$line" =~ ^([^=]+)=(.*)$ ]]; then
|
||||||
|
local key="${BASH_REMATCH[1]}"
|
||||||
cfg_path = Path(sys.argv[1])
|
local value="${BASH_REMATCH[2]}"
|
||||||
content = cfg_path.read_text().splitlines()
|
local escaped_value
|
||||||
output = []
|
escaped_value=$(echo "$value" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g')
|
||||||
in_tools = False
|
echo "$key = \"$escaped_value\""
|
||||||
added = False
|
|
||||||
|
|
||||||
for line in content:
|
|
||||||
stripped = line.strip()
|
|
||||||
if stripped.startswith("[") and stripped.endswith("]"):
|
|
||||||
if in_tools and not added:
|
|
||||||
output.append("web_search = true")
|
|
||||||
added = True
|
|
||||||
in_tools = stripped == "[tools]"
|
|
||||||
output.append(line)
|
|
||||||
continue
|
|
||||||
if in_tools and stripped.startswith("web_search"):
|
|
||||||
added = True
|
|
||||||
output.append(line)
|
|
||||||
|
|
||||||
if in_tools and not added:
|
|
||||||
output.append("web_search = true")
|
|
||||||
|
|
||||||
cfg_path.write_text("\n".join(output) + "\n")
|
|
||||||
PY
|
|
||||||
then
|
|
||||||
print_error "Failed to enable Codex web search tool. Add 'web_search = true' under [tools] in $codex_config manually."
|
|
||||||
else
|
|
||||||
print_success "Enabled Codex web search tool"
|
|
||||||
fi
|
fi
|
||||||
else
|
done <<< "$env_vars"
|
||||||
{
|
|
||||||
echo ""
|
|
||||||
echo "[tools]"
|
|
||||||
echo "web_search = true"
|
|
||||||
} >> "$codex_config" && print_success "Enabled Codex web search tool" || \
|
|
||||||
print_error "Failed to enable Codex web search tool. Add 'web_search = true' under [tools] in $codex_config manually."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
print_info "Skipping Codex web search tool enablement"
|
|
||||||
fi
|
fi
|
||||||
fi
|
} >> "$codex_config"
|
||||||
else
|
|
||||||
print_error "Failed to update Codex CLI config"
|
|
||||||
echo "Manual config location: $codex_config"
|
|
||||||
echo "Add this configuration:"
|
|
||||||
|
|
||||||
# Generate example with actual environment variables for error case
|
if [[ $? -ne 0 ]]; then
|
||||||
env_vars=$(parse_env_variables)
|
print_error "Failed to update Codex CLI config"
|
||||||
cat << EOF
|
echo "Manual config location: $codex_config"
|
||||||
|
echo "Add this configuration:"
|
||||||
|
cat <<'CODExEOF'
|
||||||
[mcp_servers.zen]
|
[mcp_servers.zen]
|
||||||
command = "sh"
|
command = "sh"
|
||||||
args = ["-c", "exec \$(which uvx 2>/dev/null || echo uvx) --from git+https://github.com/BeehiveInnovations/zen-mcp-server.git zen-mcp-server"]
|
args = ["-c", "exec \$(which uvx 2>/dev/null || echo uvx) --from git+https://github.com/BeehiveInnovations/zen-mcp-server.git zen-mcp-server"]
|
||||||
@@ -1809,19 +1739,123 @@ tool_timeout_sec = 1200
|
|||||||
|
|
||||||
[mcp_servers.zen.env]
|
[mcp_servers.zen.env]
|
||||||
PATH = "/usr/local/bin:/usr/bin:/bin:/opt/homebrew/bin:\$HOME/.local/bin:\$HOME/.cargo/bin:\$HOME/bin"
|
PATH = "/usr/local/bin:/usr/bin:/bin:/opt/homebrew/bin:\$HOME/.local/bin:\$HOME/.cargo/bin:\$HOME/bin"
|
||||||
EOF
|
|
||||||
|
|
||||||
# Add environment variable examples only if they exist
|
[features]
|
||||||
if [[ -n "$env_vars" ]]; then
|
web_search_request = true
|
||||||
while IFS= read -r line; do
|
CODExEOF
|
||||||
if [[ -n "$line" && "$line" =~ ^([^=]+)=(.*)$ ]]; then
|
|
||||||
local key="${BASH_REMATCH[1]}"
|
if [[ -n "$env_vars" ]]; then
|
||||||
echo "${key} = \"your_$(echo "${key}" | tr '[:upper:]' '[:lower:]')\""
|
while IFS= read -r line; do
|
||||||
|
if [[ -n "$line" && "$line" =~ ^([^=]+)=(.*)$ ]]; then
|
||||||
|
local key="${BASH_REMATCH[1]}"
|
||||||
|
echo "${key} = \"your_$(echo "${key}" | tr '[:upper:]' '[:lower:]')\""
|
||||||
|
fi
|
||||||
|
done <<< "$env_vars"
|
||||||
|
else
|
||||||
|
echo "GEMINI_API_KEY = \"your_gemini_api_key_here\""
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_success "Successfully configured Codex CLI"
|
||||||
|
echo " Config: $codex_config"
|
||||||
|
echo " Restart Codex CLI to use Zen MCP Server"
|
||||||
|
codex_has_zen=true
|
||||||
|
else
|
||||||
|
print_info "Codex CLI already configured; refreshing Codex settings..."
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$codex_has_zen" == true ]]; then
|
||||||
|
if ! grep -Eq '^\s*web_search_request\s*=' "$codex_config" 2>/dev/null; then
|
||||||
|
echo ""
|
||||||
|
print_info "Web search requests let Codex pull fresh documentation for Zen's API lookup tooling."
|
||||||
|
read -p "Enable Codex CLI web search requests? (Y/n): " -n 1 -r
|
||||||
|
echo ""
|
||||||
|
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
|
||||||
|
if grep -Eq '^\s*\[features\]' "$codex_config" 2>/dev/null; then
|
||||||
|
if ! python3 - "$codex_config" <<'PY'
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
cfg_path = Path(sys.argv[1])
|
||||||
|
content = cfg_path.read_text().splitlines()
|
||||||
|
output = []
|
||||||
|
in_features = False
|
||||||
|
added = False
|
||||||
|
|
||||||
|
for line in content:
|
||||||
|
stripped = line.strip()
|
||||||
|
if stripped.startswith("[") and stripped.endswith("]"):
|
||||||
|
if in_features and not added:
|
||||||
|
output.append("web_search_request = true")
|
||||||
|
added = True
|
||||||
|
in_features = stripped == "[features]"
|
||||||
|
output.append(line)
|
||||||
|
continue
|
||||||
|
if in_features and stripped.startswith("web_search_request"):
|
||||||
|
added = True
|
||||||
|
output.append(line)
|
||||||
|
|
||||||
|
if in_features and not added:
|
||||||
|
output.append("web_search_request = true")
|
||||||
|
|
||||||
|
cfg_path.write_text("\n".join(output) + "\n")
|
||||||
|
PY
|
||||||
|
then
|
||||||
|
print_error "Failed to enable Codex web search request feature. Add 'web_search_request = true' under [features] in $codex_config manually."
|
||||||
|
else
|
||||||
|
print_success "Enabled Codex web search request feature"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo ""
|
||||||
|
echo "[features]"
|
||||||
|
echo "web_search_request = true"
|
||||||
|
} >> "$codex_config" && print_success "Enabled Codex web search request feature" || \
|
||||||
|
print_error "Failed to enable Codex web search request feature. Add 'web_search_request = true' under [features] in $codex_config manually."
|
||||||
fi
|
fi
|
||||||
done <<< "$env_vars"
|
else
|
||||||
else
|
print_info "Skipping Codex web search request feature"
|
||||||
# Show GEMINI_API_KEY example if no environment variables exist
|
fi
|
||||||
echo "GEMINI_API_KEY = \"your_gemini_api_key_here\""
|
fi
|
||||||
|
|
||||||
|
if grep -Eq '^\s*\[tools\]' "$codex_config" 2>/dev/null && \
|
||||||
|
grep -Eq '^\s*web_search\s*=' "$codex_config" 2>/dev/null; then
|
||||||
|
local removal_status
|
||||||
|
if removal_status=$(python3 - "$codex_config" <<'PY' | tr -d '\n'
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
cfg_path = Path(sys.argv[1])
|
||||||
|
lines = cfg_path.read_text().splitlines()
|
||||||
|
output = []
|
||||||
|
in_tools = False
|
||||||
|
removed = False
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
stripped = line.strip()
|
||||||
|
if stripped.startswith('[') and stripped.endswith(']'):
|
||||||
|
in_tools = stripped == '[tools]'
|
||||||
|
output.append(line)
|
||||||
|
continue
|
||||||
|
if in_tools and stripped.startswith('web_search'):
|
||||||
|
removed = True
|
||||||
|
continue
|
||||||
|
output.append(line)
|
||||||
|
|
||||||
|
if removed:
|
||||||
|
cfg_path.write_text("\n".join(output) + "\n")
|
||||||
|
print('REMOVED', end='')
|
||||||
|
else:
|
||||||
|
print('UNCHANGED', end='')
|
||||||
|
PY
|
||||||
|
); then
|
||||||
|
if [[ "$removal_status" == "REMOVED" ]]; then
|
||||||
|
print_success "Removed deprecated Codex [tools].web_search entry"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
print_warning "Failed to clean up deprecated Codex [tools].web_search entry; remove manually from $codex_config"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user