Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 47 additions & 25 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1108,11 +1108,15 @@ is_category_supported() {
local category="$1"
local supported="$2"
local item
local saved_ifs="${IFS}"
IFS=' '
for item in ${supported}; do
if [ "${item}" = "${category}" ]; then
IFS="${saved_ifs}"
return 0
fi
done
IFS="${saved_ifs}"
return 1
}

Expand All @@ -1126,21 +1130,27 @@ get_available_categories() {
local -a available=()
local cat editor supported

local saved_ifs="${IFS}"
for cat in "${base[@]}"; do
local ok=1
IFS=' '
for editor in ${SELECTED_EDITORS}; do
IFS="${saved_ifs}"
supported="$(get_supported_categories "${editor}" "${scope}")"
if ! is_category_supported "${cat}" "${supported}"; then
ok=0
break
fi
done
IFS="${saved_ifs}"
if [ "${ok}" -eq 1 ]; then
available+=("${cat}")
fi
done

IFS=' '
printf '%s' "${available[*]}"
IFS="${saved_ifs}"
}

normalize_selected_categories() {
Expand Down Expand Up @@ -1220,15 +1230,15 @@ mcp_category_selected() {
extract_mcp_keys_fallback() {
local src="$1"
awk '
BEGIN { in=0; depth=0 }
BEGIN { inside=0; depth=0 }
/"mcpServers"[[:space:]]*:[[:space:]]*{/ {
in=1
inside=1
depth=1
next
}
in {
if (depth == 1 && match($0, /"[^"]+"[[:space:]]*:[[:space:]]*{/)) {
key=substr($0, RSTART + 1, RLENGTH - 3)
inside {
if (depth == 1 && match($0, /"[^"]+"/)) {
key=substr($0, RSTART + 1, RLENGTH - 2)
print key
}
depth += gsub(/{/, "{")
Expand Down Expand Up @@ -1984,7 +1994,8 @@ build_selected_mcp_source() {
TMP_ROOT="$(mktemp -d)"
fi

local tmp="${TMP_ROOT}/mcp_selected.$$"
local tmp
tmp="$(mktemp "${TMP_ROOT}/mcp_selected.XXXXXX")"
if command -v jq >/dev/null 2>&1; then
local keys_json
keys_json="$(printf '%s' "${selected}" | awk -F',' '{
Expand Down Expand Up @@ -2085,7 +2096,8 @@ merge_codex_mcp() {
TMP_ROOT="$(mktemp -d)"
fi

local tmp="${TMP_ROOT}/mcp_codex.$$"
local tmp
tmp="$(mktemp "${TMP_ROOT}/mcp_codex.XXXXXX")"
local -a selected_keys=()
local key
while IFS= read -r key; do
Expand Down Expand Up @@ -2192,7 +2204,7 @@ merge_mcp() {
fi

local tmp
tmp="${TMP_ROOT}/mcp_merge.$$"
tmp="$(mktemp "${TMP_ROOT}/mcp_merge.XXXXXX")"
jq -s '.[0] * .[1]' "${dest}" "${src}" > "${tmp}" || {
rm -f "${tmp}"
return 1
Expand Down Expand Up @@ -2308,10 +2320,10 @@ build_codex_mcp_block_fallback() {
BEGIN {
have_filter = (keys_csv != "")
if (have_filter) {
n = split(keys_csv, tmp, ",")
n = split(keys_csv, split_parts, ",")
for (i = 1; i <= n; i++) {
if (tmp[i] != "") {
keep[tmp[i]] = 1
if (split_parts[i] != "") {
keep[split_parts[i]] = 1
}
}
}
Expand All @@ -2326,6 +2338,15 @@ build_codex_mcp_block_fallback() {
gsub(/"/, "\\\"", s)
return s
}
function extract_json_val(line) {
sub(/^[^:]*:[[:space:]]*"/, "", line)
sub(/"[[:space:]]*,?[[:space:]]*$/, "", line)
return line
}
function extract_quoted(line) {
if (!match(line, /"[^"]*"/)) return ""
return substr(line, RSTART + 1, RLENGTH - 2)
}
function flush_args() {
if (skip || !in_args) return
printf "args = ["
Expand All @@ -2345,33 +2366,34 @@ build_codex_mcp_block_fallback() {
}
/^[[:space:]]*"mcpServers"[[:space:]]*:/ {
in_servers = 1
next
}
in_servers && match($0, /^[[:space:]]*"([^"]+)"[[:space:]]*:[[:space:]]*{/, m) {
current = m[1]
in_servers && /^[[:space:]]*"[^"]+"[[:space:]]*:[[:space:]]*{/ {
current = extract_quoted($0)
skip = (have_filter && !keep[current])
start_block(current)
next
}
current != "" {
if (match($0, /^[[:space:]]*"command"[[:space:]]*:[[:space:]]*"([^"]*)"/, m)) {
if (!skip) printf "command = \"%s\"\n", toml_escape(m[1])
if (/^[[:space:]]*"command"[[:space:]]*:[[:space:]]*"/) {
if (!skip) printf "command = \"%s\"\n", toml_escape(extract_json_val($0))
next
}
if (match($0, /^[[:space:]]*"type"[[:space:]]*:[[:space:]]*"([^"]*)"/, m)) {
if (!skip) printf "type = \"%s\"\n", toml_escape(m[1])
if (/^[[:space:]]*"type"[[:space:]]*:[[:space:]]*"/) {
if (!skip) printf "type = \"%s\"\n", toml_escape(extract_json_val($0))
next
}
if (match($0, /^[[:space:]]*"url"[[:space:]]*:[[:space:]]*"([^"]*)"/, m)) {
if (!skip) printf "url = \"%s\"\n", toml_escape(m[1])
if (/^[[:space:]]*"url"[[:space:]]*:[[:space:]]*"/) {
if (!skip) printf "url = \"%s\"\n", toml_escape(extract_json_val($0))
next
}
if (match($0, /^[[:space:]]*"args"[[:space:]]*:[[:space:]]*\[/)) {
if (/^[[:space:]]*"args"[[:space:]]*:[[:space:]]*\[/) {
in_args = 1
args_count = 0
if (match($0, /\[[^]]*]/)) {
tmp = $0
while (match(tmp, /"([^"]*)"/, m)) {
args[++args_count] = m[1]
tmp = substr($0, RSTART, RLENGTH)
while (match(tmp, /"[^"]*"/)) {
args[++args_count] = substr(tmp, RSTART + 1, RLENGTH - 2)
tmp = substr(tmp, RSTART + RLENGTH)
}
flush_args()
Expand All @@ -2380,8 +2402,8 @@ build_codex_mcp_block_fallback() {
}
if (in_args) {
tmp = $0
while (match(tmp, /"([^"]*)"/, m)) {
args[++args_count] = m[1]
while (match(tmp, /"[^"]*"/)) {
args[++args_count] = substr(tmp, RSTART + 1, RLENGTH - 2)
tmp = substr(tmp, RSTART + RLENGTH)
}
if (index($0, "]")) {
Expand Down