Skip to content

MCP Servers

Every MCP server in your AI apps in one list: test one and see its tools, switch it off without deleting it, add from the MCP Registry, and see your skills. Mac only.

by TailApps · Version 1 · Updated 16 hours ago

Price
Free
Works on
Mac
Permissions
18

What it does

  • Lives where you glance

    Menu bar, TailApps Dock, Dashboard and a floating window on your Mac.

  • Stays up to date

    Runs its script stamp.sh on your Mac every 20 seconds

  • Stays up to date

    Runs its script skills.sh on your Mac every 2 minutes

  • Asks you to set up

    Claude Code (~/.claude.json), Claude Desktop, Cursor (~/.cursor/mcp.json), VS Code (User/mcp.json), Windsurf (mcp_config.json), Gemini CLI (~/.gemini/settings.json), Codex (~/.codex/config.toml), Claude Code skills folder, Codex skills folder

What it may do

TailApps shows this list before installing and asks you once. The card can do nothing else.

  • Run its script scan.sh

    script:scan.sh

  • Run its script codex.sh

    script:codex.sh

  • Run its script stamp.sh

    script:stamp.sh

  • Run its script test.sh

    script:test.sh

  • Run its script toggle.sh

    script:toggle.sh

  • Run its script install.sh

    script:install.sh

  • Run its script skills.sh

    script:skills.sh

  • Run its script skill-switch.sh

    script:skill-switch.sh

  • Connect to registry.modelcontextprotocol.io

    net:registry.modelcontextprotocol.io

  • Save into a folder you choose

    files.write:claude_code

  • Save into a folder you choose

    files.write:claude_desktop

  • Save into a folder you choose

    files.write:cursor

  • Save into a folder you choose

    files.write:vscode

  • Save into a folder you choose

    files.write:windsurf

  • Save into a folder you choose

    files.write:gemini

  • Save into a folder you choose

    files.write:codex

  • Save into a folder you choose

    files.write:claude_skills

  • Save into a folder you choose

    files.write:codex_skills

Scripts

Everything it runs is here to read before you install.

