summaryrefslogtreecommitdiff
path: root/link/claude.sh
diff options
context:
space:
mode:
Diffstat (limited to 'link/claude.sh')
-rwxr-xr-xlink/claude.sh26
1 files changed, 22 insertions, 4 deletions
diff --git a/link/claude.sh b/link/claude.sh
index 56f3724..2d6679c 100755
--- a/link/claude.sh
+++ b/link/claude.sh
@@ -41,7 +41,10 @@ link "$config_dir/claude/CLAUDE.md" "$HOME/.claude/CLAUDE.md"
# trust, which includes $HOME, so a token fetched there
# would simply be missing. The secret ends up in
# ~/.claude.json, which Claude Code keeps mode 600. A
-# secret that cannot be read skips that server, loudly.
+# secret that exists but is in a bucket this host
+# doesn't read leaves that server out here, and takes
+# out one registered before; one that cannot be read
+# otherwise skips that server, loudly.
#
# "desktop" a whole spec to give Claude Desktop instead of this one,
# e.g. a local stdio server where Claude Code gets a remote
@@ -120,13 +123,21 @@ then
then
echo "Will register MCP server (user scope): $name"
else
- if ! code_spec="$(python3 -c 'import json, re, subprocess, sys
+ rc=0
+ code_spec="$(python3 -c 'import json, re, subprocess, sys
spec = json.loads(sys.argv[1])
spec.pop("desktop", None)
def secret(match):
name = match.group(1)
try:
+ if subprocess.run(["szecret", "has", name], capture_output=True).returncode != 0:
+ # Not a reader only when it exists elsewhere; anything else is a fault.
+ names = subprocess.run(["szecret", "list", "--names", "--all"], check=True, capture_output=True, text=True).stdout.split()
+ if any(n.endswith("/" + name) for n in names):
+ print("this host does not read %s" % name)
+ sys.exit(3)
+ sys.exit("szecret has no %s" % name)
return subprocess.run(["szecret", "get", name], check=True, capture_output=True, text=True).stdout.strip()
except (OSError, subprocess.CalledProcessError):
sys.exit("szecret get %s failed" % name)
@@ -140,9 +151,16 @@ def expand(value):
return [expand(v) for v in value]
return value
-print(json.dumps(expand(spec)))' "$spec" 2>&1)"
+print(json.dumps(expand(spec)))' "$spec" 2>&1)" || rc=$?
+ if [[ "$rc" -ne 0 ]]
then
- red "MCP server (user scope) not registered: $name: $code_spec"
+ if [[ "$rc" -eq 3 ]]
+ then
+ claude mcp remove --scope user "$name" >/dev/null 2>&1 || true
+ echo "MCP server (user scope) not here: $name: $code_spec"
+ else
+ red "MCP server (user scope) not registered: $name: $code_spec"
+ fi
continue
fi
green "MCP server (user scope): $name"