#!/bin/sh # quso.ai MCP setup # # curl -fsSL https://mcp.quso.ai/mcp/setup.sh | sh # # Adds the quso.ai MCP server to the AI apps it finds on this computer, and # installs the "quso" skill where an app loads skills. It shows what it will # do and asks first, changes only quso's own entries, and backs up any config # file before it edits it. Signing in happens in each app afterwards. # # Options (after `sh -s --` when piped, for example `| sh -s -- --dry-run`): # --dry-run show what would change, change nothing # --yes do not ask before changing # --only LIST only these apps, comma-separated: # claude-code,cursor,vscode,codex,gemini # --no-skill add the server only, not the skill # --remove remove quso's server entries and skill instead # --help show this help # # Environment (for testing against another server): # QUSO_MCP_URL default https://mcp.quso.ai/mcp # QUSO_SKILL_BASE default https://mcp.quso.ai/mcp/skill set -u QUSO_NAME="quso" QUSO_URL="${QUSO_MCP_URL:-https://mcp.quso.ai/mcp}" SKILL_BASE="${QUSO_SKILL_BASE:-https://mcp.quso.ai/mcp/skill}" # The skill's files, relative to its folder. Must match the server's list # (a test checks it). SKILL_FILES="SKILL.md reference/networks.md reference/recovery.md" ALL_APPS="claude-code cursor vscode codex gemini" DRY_RUN=0 ASSUME_YES=0 WITH_SKILL=1 REMOVE=0 ONLY="" say() { printf '%s\n' "$*"; } warn() { printf 'quso setup: %s\n' "$*" >&2; } usage() { cat <<'EOF' quso.ai MCP setup: adds https://mcp.quso.ai/mcp to the AI apps on this computer and installs the quso skill where an app loads skills. Options: --dry-run show what would change, change nothing --yes do not ask before changing --only LIST only these apps, comma-separated: claude-code,cursor,vscode,codex,gemini --no-skill add the server only, not the skill --remove remove quso's server entries and skill instead --help show this help Read the whole script at https://mcp.quso.ai/mcp/setup.sh EOF } while [ $# -gt 0 ]; do case "$1" in --dry-run) DRY_RUN=1 ;; --yes|-y) ASSUME_YES=1 ;; --no-skill) WITH_SKILL=0 ;; --remove) REMOVE=1 ;; --only) [ $# -ge 2 ] || { warn "--only needs a list"; exit 2; } ONLY=$(printf '%s' "$2" | tr ',' ' ') shift ;; --only=*) ONLY=$(printf '%s' "${1#--only=}" | tr ',' ' ') ;; --help|-h) usage; exit 0 ;; *) warn "unknown option: $1 (try --help)"; exit 2 ;; esac shift done for app in $ONLY; do case " $ALL_APPS " in *" $app "*) ;; *) warn "unknown app in --only: $app (one of: $ALL_APPS)"; exit 2 ;; esac done wanted() { [ -z "$ONLY" ] && return 0 case " $ONLY " in *" $1 "*) return 0 ;; esac return 1 } have() { command -v "$1" >/dev/null 2>&1; } OS=$(uname -s 2>/dev/null || echo unknown) case "$OS" in Darwin) APP_SUPPORT="$HOME/Library/Application Support" ;; *) APP_SUPPORT="${XDG_CONFIG_HOME:-$HOME/.config}" ;; esac VSCODE_USER_DIR="$APP_SUPPORT/Code/User" # GitHub Copilot's own user files (VS Code's Copilot agent and Copilot CLI). COPILOT_DIR="${COPILOT_HOME:-$HOME/.copilot}" # already FILE: true when FILE already names quso's server address. already() { [ -f "$1" ] && grep -q "$QUSO_URL" "$1" 2>/dev/null; } # --- JSON config files ------------------------------------------------------- # A JSON helper is needed only to merge into a config file that already has # other servers. Prefer python3, then node. On macOS, /usr/bin/python3 is a # stub that opens an installer when the developer tools are missing, so it # counts only when they are installed. JSON_TOOL="" if have python3; then if [ "$OS" != "Darwin" ] || [ "$(command -v python3)" != "/usr/bin/python3" ] \ || xcode-select -p >/dev/null 2>&1; then python3 -c 'import json' >/dev/null 2>&1 && JSON_TOOL=python3 fi fi if [ -z "$JSON_TOOL" ] && have node; then JSON_TOOL=node fi # json_edit FILE KEY ENTRY_JSON add|remove # Sets FILE's KEY.quso to ENTRY_JSON (add), or deletes it (remove), keeping # every other entry. Refuses a file that is not a JSON object. json_edit() { file=$1 key=$2 entry=$3 mode=$4 case "$JSON_TOOL" in python3) python3 - "$file" "$key" "$entry" "$mode" "$QUSO_NAME" <<'PY' import json, sys path, key, entry, mode, name = sys.argv[1:6] try: with open(path) as f: text = f.read() data = json.loads(text) if text.strip() else {} except FileNotFoundError: data = {} except ValueError: sys.exit(3) if not isinstance(data, dict): sys.exit(3) servers = data.get(key) if servers is None: servers = {} if not isinstance(servers, dict): sys.exit(3) if mode == "add": servers[name] = json.loads(entry) else: servers.pop(name, None) data[key] = servers with open(path, "w") as f: json.dump(data, f, indent=2) f.write("\n") PY ;; node) node -e ' const fs = require("fs"); const [path, key, entry, mode, name] = process.argv.slice(1); let data = {}; try { const text = fs.readFileSync(path, "utf8"); data = text.trim() ? JSON.parse(text) : {}; } catch (e) { if (e.code !== "ENOENT") process.exit(3); } if (data === null || typeof data !== "object" || Array.isArray(data)) process.exit(3); let servers = data[key] ?? {}; if (servers === null || typeof servers !== "object" || Array.isArray(servers)) process.exit(3); if (mode === "add") servers[name] = JSON.parse(entry); else delete servers[name]; data[key] = servers; fs.writeFileSync(path, JSON.stringify(data, null, 2) + "\n"); ' "$file" "$key" "$entry" "$mode" "$QUSO_NAME" ;; *) return 4 ;; esac } # configure_json APP FILE KEY ENTRY_JSON # Adds (or with --remove, deletes) quso in a JSON config file, with a backup. configure_json() { app=$1 file=$2 key=$3 entry=$4 if [ "$REMOVE" -eq 1 ]; then if [ ! -f "$file" ] || ! grep -q "\"$QUSO_NAME\"" "$file" 2>/dev/null; then say " $app: no quso entry in $file" return 0 fi action="remove quso from $file" else if [ -f "$file" ] && grep -q "$QUSO_URL" "$file" 2>/dev/null; then say " $app: already set up in $file" return 0 fi action="add quso to $file" fi if [ "$DRY_RUN" -eq 1 ]; then say " $app: would $action" return 0 fi mkdir -p "$(dirname "$file")" || return 1 if [ -s "$file" ]; then backup="$file.quso-backup-$(date +%Y%m%d%H%M%S)" cp "$file" "$backup" || return 1 else backup="" fi if [ ! -s "$file" ] && [ "$REMOVE" -eq 0 ]; then printf '{\n "%s": {\n "%s": %s\n }\n}\n' "$key" "$QUSO_NAME" "$entry" > "$file" || return 1 say " $app: added quso to $file" return 0 fi json_edit "$file" "$key" "$entry" "$( [ "$REMOVE" -eq 1 ] && echo remove || echo add )" rc=$? if [ $rc -eq 0 ]; then say " $app: $( [ "$REMOVE" -eq 1 ] && echo removed quso from || echo added quso to ) $file${backup:+ (backup: $backup)}" return 0 fi [ -n "$backup" ] && rm -f "$backup" if [ $rc -eq 4 ]; then warn "$app: $file has other servers and no python3 or node is here to merge safely. Add this under \"$key\" yourself: \"$QUSO_NAME\": $entry" else warn "$app: $file is not plain JSON, so it was left unchanged. Add this under \"$key\" yourself: \"$QUSO_NAME\": $entry" fi return 1 } # --- Each app ------------------------------------------------------------------ run() { # run DESCRIPTION CMD...: run a command, or print it with --dry-run. desc=$1 shift if [ "$DRY_RUN" -eq 1 ]; then say " would run: $*" return 0 fi if "$@" >/dev/null 2>&1; then say " $desc" return 0 fi warn "failed: $*" return 1 } setup_claude_code() { # User scope is stored in ~/.claude.json. if [ "$REMOVE" -eq 1 ]; then already "$HOME/.claude.json" || { say " claude-code: no quso server"; return 0; } run "claude-code: removed quso" claude mcp remove --scope user "$QUSO_NAME" return fi if already "$HOME/.claude.json"; then say " claude-code: already set up" return 0 fi run "claude-code: added quso" \ claude mcp add --transport http --scope user "$QUSO_NAME" "$QUSO_URL" } setup_cursor() { configure_json cursor "$HOME/.cursor/mcp.json" mcpServers \ "{\"url\": \"$QUSO_URL\"}" } setup_vscode() { # Copilot's portable user file, which VS Code's Copilot agent reads. (The # editor-managed mcp.json that `code --add-mcp` writes is being retired.) configure_json vscode "$COPILOT_DIR/mcp-config.json" mcpServers \ "{\"type\": \"http\", \"url\": \"$QUSO_URL\", \"tools\": [\"*\"]}" } setup_codex() { if [ "$REMOVE" -eq 1 ]; then already "$HOME/.codex/config.toml" || { say " codex: no quso server"; return 0; } run "codex: removed quso" codex mcp remove "$QUSO_NAME" return fi if already "$HOME/.codex/config.toml"; then say " codex: already set up" return 0 fi run "codex: added quso" codex mcp add "$QUSO_NAME" --url "$QUSO_URL" } setup_gemini() { if [ "$REMOVE" -eq 1 ]; then already "$HOME/.gemini/settings.json" || { say " gemini: no quso server"; return 0; } run "gemini: removed quso" gemini mcp remove --scope user "$QUSO_NAME" return fi if already "$HOME/.gemini/settings.json"; then say " gemini: already set up" return 0 fi run "gemini: added quso" \ gemini mcp add --transport http --scope user "$QUSO_NAME" "$QUSO_URL" } # --- Skill ----------------------------------------------------------------------- # install_skill APP DIR: put the skill's files in DIR (the app's skills # folder + /quso), or with --remove delete DIR. install_skill() { app=$1 dir=$2 if [ "$REMOVE" -eq 1 ]; then [ -f "$dir/SKILL.md" ] || { say " $app: no quso skill in $dir"; return 0; } if [ "$DRY_RUN" -eq 1 ]; then say " $app: would remove the skill $dir"; return 0; fi rm -rf "$dir" && say " $app: removed the skill $dir" return fi if [ "$DRY_RUN" -eq 1 ]; then say " $app: would install the quso skill in $dir" return 0 fi tmp=$(mktemp -d 2>/dev/null || mktemp -d -t quso) || return 1 for f in $SKILL_FILES; do mkdir -p "$tmp/$(dirname "$f")" || { rm -rf "$tmp"; return 1; } if ! curl -fsSL "$SKILL_BASE/$f" -o "$tmp/$f"; then warn "$app: could not download the skill file $f" rm -rf "$tmp" return 1 fi done head -n 1 "$tmp/SKILL.md" | grep -qx -- '---' || { warn "$app: the downloaded skill does not look right; nothing was installed" rm -rf "$tmp"; return 1; } if ! { mkdir -p "$(dirname "$dir")" && rm -rf "$dir" && mv "$tmp" "$dir"; }; then warn "$app: could not write the skill to $dir" rm -rf "$tmp" return 1 fi say " $app: installed the quso skill in $dir" } # --- Plan, ask, do ----------------------------------------------------------------- FOUND="" detect() { wanted claude-code && have claude && FOUND="$FOUND claude-code" wanted cursor && { [ -d "$HOME/.cursor" ] || have cursor; } && FOUND="$FOUND cursor" wanted vscode && { have code || [ -d "$VSCODE_USER_DIR" ] || [ -d "$COPILOT_DIR" ]; } && FOUND="$FOUND vscode" wanted codex && have codex && FOUND="$FOUND codex" wanted gemini && have gemini && FOUND="$FOUND gemini" return 0 } # Where each app loads personal skills. Codex, Cursor and Gemini CLI all # read the shared ~/.agents/skills, so one copy there serves the three. skill_dir_for() { case "$1" in claude-code) printf '%s' "$HOME/.claude/skills/$QUSO_NAME" ;; codex|cursor|gemini) printf '%s' "$HOME/.agents/skills/$QUSO_NAME" ;; vscode) printf '%s' "$COPILOT_DIR/skills/$QUSO_NAME" ;; *) printf '' ;; esac } detect say "quso.ai MCP setup" say "Server: $QUSO_URL" if [ -z "$FOUND" ]; then say "" say "No supported app was found on this computer${ONLY:+ (asked for: $ONLY)}." say "Claude (web, desktop, mobile) and ChatGPT are set up in the app itself:" say " https://mcp.quso.ai/mcp is the address to add as a custom connector." exit 0 fi say "" if [ "$REMOVE" -eq 1 ]; then say "This removes quso from:" else say "This sets up quso in:" fi for app in $FOUND; do sd=$(skill_dir_for "$app") if [ "$WITH_SKILL" -eq 1 ] && [ -n "$sd" ]; then say " $app (server and skill)" else say " $app (server)" fi done if [ "$DRY_RUN" -eq 0 ] && [ "$ASSUME_YES" -eq 0 ]; then if [ -r /dev/tty ] && (exec /dev/null; then printf 'Continue? [y/N] ' read -r answer \"" say "Connecting needs a paid quso.ai plan." exit $FAILED