codex.sh
#!/bin/sh
# Args 1-9: the files and folders picked in the card's settings (empty when not picked). A picked one may be changed;
# otherwise the card reads where each AI app keeps it, and changes nothing there.
P_claude_code=$1 P_claude_desktop=$2 P_cursor=$3 P_vscode=$4 P_windsurf=$5 P_gemini=$6 P_codex=$7 P_claude_skills=$8 P_codex_skills=$9
shift 9
AS="$HOME/Library/Application Support"
APPS="claude_code claude_desktop cursor vscode windsurf gemini codex"
picked() {
  case "$1" in
    claude_code) printf '%s' "$P_claude_code" ;; claude_desktop) printf '%s' "$P_claude_desktop" ;; cursor) printf '%s' "$P_cursor" ;;
    vscode) printf '%s' "$P_vscode" ;; windsurf) printf '%s' "$P_windsurf" ;; gemini) printf '%s' "$P_gemini" ;; codex) printf '%s' "$P_codex" ;;
    claude_skills) printf '%s' "$P_claude_skills" ;; codex_skills) printf '%s' "$P_codex_skills" ;;
  esac
}
default_of() {
  case "$1" in
    claude_code) printf '%s' "$HOME/.claude.json" ;;
    claude_desktop) printf '%s' "$AS/Claude/claude_desktop_config.json" ;;
    cursor) printf '%s' "$HOME/.cursor/mcp.json" ;;
    vscode) printf '%s' "$AS/Code/User/mcp.json" ;;
    windsurf) printf '%s' "$HOME/.codeium/windsurf/mcp_config.json" ;;
    gemini) printf '%s' "$HOME/.gemini/settings.json" ;;
    codex) printf '%s' "$HOME/.codex/config.toml" ;;
    claude_skills) printf '%s' "$HOME/.claude/skills" ;;
    codex_skills) printf '%s' "$HOME/.codex/skills" ;;
  esac
}
file_of() { p=$(picked "$1"); [ -n "$p" ] && printf '%s' "$p" || default_of "$1"; }
name_of() {
  case "$1" in
    claude_code) echo "Claude Code" ;; claude_desktop) echo "Claude Desktop" ;; cursor) echo "Cursor" ;;
    vscode) echo "VS Code" ;; windsurf) echo "Windsurf" ;; gemini) echo "Gemini CLI" ;; codex) echo "Codex" ;;
  esac
}
# Where an app keeps its servers inside its JSON file, as a jq path.
base_of() {
  case "$1" in
    claude_code) case "$2" in local:*) jq -cn --arg p "${2#local:}" '["projects", $p, "mcpServers"]' ;; *) echo '["mcpServers"]' ;; esac ;;
    vscode) echo '["servers"]' ;;
    *) echo '["mcpServers"]' ;;
  esac
}
fail() { printf '%s\n' "$*" >&2; exit 1; }
# The card's own folder (tmp/<card>/): switched-off servers and backups live here, never in the card's state.
OWN=$(dirname "${TMPDIR%/}")
PARKED="$OWN/parked.json"
[ -f "$PARKED" ] || { umask 077; echo '[]' > "$PARKED"; }
# A file may only be changed when the person picked it in settings.
writable_of() {
  p=$(picked "$1")
  [ -n "$p" ] || fail "To change $(name_of "$1")'s servers, choose its file in this card's settings (the gear): $(default_of "$1" | sed "s|^$HOME|~|")"
  [ -f "$p" ] || fail "$(name_of "$1")'s file isn't there any more: $p"
  printf '%s' "$p"
}
# A copy of the file before each change, the newest 30 kept.
backup() {
  mkdir -p "$OWN/backups" && chmod 700 "$OWN/backups"
  b="$OWN/backups/$2-$(date +%Y%m%d-%H%M%S)-$$.bak"
  cp -p "$1" "$b" || fail "Couldn't back up $1"
  ls -t "$OWN/backups"/*.bak 2>/dev/null | tail -n +31 | while IFS= read -r old; do rm -f "$old"; done
}
# The file's modification time and size, taken before reading it (seen) and checked again just before writing
# (unchanged), so a change the AI app made meanwhile isn't written over.
stamp_of() { stat -c '%.9Y %s' "$1" 2>/dev/null || stat -f '%Fm %z' "$1" 2>/dev/null; }
seen() { SEEN=$(stamp_of "$1"); }
unchanged() { [ -z "$SEEN" ] || [ "$(stamp_of "$1")" = "$SEEN" ]; }
# Write new text over a file in place (keeps its permissions; the sandbox allows only the picked file itself).
replace() {
  [ -s "$2" ] || fail "Nothing to write"
  unchanged "$1" || fail "$1 changed while this ran, so nothing was written. Try again"
  cat "$2" > "$1" || fail "Couldn't write $1"
}

# Codex's config.toml as text, for parse:'toml' (only inside the scan action, never kept in the card's state).
f=$(file_of codex)
[ -f "$f" ] && cat "$f"
exit 0
install.sh
#!/bin/sh
# Args 1-9: the files and folders picked in the card's settings (empty when not picked). A picked one may be changed;
# otherwise the card reads where each AI app keeps it, and changes nothing there.
P_claude_code=$1 P_claude_desktop=$2 P_cursor=$3 P_vscode=$4 P_windsurf=$5 P_gemini=$6 P_codex=$7 P_claude_skills=$8 P_codex_skills=$9
shift 9
AS="$HOME/Library/Application Support"
APPS="claude_code claude_desktop cursor vscode windsurf gemini codex"
picked() {
  case "$1" in
    claude_code) printf '%s' "$P_claude_code" ;; claude_desktop) printf '%s' "$P_claude_desktop" ;; cursor) printf '%s' "$P_cursor" ;;
    vscode) printf '%s' "$P_vscode" ;; windsurf) printf '%s' "$P_windsurf" ;; gemini) printf '%s' "$P_gemini" ;; codex) printf '%s' "$P_codex" ;;
    claude_skills) printf '%s' "$P_claude_skills" ;; codex_skills) printf '%s' "$P_codex_skills" ;;
  esac
}
default_of() {
  case "$1" in
    claude_code) printf '%s' "$HOME/.claude.json" ;;
    claude_desktop) printf '%s' "$AS/Claude/claude_desktop_config.json" ;;
    cursor) printf '%s' "$HOME/.cursor/mcp.json" ;;
    vscode) printf '%s' "$AS/Code/User/mcp.json" ;;
    windsurf) printf '%s' "$HOME/.codeium/windsurf/mcp_config.json" ;;
    gemini) printf '%s' "$HOME/.gemini/settings.json" ;;
    codex) printf '%s' "$HOME/.codex/config.toml" ;;
    claude_skills) printf '%s' "$HOME/.claude/skills" ;;
    codex_skills) printf '%s' "$HOME/.codex/skills" ;;
  esac
}
file_of() { p=$(picked "$1"); [ -n "$p" ] && printf '%s' "$p" || default_of "$1"; }
name_of() {
  case "$1" in
    claude_code) echo "Claude Code" ;; claude_desktop) echo "Claude Desktop" ;; cursor) echo "Cursor" ;;
    vscode) echo "VS Code" ;; windsurf) echo "Windsurf" ;; gemini) echo "Gemini CLI" ;; codex) echo "Codex" ;;
  esac
}
# Where an app keeps its servers inside its JSON file, as a jq path.
base_of() {
  case "$1" in
    claude_code) case "$2" in local:*) jq -cn --arg p "${2#local:}" '["projects", $p, "mcpServers"]' ;; *) echo '["mcpServers"]' ;; esac ;;
    vscode) echo '["servers"]' ;;
    *) echo '["mcpServers"]' ;;
  esac
}
fail() { printf '%s\n' "$*" >&2; exit 1; }
# The card's own folder (tmp/<card>/): switched-off servers and backups live here, never in the card's state.
OWN=$(dirname "${TMPDIR%/}")
PARKED="$OWN/parked.json"
[ -f "$PARKED" ] || { umask 077; echo '[]' > "$PARKED"; }
# A file may only be changed when the person picked it in settings.
writable_of() {
  p=$(picked "$1")
  [ -n "$p" ] || fail "To change $(name_of "$1")'s servers, choose its file in this card's settings (the gear): $(default_of "$1" | sed "s|^$HOME|~|")"
  [ -f "$p" ] || fail "$(name_of "$1")'s file isn't there any more: $p"
  printf '%s' "$p"
}
# A copy of the file before each change, the newest 30 kept.
backup() {
  mkdir -p "$OWN/backups" && chmod 700 "$OWN/backups"
  b="$OWN/backups/$2-$(date +%Y%m%d-%H%M%S)-$$.bak"
  cp -p "$1" "$b" || fail "Couldn't back up $1"
  ls -t "$OWN/backups"/*.bak 2>/dev/null | tail -n +31 | while IFS= read -r old; do rm -f "$old"; done
}
# The file's modification time and size, taken before reading it (seen) and checked again just before writing
# (unchanged), so a change the AI app made meanwhile isn't written over.
stamp_of() { stat -c '%.9Y %s' "$1" 2>/dev/null || stat -f '%Fm %z' "$1" 2>/dev/null; }
seen() { SEEN=$(stamp_of "$1"); }
unchanged() { [ -z "$SEEN" ] || [ "$(stamp_of "$1")" = "$SEEN" ]; }
# Write new text over a file in place (keeps its permissions; the sandbox allows only the picked file itself).
replace() {
  [ -s "$2" ] || fail "Nothing to write"
  unchanged "$1" || fail "$1 changed while this ran, so nothing was written. Try again"
  cat "$2" > "$1" || fail "Couldn't write $1"
}

# Add a server from the MCP Registry to the chosen AI apps, each in its own format, after a backup of each file.
# Args: the registry's server object, the app ids as a JSON list, and the keys the person typed when asked
# ("NAME=value", separated by new lines or "; "; "header NAME=value" for a hosted server's headers). Prints { installed: [app names], skipped: [{ app, why }] }.
server=$1 targets=${2:-"[]"} typed=$3
[ -n "$server" ] && [ "$server" != null ] || fail "Pick a server first"
[ "$(printf '%s' "$targets" | jq 'length')" -gt 0 ] || fail "Tick at least one app to add it to"
name=$(printf '%s' "$server" | jq -r '.name | split("/") | last | gsub("[^A-Za-z0-9_-]"; "-")')
# What runs: the first package we know how to start, else the first hosted address.
spec=$(printf '%s' "$typed" | jq -Rs --argjson s "$server" '
  ([splits("\n|;\\s*(?=(header\\s+)?[A-Za-z_][A-Za-z0-9_-]*\\s*=)")] | map(sub("\r$"; "") | sub("^\\s+"; "") | select(test("^(#|$)") | not))) as $lines
  | ([$lines[] | select(startswith("header ") | not) | capture("^\\s*(?<k>[A-Za-z_][A-Za-z0-9_]*)\\s*=(?<v>.*)$")] | map({ (.k): (.v | sub("^\\s+"; "")) }) | add // {} | with_entries(select(.value != ""))) as $env
  | ([$lines[] | select(startswith("header ")) | sub("^header "; "") | capture("^\\s*(?<k>[A-Za-z0-9-]+)\\s*=(?<v>.*)$")] | map({ (.k): (.v | sub("^\\s+"; "")) }) | add // {} | with_entries(select(.value != ""))) as $headers
  | ([$s.packages[]? | select((.transport.type // "stdio") == "stdio" and (.registryType == "npm" or .registryType == "pypi" or .registryType == "oci"))] | .[0]) as $p
  | ($s.remotes // [] | .[0]) as $r
  | if $p then
      ([$p.environmentVariables[]? | select(.isRequired == true and ($env[.name] // "") == "") | .name]) as $missing
      | ([$p.packageArguments[]? | select(.value != null) | if .type == "named" then .name, .value else .value end | tostring]) as $extra
      | (if ($p.version // "") == "" then $p.identifier elif $p.registryType == "pypi" then "\($p.identifier)==\($p.version)"
         elif $p.registryType == "npm" then "\($p.identifier)@\($p.version)"
         elif ($p.identifier | contains(":")) then $p.identifier else "\($p.identifier):\($p.version)" end) as $id
      | { kind: "stdio", missing: $missing, env: $env,
          command: ({ npm: "npx", pypi: "uvx", oci: "docker" }[$p.registryType]),
          args: ((if $p.registryType == "npm" then ["-y", $id] elif $p.registryType == "pypi" then [$id]
                  else ["run", "-i", "--rm"] + [$env | keys[] | "-e", .] + [$id] end) + $extra) }
    elif $r then
      ([$r.headers[]? | select(.isRequired == true and ($headers[.name] // "") == "") | .name]) as $missing
      | { kind: (if $r.type == "sse" then "sse" else "http" end), url: $r.url, headers: $headers, missing: $missing }
    else { error: "It has nothing this card can install (no npm, PyPI or Docker package, and no hosted address)" } end') || fail "Couldn't read that server's details"
[ -n "$spec" ] || fail "Couldn't read that server's details"
e=$(printf '%s' "$spec" | jq -r '.error // empty'); [ -z "$e" ] || fail "$e"
missing=$(printf '%s' "$spec" | jq -r '.missing | join(", ")')
[ -z "$missing" ] || fail "Fill in $missing first"
# The entry each app expects.
entry_for() {
  printf '%s' "$spec" | jq -c --arg app "$1" '
    def drop_empty: with_entries(select(.value != null and .value != {} and .value != []));
    if .kind == "stdio" then
      (if ($app == "claude_code" or $app == "vscode") then { type: "stdio" } else {} end) + { command, args, env } | drop_empty
    elif $app == "claude_desktop" then
      { command: "npx", args: (["-y", "mcp-remote", .url] + ([.headers | to_entries[] | "--header", "\(.key):\(.value)"])) }
    elif $app == "windsurf" then { serverUrl: .url, headers } | drop_empty
    elif $app == "gemini" then (if .kind == "sse" then { url, headers } else { httpUrl: .url, headers } end) | drop_empty
    elif $app == "cursor" then { url, headers } | drop_empty
    else { type: .kind, url, headers } | drop_empty end'
}
toml_for() {
  printf '%s' "$spec" | jq -r --arg n "$name" '
    def kv: to_entries | map("\(.key | tojson) = \(.value | tojson)") | join(", ");
    "[mcp_servers.\($n)]\n" + (if .kind == "stdio"
      then "command = \(.command | tojson)\nargs = \(.args | tojson)\n" + (if (.env | length) > 0 then "env = { \(.env | kv) }\n" else "" end)
      else "url = \(.url | tojson)\n" + (if (.headers | length) > 0 then "http_headers = { \(.headers | kv) }\n" else "" end) end)'
}
done_list="$TMPDIR/done"; skip_list="$TMPDIR/skip"; : > "$done_list"; : > "$skip_list"
skip() { jq -cn --arg app "$(name_of "$1")" --arg why "$2" '{ app: $app, why: $why }' >> "$skip_list"; }
for a in $(printf '%s' "$targets" | jq -r '.[]'); do
  n=$(name_of "$a"); [ -n "$n" ] || continue
  f=$(picked "$a")
  if [ -z "$f" ]; then skip "$a" "Choose its file in this card's settings first"; continue; fi
  if [ ! -f "$f" ]; then skip "$a" "Its file isn't there"; continue; fi
  seen "$f"
  new="$TMPDIR/new-$a"
  if [ "$a" = codex ]; then
    if [ "$(printf '%s' "$spec" | jq -r .kind)" = sse ]; then skip "$a" "Codex doesn't take the older SSE kind"; continue; fi
    if grep -Eq "^[[:space:]]*\[mcp_servers\.\"?$name\"?\]" "$f"; then skip "$a" "It already has a server named $name"; continue; fi
    { cat "$f"; [ -n "$(tail -c 1 "$f")" ] && echo; echo; toml_for; } > "$new"
  else
    base=$(base_of "$a" user)
    if ! jq -e . "$f" > /dev/null 2>&1; then skip "$a" "Its file has comments or isn't plain JSON"; continue; fi
    if [ "$(jq --argjson b "$base" --arg n "$name" 'getpath($b + [$n]) != null' "$f")" = true ]; then skip "$a" "It already has a server named $name"; continue; fi
    jq --argjson b "$base" --arg n "$name" --argjson e "$(entry_for "$a")" 'setpath($b + [$n]; $e)' "$f" > "$new" || { skip "$a" "Couldn't change its file"; continue; }
  fi
  unchanged "$f" || { skip "$a" "Its file changed meanwhile. Try again"; continue; }
  backup "$f" "$a"
  replace "$f" "$new"
  printf '%s\n' "$n" | jq -R . >> "$done_list"
done
jq -n --arg name "$name" --slurpfile d "$done_list" --slurpfile s "$skip_list" '{ name: $name, installed: $d, skipped: $s }'
scan.sh
#!/bin/sh
# Args 1-9: the files and folders picked in the card's settings (empty when not picked). A picked one may be changed;
# otherwise the card reads where each AI app keeps it, and changes nothing there.
P_claude_code=$1 P_claude_desktop=$2 P_cursor=$3 P_vscode=$4 P_windsurf=$5 P_gemini=$6 P_codex=$7 P_claude_skills=$8 P_codex_skills=$9
shift 9
AS="$HOME/Library/Application Support"
APPS="claude_code claude_desktop cursor vscode windsurf gemini codex"
picked() {
  case "$1" in
    claude_code) printf '%s' "$P_claude_code" ;; claude_desktop) printf '%s' "$P_claude_desktop" ;; cursor) printf '%s' "$P_cursor" ;;
    vscode) printf '%s' "$P_vscode" ;; windsurf) printf '%s' "$P_windsurf" ;; gemini) printf '%s' "$P_gemini" ;; codex) printf '%s' "$P_codex" ;;
    claude_skills) printf '%s' "$P_claude_skills" ;; codex_skills) printf '%s' "$P_codex_skills" ;;
  esac
}
default_of() {
  case "$1" in
    claude_code) printf '%s' "$HOME/.claude.json" ;;
    claude_desktop) printf '%s' "$AS/Claude/claude_desktop_config.json" ;;
    cursor) printf '%s' "$HOME/.cursor/mcp.json" ;;
    vscode) printf '%s' "$AS/Code/User/mcp.json" ;;
    windsurf) printf '%s' "$HOME/.codeium/windsurf/mcp_config.json" ;;
    gemini) printf '%s' "$HOME/.gemini/settings.json" ;;
    codex) printf '%s' "$HOME/.codex/config.toml" ;;
    claude_skills) printf '%s' "$HOME/.claude/skills" ;;
    codex_skills) printf '%s' "$HOME/.codex/skills" ;;
  esac
}
file_of() { p=$(picked "$1"); [ -n "$p" ] && printf '%s' "$p" || default_of "$1"; }
name_of() {
  case "$1" in
    claude_code) echo "Claude Code" ;; claude_desktop) echo "Claude Desktop" ;; cursor) echo "Cursor" ;;
    vscode) echo "VS Code" ;; windsurf) echo "Windsurf" ;; gemini) echo "Gemini CLI" ;; codex) echo "Codex" ;;
  esac
}
# Where an app keeps its servers inside its JSON file, as a jq path.
base_of() {
  case "$1" in
    claude_code) case "$2" in local:*) jq -cn --arg p "${2#local:}" '["projects", $p, "mcpServers"]' ;; *) echo '["mcpServers"]' ;; esac ;;
    vscode) echo '["servers"]' ;;
    *) echo '["mcpServers"]' ;;
  esac
}
fail() { printf '%s\n' "$*" >&2; exit 1; }
# The card's own folder (tmp/<card>/): switched-off servers and backups live here, never in the card's state.
OWN=$(dirname "${TMPDIR%/}")
PARKED="$OWN/parked.json"
[ -f "$PARKED" ] || { umask 077; echo '[]' > "$PARKED"; }
# A file may only be changed when the person picked it in settings.
writable_of() {
  p=$(picked "$1")
  [ -n "$p" ] || fail "To change $(name_of "$1")'s servers, choose its file in this card's settings (the gear): $(default_of "$1" | sed "s|^$HOME|~|")"
  [ -f "$p" ] || fail "$(name_of "$1")'s file isn't there any more: $p"
  printf '%s' "$p"
}
# A copy of the file before each change, the newest 30 kept.
backup() {
  mkdir -p "$OWN/backups" && chmod 700 "$OWN/backups"
  b="$OWN/backups/$2-$(date +%Y%m%d-%H%M%S)-$$.bak"
  cp -p "$1" "$b" || fail "Couldn't back up $1"
  ls -t "$OWN/backups"/*.bak 2>/dev/null | tail -n +31 | while IFS= read -r old; do rm -f "$old"; done
}
# The file's modification time and size, taken before reading it (seen) and checked again just before writing
# (unchanged), so a change the AI app made meanwhile isn't written over.
stamp_of() { stat -c '%.9Y %s' "$1" 2>/dev/null || stat -f '%Fm %z' "$1" 2>/dev/null; }
seen() { SEEN=$(stamp_of "$1"); }
unchanged() { [ -z "$SEEN" ] || [ "$(stamp_of "$1")" = "$SEEN" ]; }
# Write new text over a file in place (keeps its permissions; the sandbox allows only the picked file itself).
replace() {
  [ -s "$2" ] || fail "Nothing to write"
  unchanged "$1" || fail "$1 changed while this ran, so nothing was written. Try again"
  cat "$2" > "$1" || fail "Couldn't write $1"
}

# Every MCP server in the AI apps' config files, as { apps, servers, names }. Values of env vars and headers never
# leave this script (only their names), and arguments or URLs that look like keys are masked.
# Arg 1: Codex's [mcp_servers] tables, as JSON (the card reads config.toml with parse:'toml').
codex=${1:-null}
[ "$codex" = "" ] && codex=null
out="$TMPDIR/servers.jsonl"
apps="$TMPDIR/apps.jsonl"
: > "$out"; : > "$apps"
NORM='
def mask_url: if . == null then null else
  sub("://[^/@\\s]+@"; "://•••@") | sub("(?<p>[?&][^=&]*(key|token|secret|auth)[^=&]*=)[^&]*"; "\(.p)•••"; "gi") end;
def mask_args: . as $a | [range(length) as $i | ($a[$i] | tostring) as $x | ($i > 0 and true | if . then ($a[$i-1] | tostring) else "" end) as $prev
  | if ($prev | test("^(-H|--header|--headers)$")) then (if ($x | test(":")) then ($x | sub(":.*$"; ": •••")) else "•••" end)
    elif ($prev | test("(?i)^-{1,2}[a-z_-]*(key|token|secret|password|auth)")) then "•••"
    elif ($x | test("^[A-Za-z][A-Za-z0-9+.-]*://")) then ($x | mask_url)
    elif ($x | test("(?i)bearer\\s")) then ($x | sub("(?i)(?<b>bearer)\\s.*$"; "\(.b) •••"))
    elif ($x | test("(?i)(key|token|secret|password)[^=]*=")) then ($x | sub("=.*$"; "=•••"))
    elif ($x | test("^(sk|ghp|gho|ghs|github_pat|xox[a-z]|pk|rk)[-_][A-Za-z0-9_-]{12,}")) then "•••"
    else ($x | mask_url) end];
def one($app; $appname; $scope; $label):
  if type != "object" then empty else to_entries[] | select(.value | type == "object") | .value as $v | ($v.url // $v.serverUrl // $v.httpUrl) as $url | {
    id: ($app + ":" + $scope + ":" + .key), name: .key, app: $app, app_name: $appname, scope: $scope, scope_label: $label,
    kind: (if $url then (if ($v.type == "sse" or $v.transport == "sse") then "sse" else "http" end) else "stdio" end),
    command: ($v.command // null), args: (($v.args // []) | if type == "array" then mask_args else [] end), url: ($url | mask_url),
    env: (($v.env // {}) | if type == "object" then keys else [] end),
    headers: (($v.headers // $v.http_headers // {}) | if type == "object" then keys else [] end),
    on: ($v.disabled != true and $v.enabled != false)
  } | .summary = (if .kind == "stdio" then ([.command // ""] + .args | join(" ")) else .url end)
  end;'
for a in $APPS; do
  f=$(file_of "$a"); p=$(picked "$a"); n=$(name_of "$a")
  err=""
  if [ ! -f "$f" ]; then found=false
  elif [ "$a" = codex ]; then
    found=true
    [ "$codex" = null ] && grep -q '^[[:space:]]*\[mcp_servers' "$f" && err="Its config.toml couldn't be read as TOML"
    printf '%s' "$codex" | jq -c --arg app "$a" --arg appname "$n" "$NORM one(\$app; \$appname; \"user\"; \"User\")" >> "$out" 2>/dev/null
  else
    found=true
    if ! jq -c --arg app "$a" --arg appname "$n" "$NORM"'
      if $app == "claude_code" then
        ((.mcpServers // {}) | one($app; $appname; "user"; "User")),
        ((.projects // {}) | to_entries[] | .key as $p | (.value.mcpServers // {}) | one($app; $appname; "local:" + $p; ($p | split("/") | last)))
      elif $app == "vscode" then (.servers // {}) | one($app; $appname; "user"; "User")
      else (.mcpServers // {}) | one($app; $appname; "user"; "User") end' "$f" >> "$out" 2>/dev/null; then
      err="Has comments or isn't plain JSON, so it's shown as empty and left alone"
    fi
  fi
  jq -cn --arg id "$a" --arg name "$n" --arg path "$(printf '%s' "$f" | sed "s|^$HOME|~|")" --argjson found "$found" \
    --argjson picked "$([ -n "$p" ] && echo true || echo false)" --arg error "$err" \
    '{ id: $id, name: $name, path: $path, found: $found, picked: $picked, error: (if $error == "" then null else $error end) }' >> "$apps"
done
# Servers switched off here: kept in the card's own folder, shown with on: false.
jq -c '.[] | .info + { on: false, parked: true }' "$PARKED" >> "$out" 2>/dev/null
jq -n --slurpfile s "$out" --slurpfile a "$apps" '
  ($s | sort_by(.name | ascii_downcase)) as $servers
  | { servers: $servers,
      apps: ($a | map(.id as $id | . + { count: ([$servers[] | select(.app == $id)] | length) })),
      names: ($servers | group_by(.name | ascii_downcase) | map({
        name: .[0].name, kind: .[0].kind, summary: .[0].summary,
        apps: (map(.app_name) | unique), on: (map(select(.on)) | length), total: length })) }'
skill-switch.sh
#!/bin/sh
# Args 1-9: the files and folders picked in the card's settings (empty when not picked). A picked one may be changed;
# otherwise the card reads where each AI app keeps it, and changes nothing there.
P_claude_code=$1 P_claude_desktop=$2 P_cursor=$3 P_vscode=$4 P_windsurf=$5 P_gemini=$6 P_codex=$7 P_claude_skills=$8 P_codex_skills=$9
shift 9
AS="$HOME/Library/Application Support"
APPS="claude_code claude_desktop cursor vscode windsurf gemini codex"
picked() {
  case "$1" in
    claude_code) printf '%s' "$P_claude_code" ;; claude_desktop) printf '%s' "$P_claude_desktop" ;; cursor) printf '%s' "$P_cursor" ;;
    vscode) printf '%s' "$P_vscode" ;; windsurf) printf '%s' "$P_windsurf" ;; gemini) printf '%s' "$P_gemini" ;; codex) printf '%s' "$P_codex" ;;
    claude_skills) printf '%s' "$P_claude_skills" ;; codex_skills) printf '%s' "$P_codex_skills" ;;
  esac
}
default_of() {
  case "$1" in
    claude_code) printf '%s' "$HOME/.claude.json" ;;
    claude_desktop) printf '%s' "$AS/Claude/claude_desktop_config.json" ;;
    cursor) printf '%s' "$HOME/.cursor/mcp.json" ;;
    vscode) printf '%s' "$AS/Code/User/mcp.json" ;;
    windsurf) printf '%s' "$HOME/.codeium/windsurf/mcp_config.json" ;;
    gemini) printf '%s' "$HOME/.gemini/settings.json" ;;
    codex) printf '%s' "$HOME/.codex/config.toml" ;;
    claude_skills) printf '%s' "$HOME/.claude/skills" ;;
    codex_skills) printf '%s' "$HOME/.codex/skills" ;;
  esac
}
file_of() { p=$(picked "$1"); [ -n "$p" ] && printf '%s' "$p" || default_of "$1"; }
name_of() {
  case "$1" in
    claude_code) echo "Claude Code" ;; claude_desktop) echo "Claude Desktop" ;; cursor) echo "Cursor" ;;
    vscode) echo "VS Code" ;; windsurf) echo "Windsurf" ;; gemini) echo "Gemini CLI" ;; codex) echo "Codex" ;;
  esac
}
# Where an app keeps its servers inside its JSON file, as a jq path.
base_of() {
  case "$1" in
    claude_code) case "$2" in local:*) jq -cn --arg p "${2#local:}" '["projects", $p, "mcpServers"]' ;; *) echo '["mcpServers"]' ;; esac ;;
    vscode) echo '["servers"]' ;;
    *) echo '["mcpServers"]' ;;
  esac
}
fail() { printf '%s\n' "$*" >&2; exit 1; }
# The card's own folder (tmp/<card>/): switched-off servers and backups live here, never in the card's state.
OWN=$(dirname "${TMPDIR%/}")
PARKED="$OWN/parked.json"
[ -f "$PARKED" ] || { umask 077; echo '[]' > "$PARKED"; }
# A file may only be changed when the person picked it in settings.
writable_of() {
  p=$(picked "$1")
  [ -n "$p" ] || fail "To change $(name_of "$1")'s servers, choose its file in this card's settings (the gear): $(default_of "$1" | sed "s|^$HOME|~|")"
  [ -f "$p" ] || fail "$(name_of "$1")'s file isn't there any more: $p"
  printf '%s' "$p"
}
# A copy of the file before each change, the newest 30 kept.
backup() {
  mkdir -p "$OWN/backups" && chmod 700 "$OWN/backups"
  b="$OWN/backups/$2-$(date +%Y%m%d-%H%M%S)-$$.bak"
  cp -p "$1" "$b" || fail "Couldn't back up $1"
  ls -t "$OWN/backups"/*.bak 2>/dev/null | tail -n +31 | while IFS= read -r old; do rm -f "$old"; done
}
# The file's modification time and size, taken before reading it (seen) and checked again just before writing
# (unchanged), so a change the AI app made meanwhile isn't written over.
stamp_of() { stat -c '%.9Y %s' "$1" 2>/dev/null || stat -f '%Fm %z' "$1" 2>/dev/null; }
seen() { SEEN=$(stamp_of "$1"); }
unchanged() { [ -z "$SEEN" ] || [ "$(stamp_of "$1")" = "$SEEN" ]; }
# Write new text over a file in place (keeps its permissions; the sandbox allows only the picked file itself).
replace() {
  [ -s "$2" ] || fail "Nothing to write"
  unchanged "$1" || fail "$1 changed while this ran, so nothing was written. Try again"
  cat "$2" > "$1" || fail "Couldn't write $1"
}

# Switch a skill off (SKILL.md → SKILL.md.off, so no agent loads it) or back on. Only inside a skills folder picked
# in the card's settings. Args: the skill's folder, true|false.
dir=${1%/} on=$2
ok=false
for kind in claude_skills codex_skills; do
  root=$(picked "$kind"); root=${root%/}
  [ -n "$root" ] && [ "$(dirname "$dir")" = "$root" ] && ok=true
done
[ "$ok" = true ] || fail "To switch skills, choose the skills folder in this card's settings (the gear)"
if [ "$on" = false ]; then
  [ -f "$dir/SKILL.md" ] || fail "There's no SKILL.md in $dir"
  [ ! -e "$dir/SKILL.md.off" ] || fail "$dir already has a SKILL.md.off"
  mv "$dir/SKILL.md" "$dir/SKILL.md.off" || fail "Couldn't switch it off"
else
  [ -f "$dir/SKILL.md.off" ] || fail "It isn't switched off"
  [ ! -e "$dir/SKILL.md" ] || fail "$dir already has a SKILL.md"
  mv "$dir/SKILL.md.off" "$dir/SKILL.md" || fail "Couldn't switch it on"
fi
echo '{"ok":true}'
skills.sh
#!/bin/sh
# Args 1-9: the files and folders picked in the card's settings (empty when not picked). A picked one may be changed;
# otherwise the card reads where each AI app keeps it, and changes nothing there.
P_claude_code=$1 P_claude_desktop=$2 P_cursor=$3 P_vscode=$4 P_windsurf=$5 P_gemini=$6 P_codex=$7 P_claude_skills=$8 P_codex_skills=$9
shift 9
AS="$HOME/Library/Application Support"
APPS="claude_code claude_desktop cursor vscode windsurf gemini codex"
picked() {
  case "$1" in
    claude_code) printf '%s' "$P_claude_code" ;; claude_desktop) printf '%s' "$P_claude_desktop" ;; cursor) printf '%s' "$P_cursor" ;;
    vscode) printf '%s' "$P_vscode" ;; windsurf) printf '%s' "$P_windsurf" ;; gemini) printf '%s' "$P_gemini" ;; codex) printf '%s' "$P_codex" ;;
    claude_skills) printf '%s' "$P_claude_skills" ;; codex_skills) printf '%s' "$P_codex_skills" ;;
  esac
}
default_of() {
  case "$1" in
    claude_code) printf '%s' "$HOME/.claude.json" ;;
    claude_desktop) printf '%s' "$AS/Claude/claude_desktop_config.json" ;;
    cursor) printf '%s' "$HOME/.cursor/mcp.json" ;;
    vscode) printf '%s' "$AS/Code/User/mcp.json" ;;
    windsurf) printf '%s' "$HOME/.codeium/windsurf/mcp_config.json" ;;
    gemini) printf '%s' "$HOME/.gemini/settings.json" ;;
    codex) printf '%s' "$HOME/.codex/config.toml" ;;
    claude_skills) printf '%s' "$HOME/.claude/skills" ;;
    codex_skills) printf '%s' "$HOME/.codex/skills" ;;
  esac
}
file_of() { p=$(picked "$1"); [ -n "$p" ] && printf '%s' "$p" || default_of "$1"; }
name_of() {
  case "$1" in
    claude_code) echo "Claude Code" ;; claude_desktop) echo "Claude Desktop" ;; cursor) echo "Cursor" ;;
    vscode) echo "VS Code" ;; windsurf) echo "Windsurf" ;; gemini) echo "Gemini CLI" ;; codex) echo "Codex" ;;
  esac
}
# Where an app keeps its servers inside its JSON file, as a jq path.
base_of() {
  case "$1" in
    claude_code) case "$2" in local:*) jq -cn --arg p "${2#local:}" '["projects", $p, "mcpServers"]' ;; *) echo '["mcpServers"]' ;; esac ;;
    vscode) echo '["servers"]' ;;
    *) echo '["mcpServers"]' ;;
  esac
}
fail() { printf '%s\n' "$*" >&2; exit 1; }
# The card's own folder (tmp/<card>/): switched-off servers and backups live here, never in the card's state.
OWN=$(dirname "${TMPDIR%/}")
PARKED="$OWN/parked.json"
[ -f "$PARKED" ] || { umask 077; echo '[]' > "$PARKED"; }
# A file may only be changed when the person picked it in settings.
writable_of() {
  p=$(picked "$1")
  [ -n "$p" ] || fail "To change $(name_of "$1")'s servers, choose its file in this card's settings (the gear): $(default_of "$1" | sed "s|^$HOME|~|")"
  [ -f "$p" ] || fail "$(name_of "$1")'s file isn't there any more: $p"
  printf '%s' "$p"
}
# A copy of the file before each change, the newest 30 kept.
backup() {
  mkdir -p "$OWN/backups" && chmod 700 "$OWN/backups"
  b="$OWN/backups/$2-$(date +%Y%m%d-%H%M%S)-$$.bak"
  cp -p "$1" "$b" || fail "Couldn't back up $1"
  ls -t "$OWN/backups"/*.bak 2>/dev/null | tail -n +31 | while IFS= read -r old; do rm -f "$old"; done
}
# The file's modification time and size, taken before reading it (seen) and checked again just before writing
# (unchanged), so a change the AI app made meanwhile isn't written over.
stamp_of() { stat -c '%.9Y %s' "$1" 2>/dev/null || stat -f '%Fm %z' "$1" 2>/dev/null; }
seen() { SEEN=$(stamp_of "$1"); }
unchanged() { [ -z "$SEEN" ] || [ "$(stamp_of "$1")" = "$SEEN" ]; }
# Write new text over a file in place (keeps its permissions; the sandbox allows only the picked file itself).
replace() {
  [ -s "$2" ] || fail "Nothing to write"
  unchanged "$1" || fail "$1 changed while this ran, so nothing was written. Try again"
  cat "$2" > "$1" || fail "Couldn't write $1"
}

# Agent skills: Claude Code's and Codex's own (switch off = SKILL.md renamed SKILL.md.off, so no agent loads it) and
# the ones that came with Claude Code plugins (shown, not switched). Prints [{ id, name, description, agent, path, on,
# can_switch, body }].
out="$TMPDIR/skills.jsonl"; : > "$out"
front() { # file key: a value from the front matter between the first two --- lines
  awk -v k="$2" 'NR == 1 && $0 != "---" { exit } NR > 1 && $0 == "---" { exit }
    NR > 1 { i = index($0, ":"); if (i && substr($0, 1, i - 1) == k) { v = substr($0, i + 1); sub(/^[ \t]+/, "", v); gsub(/^["'\'']|["'\'']$/, "", v); print v; exit } }' "$1"
}
add() { # file agent on can_switch
  dir=$(dirname "$1")
  n=$(front "$1" name); [ -n "$n" ] || n=$(basename "$dir")
  jq -cn --arg path "$dir" --arg name "$n" --arg description "$(front "$1" description)" --arg agent "$2" \
    --argjson on "$3" --argjson can "$4" --rawfile body "$1" \
    '{ id: $path, name: $name, description: $description, agent: $agent, path: $path, on: $on, can_switch: $can, body: ($body | .[0:6000]) }' >> "$out"
}
for kind in claude_skills codex_skills; do
  d=$(picked "$kind"); can=true
  [ -n "$d" ] || { d=$(default_of "$kind"); can=false; }
  agent=$([ "$kind" = claude_skills ] && echo "Claude Code" || echo "Codex")
  [ -d "$d" ] || continue
  for s in "$d"/*/; do
    [ -f "$s/SKILL.md" ] && add "$s/SKILL.md" "$agent" true "$can"
    [ -f "$s/SKILL.md.off" ] && add "$s/SKILL.md.off" "$agent" false "$can"
  done
done
# Plugins' skills: ~/.claude/plugins/cache/<marketplace>/<plugin>/<version>/skills/<skill>/SKILL.md
find "$HOME/.claude/plugins/cache" -maxdepth 6 -path '*/skills/*/SKILL.md' 2>/dev/null | sort | while IFS= read -r f; do
  plugin=$(printf '%s' "$f" | sed -E 's|.*/plugins/cache/[^/]+/([^/]+)/.*|\1|')
  add "$f" "Plugin $plugin" true false
done
jq -s 'unique_by(.path) | sort_by(.name | ascii_downcase)' "$out"
stamp.sh
#!/bin/sh
# Args 1-9: the files and folders picked in the card's settings (empty when not picked). A picked one may be changed;
# otherwise the card reads where each AI app keeps it, and changes nothing there.
P_claude_code=$1 P_claude_desktop=$2 P_cursor=$3 P_vscode=$4 P_windsurf=$5 P_gemini=$6 P_codex=$7 P_claude_skills=$8 P_codex_skills=$9
shift 9
AS="$HOME/Library/Application Support"
APPS="claude_code claude_desktop cursor vscode windsurf gemini codex"
picked() {
  case "$1" in
    claude_code) printf '%s' "$P_claude_code" ;; claude_desktop) printf '%s' "$P_claude_desktop" ;; cursor) printf '%s' "$P_cursor" ;;
    vscode) printf '%s' "$P_vscode" ;; windsurf) printf '%s' "$P_windsurf" ;; gemini) printf '%s' "$P_gemini" ;; codex) printf '%s' "$P_codex" ;;
    claude_skills) printf '%s' "$P_claude_skills" ;; codex_skills) printf '%s' "$P_codex_skills" ;;
  esac
}
default_of() {
  case "$1" in
    claude_code) printf '%s' "$HOME/.claude.json" ;;
    claude_desktop) printf '%s' "$AS/Claude/claude_desktop_config.json" ;;
    cursor) printf '%s' "$HOME/.cursor/mcp.json" ;;
    vscode) printf '%s' "$AS/Code/User/mcp.json" ;;
    windsurf) printf '%s' "$HOME/.codeium/windsurf/mcp_config.json" ;;
    gemini) printf '%s' "$HOME/.gemini/settings.json" ;;
    codex) printf '%s' "$HOME/.codex/config.toml" ;;
    claude_skills) printf '%s' "$HOME/.claude/skills" ;;
    codex_skills) printf '%s' "$HOME/.codex/skills" ;;
  esac
}
file_of() { p=$(picked "$1"); [ -n "$p" ] && printf '%s' "$p" || default_of "$1"; }
name_of() {
  case "$1" in
    claude_code) echo "Claude Code" ;; claude_desktop) echo "Claude Desktop" ;; cursor) echo "Cursor" ;;
    vscode) echo "VS Code" ;; windsurf) echo "Windsurf" ;; gemini) echo "Gemini CLI" ;; codex) echo "Codex" ;;
  esac
}
# Where an app keeps its servers inside its JSON file, as a jq path.
base_of() {
  case "$1" in
    claude_code) case "$2" in local:*) jq -cn --arg p "${2#local:}" '["projects", $p, "mcpServers"]' ;; *) echo '["mcpServers"]' ;; esac ;;
    vscode) echo '["servers"]' ;;
    *) echo '["mcpServers"]' ;;
  esac
}
fail() { printf '%s\n' "$*" >&2; exit 1; }
# The card's own folder (tmp/<card>/): switched-off servers and backups live here, never in the card's state.
OWN=$(dirname "${TMPDIR%/}")
PARKED="$OWN/parked.json"
[ -f "$PARKED" ] || { umask 077; echo '[]' > "$PARKED"; }
# A file may only be changed when the person picked it in settings.
writable_of() {
  p=$(picked "$1")
  [ -n "$p" ] || fail "To change $(name_of "$1")'s servers, choose its file in this card's settings (the gear): $(default_of "$1" | sed "s|^$HOME|~|")"
  [ -f "$p" ] || fail "$(name_of "$1")'s file isn't there any more: $p"
  printf '%s' "$p"
}
# A copy of the file before each change, the newest 30 kept.
backup() {
  mkdir -p "$OWN/backups" && chmod 700 "$OWN/backups"
  b="$OWN/backups/$2-$(date +%Y%m%d-%H%M%S)-$$.bak"
  cp -p "$1" "$b" || fail "Couldn't back up $1"
  ls -t "$OWN/backups"/*.bak 2>/dev/null | tail -n +31 | while IFS= read -r old; do rm -f "$old"; done
}
# The file's modification time and size, taken before reading it (seen) and checked again just before writing
# (unchanged), so a change the AI app made meanwhile isn't written over.
stamp_of() { stat -c '%.9Y %s' "$1" 2>/dev/null || stat -f '%Fm %z' "$1" 2>/dev/null; }
seen() { SEEN=$(stamp_of "$1"); }
unchanged() { [ -z "$SEEN" ] || [ "$(stamp_of "$1")" = "$SEEN" ]; }
# Write new text over a file in place (keeps its permissions; the sandbox allows only the picked file itself).
replace() {
  [ -s "$2" ] || fail "Nothing to write"
  unchanged "$1" || fail "$1 changed while this ran, so nothing was written. Try again"
  cat "$2" > "$1" || fail "Couldn't write $1"
}

# When each config file last changed (and the card's own switched-off list), so the card reads them again only then.
for a in $APPS; do f=$(file_of "$a"); [ -f "$f" ] && stat -f '%m' "$f" 2>/dev/null || echo 0; done | tr '\n' '-'
stat -f '%m' "$PARKED" 2>/dev/null || echo 0
test.sh
#!/bin/sh
# Args 1-9: the files and folders picked in the card's settings (empty when not picked). A picked one may be changed;
# otherwise the card reads where each AI app keeps it, and changes nothing there.
P_claude_code=$1 P_claude_desktop=$2 P_cursor=$3 P_vscode=$4 P_windsurf=$5 P_gemini=$6 P_codex=$7 P_claude_skills=$8 P_codex_skills=$9
shift 9
AS="$HOME/Library/Application Support"
APPS="claude_code claude_desktop cursor vscode windsurf gemini codex"
picked() {
  case "$1" in
    claude_code) printf '%s' "$P_claude_code" ;; claude_desktop) printf '%s' "$P_claude_desktop" ;; cursor) printf '%s' "$P_cursor" ;;
    vscode) printf '%s' "$P_vscode" ;; windsurf) printf '%s' "$P_windsurf" ;; gemini) printf '%s' "$P_gemini" ;; codex) printf '%s' "$P_codex" ;;
    claude_skills) printf '%s' "$P_claude_skills" ;; codex_skills) printf '%s' "$P_codex_skills" ;;
  esac
}
default_of() {
  case "$1" in
    claude_code) printf '%s' "$HOME/.claude.json" ;;
    claude_desktop) printf '%s' "$AS/Claude/claude_desktop_config.json" ;;
    cursor) printf '%s' "$HOME/.cursor/mcp.json" ;;
    vscode) printf '%s' "$AS/Code/User/mcp.json" ;;
    windsurf) printf '%s' "$HOME/.codeium/windsurf/mcp_config.json" ;;
    gemini) printf '%s' "$HOME/.gemini/settings.json" ;;
    codex) printf '%s' "$HOME/.codex/config.toml" ;;
    claude_skills) printf '%s' "$HOME/.claude/skills" ;;
    codex_skills) printf '%s' "$HOME/.codex/skills" ;;
  esac
}
file_of() { p=$(picked "$1"); [ -n "$p" ] && printf '%s' "$p" || default_of "$1"; }
name_of() {
  case "$1" in
    claude_code) echo "Claude Code" ;; claude_desktop) echo "Claude Desktop" ;; cursor) echo "Cursor" ;;
    vscode) echo "VS Code" ;; windsurf) echo "Windsurf" ;; gemini) echo "Gemini CLI" ;; codex) echo "Codex" ;;
  esac
}
# Where an app keeps its servers inside its JSON file, as a jq path.
base_of() {
  case "$1" in
    claude_code) case "$2" in local:*) jq -cn --arg p "${2#local:}" '["projects", $p, "mcpServers"]' ;; *) echo '["mcpServers"]' ;; esac ;;
    vscode) echo '["servers"]' ;;
    *) echo '["mcpServers"]' ;;
  esac
}
fail() { printf '%s\n' "$*" >&2; exit 1; }
# The card's own folder (tmp/<card>/): switched-off servers and backups live here, never in the card's state.
OWN=$(dirname "${TMPDIR%/}")
PARKED="$OWN/parked.json"
[ -f "$PARKED" ] || { umask 077; echo '[]' > "$PARKED"; }
# A file may only be changed when the person picked it in settings.
writable_of() {
  p=$(picked "$1")
  [ -n "$p" ] || fail "To change $(name_of "$1")'s servers, choose its file in this card's settings (the gear): $(default_of "$1" | sed "s|^$HOME|~|")"
  [ -f "$p" ] || fail "$(name_of "$1")'s file isn't there any more: $p"
  printf '%s' "$p"
}
# A copy of the file before each change, the newest 30 kept.
backup() {
  mkdir -p "$OWN/backups" && chmod 700 "$OWN/backups"
  b="$OWN/backups/$2-$(date +%Y%m%d-%H%M%S)-$$.bak"
  cp -p "$1" "$b" || fail "Couldn't back up $1"
  ls -t "$OWN/backups"/*.bak 2>/dev/null | tail -n +31 | while IFS= read -r old; do rm -f "$old"; done
}
# The file's modification time and size, taken before reading it (seen) and checked again just before writing
# (unchanged), so a change the AI app made meanwhile isn't written over.
stamp_of() { stat -c '%.9Y %s' "$1" 2>/dev/null || stat -f '%Fm %z' "$1" 2>/dev/null; }
seen() { SEEN=$(stamp_of "$1"); }
unchanged() { [ -z "$SEEN" ] || [ "$(stamp_of "$1")" = "$SEEN" ]; }
# Write new text over a file in place (keeps its permissions; the sandbox allows only the picked file itself).
replace() {
  [ -s "$2" ] || fail "Nothing to write"
  unchanged "$1" || fail "$1 changed while this ran, so nothing was written. Try again"
  cat "$2" > "$1" || fail "Couldn't write $1"
}

# Connect to one server the way an AI app does (MCP's initialize, then tools/list) and print
# { id, name, ok, took (seconds), server, tools: [{ name, description }], error }.
# Args: id, then Codex's [mcp_servers] as JSON (from parse:'toml').
id=$1 codex=${2:-null}
[ "$codex" = "" ] && codex=null
a=${id%%:*}; rest=${id#*:}; name=${id##*:}; scope=${rest%:*}
f=$(file_of "$a")
started=$(date +%s)
entry=null
result() { # ok error tools server
  # A server's own error text may repeat a key it was given: the entry's env and header values never leave this script.
  jq -cn --arg id "$id" --arg name "$name" --argjson ok "$1" --arg error "$2" --argjson tools "${3:-[]}" --argjson server "${4:-null}" \
    --argjson took "$(( $(date +%s) - started ))" --argjson entry "${entry:-null}" \
    '([($entry // {}) | (.env, .headers, .http_headers) | objects | .[] | tostring | select(length >= 4)]) as $secrets
     | (reduce $secrets[] as $v ($error; split($v) | join("•••"))) as $error
     | { id: $id, name: $name, ok: $ok, took: $took, at: now, server: $server, tools: $tools, error: (if $error == "" then null else $error end) }'
  exit 0
}
entry=$(jq -c --arg id "$id" 'map(select(.id == $id)) | .[0].entry // null' "$PARKED")
if [ "$entry" = null ]; then
  if [ "$a" = codex ]; then
    entry=$(printf '%s' "$codex" | jq -c --arg n "$name" '.[$n] // null')
  else
    [ -f "$f" ] || result false "$(name_of "$a")'s file isn't there"
    entry=$(jq -c --argjson b "$(base_of "$a" "$scope")" --arg n "$name" 'getpath($b + [$n])' "$f" 2>/dev/null)
  fi
fi
[ -n "$entry" ] && [ "$entry" != null ] || result false "Couldn't find $name's settings (a switched-off Codex server is tested once it's on)"
get() { printf '%s' "$entry" | jq -r "$1"; }
url=$(get '.url // .serverUrl // .httpUrl // empty')
INIT='{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"tailapps-mcp-check","version":"1.0"}}}'
READY='{"jsonrpc":"2.0","method":"notifications/initialized"}'
list() { printf '{"jsonrpc":"2.0","id":%s,"method":"tools/list"%s}' "$1" "$([ -n "$2" ] && printf ',"params":{"cursor":%s}' "$(jq -cn --arg c "$2" '$c')")"; }
# The answer with this id among the lines a server wrote (partial lines are skipped).
answer() { jq -cR --argjson id "$1" 'fromjson? | select(type == "object" and .id == $id)' "$2" 2>/dev/null | head -n 1; }
tools="$TMPDIR/tools.jsonl"; : > "$tools"

if [ -n "$url" ]; then
  [ "$(get '.type // .transport // empty')" = sse ] && result false "This server uses the older SSE kind, which the check doesn't speak yet"
  set --
  for k in $(get '(.headers // .http_headers // {}) | keys[]' | tr '\n' ' '); do
    set -- "$@" -H "$k: $(printf '%s' "$entry" | jq -r --arg k "$k" '(.headers // .http_headers)[$k] | tostring')"
  done
  post() { # body -> response body in $TMPDIR/body, headers in $TMPDIR/h
    code=$(curl -sS -m 30 -o "$TMPDIR/body" -D "$TMPDIR/h" -w '%{http_code}' -H 'Content-Type: application/json' \
      -H 'Accept: application/json, text/event-stream' -H 'MCP-Protocol-Version: 2025-06-18' \
      ${session:+-H "Mcp-Session-Id: $session"} "$@" --data-binary "$body" "$url" 2>"$TMPDIR/err") || result false "Couldn't reach it: $(tail -n 1 "$TMPDIR/err")"
    case "$code" in 2*) ;; 401|403) result false "It needs a sign-in (status $code). Sign in from your AI app; this check can't" ;; *) result false "It answered with status $code" ;; esac
    # Streamed answers come as `data:` lines.
    sed -n 's/^data: *//p' "$TMPDIR/body" > "$TMPDIR/events"
    [ -s "$TMPDIR/events" ] && cat "$TMPDIR/events" > "$TMPDIR/body"
    tr -d '\r' < "$TMPDIR/body" > "$TMPDIR/b2" && echo >> "$TMPDIR/b2"
  }
  session=""
  body=$INIT; post "$@"
  init=$(answer 1 "$TMPDIR/b2")
  session=$(tr -d '\r' < "$TMPDIR/h" | awk 'tolower($1) == "mcp-session-id:" { print $2 }' | tail -n 1)
  body=$READY; curl -sS -m 10 -o /dev/null -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' \
    ${session:+-H "Mcp-Session-Id: $session"} "$@" --data-binary "$body" "$url" 2>/dev/null
  cursor=""; i=2
  while [ $i -le 6 ]; do
    body=$(list $i "$cursor"); post "$@"
    page=$(answer $i "$TMPDIR/b2")
    [ -n "$page" ] || break
    printf '%s' "$page" | jq -c '.result.tools[]? | { name, description: (.description // "" | .[0:300]) }' >> "$tools"
    cursor=$(printf '%s' "$page" | jq -r '.result.nextCursor // empty')
    [ -n "$cursor" ] || break
    i=$((i + 1))
  done
