feat(enable-mother): jq-merge the mother entry instead of overwriting

Track C's enable-mother overwrote external-mcp.json with a single mother
server. Use jq to merge the mother entry into the existing registry so other
configured servers are preserved, written atomically (mktemp in same dir + mv).
This is the concrete consumer that makes jq a real dependency of the MCP path;
fails loudly if jq is absent.

(Re-applied: the original commit was lost to a branch-recreation race when #97
merged at the packages-only commit.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Sam & Claude 2026-06-21 19:30:40 +02:00
parent f0c1b5ea37
commit c49fe82ea8

View file

@ -62,17 +62,26 @@ mdo -u root sh -c '
fi
' sh "$COLIBRI_HOME" "$SSH_KEY"
# 3. Write the mother entry into the external MCP registry.
# 3. Merge the mother entry into the external MCP registry. Use jq so existing
# server entries are preserved (not overwritten), and write atomically.
echo "[2/4] Registering mother in ${EXTERNAL_MCP}..."
printf '%s\n' "{
\"servers\": {
\"mother\": {
\"command\": \"ssh\",
\"args\": [\"-i\", \"${SSH_KEY}\", \"-o\", \"BatchMode=yes\", \"-o\", \"StrictHostKeyChecking=accept-new\", \"${MOTHER_HOST}\", \"${MOTHER_CMD}\"],
\"env\": {}
}
}
}" | mdo -u root sh -c 'cat > "$1"; chmod 0644 "$1"' sh "$EXTERNAL_MCP"
if ! have jq; then
echo " ERROR: jq is required to merge the mother entry into ${EXTERNAL_MCP}."
finish 1
fi
existing="$(mdo -u root cat "$EXTERNAL_MCP" 2>/dev/null || echo '{}')"
[ -n "$existing" ] || existing='{}'
printf '%s\n' "$existing" |
jq --arg host "$MOTHER_HOST" --arg cmd "$MOTHER_CMD" --arg key "$SSH_KEY" \
'.servers = ((.servers // {}) + {mother: {command: "ssh", args: ["-i", $key, "-o", "BatchMode=yes", "-o", "StrictHostKeyChecking=accept-new", $host, $cmd], env: {}}})' |
mdo -u root sh -c '
set -eu
f="$1"
tmp="$(mktemp "$(dirname "$f")/external-mcp.XXXXXX")"
cat >"$tmp"
chmod 0644 "$tmp"
mv "$tmp" "$f"
' sh "$EXTERNAL_MCP"
# 4. Allow external MCP calls: upsert COLIBRI_MCP_EXTERNAL_CALL=1 into provider.env.
echo "[3/4] Enabling external MCP calls..."