#!/usr/bin/env bash # Import (or upgrade in place) one tool package into a named database over MCP. # # scripts/dev/import-tool.sh --database # # A directory is packed first with scripts/pack-tool.mjs. The package goes to # import_tool, which upgrades a tool already installed under its id in place and # makes the package's pictures the tool's pictures (replace_pictures) — the only # way a picture's bytes reach a database, since update_definition only names a # photo the database already holds. The writer is the dev Cotton MCP client: # COTTON_MCP_URL/COTTON_MCP_TOKEN or the memory-mirror config. The token is # never printed. set -euo pipefail root="$(cd "$(dirname "$0")/../.." && pwd)" usage="usage: scripts/dev/import-tool.sh --database " source="${1:?$usage}" [ "${2:-}" = --database ] && [ -n "${3:-}" ] || { echo "$usage" >&2; exit 2; } database="$3" package="$source" if [ -d "$source" ]; then scratch="$(mktemp -d)" trap 'rm -rf "$scratch"' EXIT package="$scratch/$(basename "$source").cottontool" node "$root/scripts/pack-tool.mjs" "$source" "$package" >&2 fi python3 -I -c ' import base64, json, sys sys.path.insert(0, sys.argv[2]) from cotton_client import Client client = Client(sys.argv[3]) with open(sys.argv[1], "rb") as package: encoded = base64.b64encode(package.read()).decode() answer = client.call("import_tool", {"bytes": encoded, "database": client.database}) print(json.dumps({"imported": answer["tool_id"], "pictures": "replaced", "database": client.database})) ' "$package" "$root/scripts/dev" "$database"