else
  cmd=$(get '.command // empty')
  [ -n "$cmd" ] || result false "It has neither a command nor a URL"
  # The places people's tools live, which a Mac app's own PATH leaves out (nvm, Volta, Bun, uv, Cargo, …).
  for d in "$HOME/.volta/bin" "$HOME/.bun/bin" "$HOME/.cargo/bin" "$HOME/.local/bin" "$HOME/.deno/bin" "$HOME/.nvm/versions/node"/*/bin; do
    [ -d "$d" ] && PATH="$PATH:$d"
  done
  export PATH
  # Arguments and env exactly as the app passes them, each one whole (no shell in between).
  set --
  count=$(get '(.env // {}) | length')
  i=0; while [ "$i" -lt "$count" ]; do set -- "$@" "$(printf '%s' "$entry" | jq -r --argjson i "$i" '.env | to_entries[$i] | "\(.key)=\(.value)"')"; i=$((i + 1)); done
  set -- "$@" "$cmd"
  count=$(get '(.args // []) | length')
  i=0; while [ "$i" -lt "$count" ]; do set -- "$@" "$(printf '%s' "$entry" | jq -r --argjson i "$i" '.args[$i] | tostring')"; i=$((i + 1)); done
  cwd=$(get '.cwd // empty'); [ -n "$cwd" ] && [ -d "$cwd" ] && cd "$cwd"
  rm -f "$TMPDIR/in"; mkfifo "$TMPDIR/in" || result false "Couldn't start it"
  # Its own process group, so stopping it also stops what it started (npx runs node).
  set -m 2>/dev/null
  /usr/bin/env "$@" < "$TMPDIR/in" > "$TMPDIR/out" 2> "$TMPDIR/err" &
  pid=$!
  exec 3> "$TMPDIR/in"
  stop() { exec 3>&-; sleep 0.3; kill -TERM -"$pid" 2>/dev/null || kill -TERM "$pid" 2>/dev/null; }
  # Still running (an exited child stays a zombie until reaped, which kill -0 can't tell apart).
  alive() { st=$(ps -o stat= -p "$pid" 2>/dev/null); case "$st" in ''|Z*) return 1 ;; esac; }
  # Waits up to 90 s for an answer (the first run of npx or uvx downloads the server).
  wait_for() {
    w=0
    while [ $w -lt 450 ]; do
      got=$(answer "$1" "$TMPDIR/out"); [ -n "$got" ] && { printf '%s' "$got"; return 0; }
      alive || return 1
      sleep 0.2; w=$((w + 1))
    done
    return 1
  }
  printf '%s\n' "$INIT" >&3
  init=$(wait_for 1) || {
    e=$(tail -n 3 "$TMPDIR/err" | tr '\n' ' '); stop
    # TailApps' sandbox stops a card's scripts from starting programs they downloaded (npx and uvx keep theirs in caches).
    case "$e" in *"Operation not permitted"*|*EPERM*|*"not permitted"*|*EACCES*|*"Sandbox"*|*"sandbox"*)
      result false "TailApps' sandbox stopped it from starting. To test servers that run on this Mac, turn on Trusted (Full Access) in this card's ⋯ menu. Hosted servers test without it" ;;
    esac
    result false "It didn't answer${e:+: $e}"
  }
  printf '%s\n' "$READY" >&3
  cursor=""; i=2
  while [ $i -le 6 ]; do
    printf '%s\n' "$(list $i "$cursor")" >&3
    page=$(wait_for $i) || break
    printf '%s' "$page" | jq -c '.result.tools[]? | { name, description: (.description // "" | .[0:300]) }' >> "$tools"
    cursor=$(printf '%s' "$page" | jq -r '.result.nextCursor // empty')
    [ -n "$cursor" ] || break
    i=$((i + 1))
  done
  stop
fi
[ -n "$init" ] || result false "It didn't answer the MCP handshake"
err=$(printf '%s' "$init" | jq -r '.error.message // empty')
[ -z "$err" ] || result false "$err"
result true "" "$(jq -sc '.' "$tools")" "$(printf '%s' "$init" | jq -c '.result.serverInfo // null')"
toggle.sh
#!/bin/sh
# Args 1-9: the files and folders picked in the card's settings (empty when not picked). A picked one may be changed;
# otherwise the card reads where each AI app keeps it, and changes nothing there.
P_claude_code=$1 P_claude_desktop=$2 P_cursor=$3 P_vscode=$4 P_windsurf=$5 P_gemini=$6 P_codex=$7 P_claude_skills=$8 P_codex_skills=$9
shift 9
AS="$HOME/Library/Application Support"
APPS="claude_code claude_desktop cursor vscode windsurf gemini codex"
picked() {
  case "$1" in
    claude_code) printf '%s' "$P_claude_code" ;; claude_desktop) printf '%s' "$P_claude_desktop" ;; cursor) printf '%s' "$P_cursor" ;;
    vscode) printf '%s' "$P_vscode" ;; windsurf) printf '%s' "$P_windsurf" ;; gemini) printf '%s' "$P_gemini" ;; codex) printf '%s' "$P_codex" ;;
    claude_skills) printf '%s' "$P_claude_skills" ;; codex_skills) printf '%s' "$P_codex_skills" ;;
  esac
}
default_of() {
  case "$1" in
    claude_code) printf '%s' "$HOME/.claude.json" ;;
    claude_desktop) printf '%s' "$AS/Claude/claude_desktop_config.json" ;;
    cursor) printf '%s' "$HOME/.cursor/mcp.json" ;;
    vscode) printf '%s' "$AS/Code/User/mcp.json" ;;
    windsurf) printf '%s' "$HOME/.codeium/windsurf/mcp_config.json" ;;
    gemini) printf '%s' "$HOME/.gemini/settings.json" ;;
    codex) printf '%s' "$HOME/.codex/config.toml" ;;
    claude_skills) printf '%s' "$HOME/.claude/skills" ;;
    codex_skills) printf '%s' "$HOME/.codex/skills" ;;
  esac
}
file_of() { p=$(picked "$1"); [ -n "$p" ] && printf '%s' "$p" || default_of "$1"; }
name_of() {
  case "$1" in
    claude_code) echo "Claude Code" ;; claude_desktop) echo "Claude Desktop" ;; cursor) echo "Cursor" ;;
    vscode) echo "VS Code" ;; windsurf) echo "Windsurf" ;; gemini) echo "Gemini CLI" ;; codex) echo "Codex" ;;
  esac
}
# Where an app keeps its servers inside its JSON file, as a jq path.
base_of() {
  case "$1" in
    claude_code) case "$2" in local:*) jq -cn --arg p "${2#local:}" '["projects", $p, "mcpServers"]' ;; *) echo '["mcpServers"]' ;; esac ;;
    vscode) echo '["servers"]' ;;
    *) echo '["mcpServers"]' ;;
  esac
}
fail() { printf '%s\n' "$*" >&2; exit 1; }
# The card's own folder (tmp/<card>/): switched-off servers and backups live here, never in the card's state.
OWN=$(dirname "${TMPDIR%/}")
PARKED="$OWN/parked.json"
[ -f "$PARKED" ] || { umask 077; echo '[]' > "$PARKED"; }
# A file may only be changed when the person picked it in settings.
writable_of() {
  p=$(picked "$1")
  [ -n "$p" ] || fail "To change $(name_of "$1")'s servers, choose its file in this card's settings (the gear): $(default_of "$1" | sed "s|^$HOME|~|")"
  [ -f "$p" ] || fail "$(name_of "$1")'s file isn't there any more: $p"
  printf '%s' "$p"
}
# A copy of the file before each change, the newest 30 kept.
backup() {
  mkdir -p "$OWN/backups" && chmod 700 "$OWN/backups"
  b="$OWN/backups/$2-$(date +%Y%m%d-%H%M%S)-$$.bak"
  cp -p "$1" "$b" || fail "Couldn't back up $1"
  ls -t "$OWN/backups"/*.bak 2>/dev/null | tail -n +31 | while IFS= read -r old; do rm -f "$old"; done
}
# The file's modification time and size, taken before reading it (seen) and checked again just before writing
# (unchanged), so a change the AI app made meanwhile isn't written over.
stamp_of() { stat -c '%.9Y %s' "$1" 2>/dev/null || stat -f '%Fm %z' "$1" 2>/dev/null; }
seen() { SEEN=$(stamp_of "$1"); }
unchanged() { [ -z "$SEEN" ] || [ "$(stamp_of "$1")" = "$SEEN" ]; }
# Write new text over a file in place (keeps its permissions; the sandbox allows only the picked file itself).
replace() {
  [ -s "$2" ] || fail "Nothing to write"
  unchanged "$1" || fail "$1 changed while this ran, so nothing was written. Try again"
  cat "$2" > "$1" || fail "Couldn't write $1"
}

# Turn one server off (its exact entry moves to the card's own folder) or back on (put back as it was).
# Args: id ("<app>:<scope>:<name>"), true|false, and the server as the card shows it (kept with the entry).
id=$1 on=$2 info=${3:-"{}"}
a=${id%%:*}; rest=${id#*:}; name=${id##*:}; scope=${rest%:*}
n=$(name_of "$a"); [ -n "$n" ] || fail "Unknown app in $id"
f=$(writable_of "$a") || exit 1
seen "$f"
new="$TMPDIR/new"
# The [mcp_servers.<name>] table of a config.toml, and its sub-tables (env), with or without quotes in the name.
toml_split() { # file name keep|block
  awk -v n="$2" -v want="$3" '
    /^[ \t]*\[/ { t = $0; sub(/^[ \t]*\[+[ \t]*/, "", t); sub(/[ \t]*\]+.*$/, "", t); gsub(/"/, "", t)
                  inblk = (t == "mcp_servers." n || index(t, "mcp_servers." n ".") == 1) }
    { if ((want == "block") == (inblk == 1)) print }' "$1"
}
if [ "$on" = false ]; then
  if [ "$a" = codex ]; then
    block=$(toml_split "$f" "$name" block)
    [ -n "$block" ] || fail "Codex's config.toml has no [mcp_servers.$name] table to switch off"
    backup "$f" "$a"
    toml_split "$f" "$name" keep > "$new"
    jq --arg id "$id" --arg toml "$block" --argjson info "$info" '[.[] | select(.id != $id)] + [{ id: $id, toml: $toml, info: $info, at: now }]' "$PARKED" > "$TMPDIR/parked"
  else
    base=$(base_of "$a" "$scope")
    entry=$(jq -c --argjson b "$base" --arg n "$name" 'getpath($b + [$n])' "$f") || fail "Couldn't read $f"
    [ "$entry" != null ] || fail "$n has no server named $name any more"
    backup "$f" "$a"
    jq --argjson b "$base" --arg n "$name" 'delpaths([$b + [$n]])' "$f" > "$new" || fail "Couldn't change $f"
    jq --arg id "$id" --argjson e "$entry" --argjson info "$info" '[.[] | select(.id != $id)] + [{ id: $id, entry: $e, info: $info, at: now }]' "$PARKED" > "$TMPDIR/parked"
  fi
  replace "$f" "$new"
  cat "$TMPDIR/parked" > "$PARKED"
  echo "{\"ok\":true}"
  exit 0
fi
saved=$(jq -c --arg id "$id" 'map(select(.id == $id)) | .[0]' "$PARKED")
[ "$saved" != null ] || fail "$name isn't switched off here"
if [ "$a" = codex ]; then
  [ -z "$(toml_split "$f" "$name" block)" ] || fail "Codex already has a server named $name"
  backup "$f" "$a"
  { cat "$f"; [ -n "$(tail -c 1 "$f")" ] && echo; echo; printf '%s\n' "$saved" | jq -r '.toml'; } > "$new"
else
  base=$(base_of "$a" "$scope")
  [ "$(jq --argjson b "$base" --arg n "$name" 'getpath($b + [$n]) != null' "$f")" = false ] || fail "$n already has a server named $name"
  backup "$f" "$a"
  jq --argjson b "$base" --arg n "$name" --argjson e "$(printf '%s' "$saved" | jq -c '.entry')" 'setpath($b + [$n]; $e)' "$f" > "$new" || fail "Couldn't change $f"
fi
replace "$f" "$new"
jq --arg id "$id" 'map(select(.id != $id))' "$PARKED" > "$TMPDIR/parked" && cat "$TMPDIR/parked" > "$PARKED"
echo "{\"ok\":true}"
Report MCP Servers?

Tell us what’s wrong with this card. We read every report.

What’s wrong