Skip to content

Commit 470b47b

Browse files
committed
feat(plugin): make Rune MCP server online with no session restart
1 parent e2fe698 commit 470b47b

2 files changed

Lines changed: 44 additions & 18 deletions

File tree

.claude-plugin/plugin.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"rune": {
1616
"command": "${CLAUDE_PLUGIN_ROOT}/bin/rune",
1717
"args": ["mcp-server"],
18-
"description": "Rune MCP server entry point. Routes through the always-present bin/rune bootstrap (the CLI's documented 'mcp-server' entry point) so a fresh install self-heals: on first spawn it installs the CLI + rune-mcp if missing, then forwards stdio to ~/.rune/bin/rune-mcp, which boots dormant until /rune:configure. No manual /mcp reconnect needed."
18+
"timeout": 30000,
19+
"description": "Rune MCP server (talks to Vault + embedder + enVector). The command is the plugin's bash wrapper, which always exists at session start; on first run it self-install rune-mcp, then exec - MCP server comes online in the same session with no restart."
1920
}
2021
}
2122
}

bin/rune

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# - When ~/.rune/bin/rune is missing: `install` and `mcp-server` are
1111
# accepted as bootstrap entry points (mcp-server self-installs the
1212
# CLI + rune-mcp first, so a fresh plugin install boots without a
13-
# manual /mcp reconnect)
13+
# manual /mcp reconnect or session restart)
1414
#
1515
# Windows support: this wrapper is bash-only. Native Windows shells
1616
# (PowerShell / cmd) cannot execute this. Windows users must invoke it
@@ -20,14 +20,8 @@ set -euo pipefail
2020
RUNE_HOME="${RUNE_HOME:-$HOME/.rune}"
2121
TARGET="$RUNE_HOME/bin/rune"
2222

23-
# Delegate to ~/.rune/bin/rune
23+
# Delegate to ~/.rune/bin/rune immediately
2424
if [ -x "$TARGET" ]; then
25-
# MCP entry point: ensure rune-mcp is also present before forwarding.
26-
# A partial install (CLI present, rune-mcp missing) would otherwise fail
27-
# the spawn. Install output goes to stderr — stdout is the MCP channel.
28-
if [ "${1:-}" = "mcp-server" ] && [ ! -x "$RUNE_HOME/bin/rune-mcp" ]; then
29-
"$TARGET" install >&2 || true
30-
fi
3125
exec "$TARGET" "$@"
3226
fi
3327

@@ -45,6 +39,42 @@ case "${1:-}" in
4539
;;
4640
esac
4741

42+
# Concurrency-safe CLI download
43+
mkdir -p "$RUNE_HOME"
44+
LOCK_DIR="$RUNE_HOME/bootstrap.lock.d"
45+
TMP=""
46+
SUMS=""
47+
cleanup() {
48+
[ -n "$TMP" ] && rm -f "$TMP"
49+
[ -n "$SUMS" ] && rm -f "$SUMS"
50+
rmdir "$LOCK_DIR" 2>/dev/null || true
51+
}
52+
53+
waited=0
54+
while ! mkdir "$LOCK_DIR" 2>/dev/null; do # another session hold lock
55+
if [ -x "$TARGET" ]; then
56+
exec "$TARGET" "$@" # bootstrap finished
57+
fi
58+
59+
sleep 1
60+
waited=$((waited + 1))
61+
if [ "$waited" -ge 120 ]; then
62+
echo "rune: bootstrap lock held >120s, reclaiming" >&2
63+
rmdir "$LOCK_DIR" 2>/dev/null || true
64+
waited=0
65+
fi
66+
done
67+
68+
# Check error
69+
trap cleanup EXIT INT TERM
70+
71+
if [ -x "$TARGET" ]; then
72+
cleanup
73+
trap - EXIT INT TERM
74+
exec "$TARGET" "$@"
75+
fi
76+
77+
# Lazy version evaluation
4878
# Priority: RUNE_VERSION > latest release (including pre-release for now)
4979
# TODO: switch to .../rune/releases/latest
5080
RUNE_VERSION="${RUNE_VERSION:-}"
@@ -96,7 +126,6 @@ mkdir -p "$(dirname "$TARGET")"
96126
# Download and verify
97127
TMP="$(mktemp -t rune-bootstrap-XXXXXX)"
98128
SUMS="$(mktemp -t rune-bootstrap-sums-XXXXXX)"
99-
trap 'rm -f "$TMP" "$SUMS"' EXIT
100129

101130
curl --fail --silent --show-error --location "$RELEASE_BASE/$ASSET" -o "$TMP"
102131
curl --fail --silent --show-error --location "$RELEASE_BASE/checksums.txt" -o "$SUMS"
@@ -120,16 +149,12 @@ if [ "$ACTUAL" != "$EXPECTED" ]; then
120149
exit 1
121150
fi
122151

123-
# Post-download
152+
# Atomic publish
124153
chmod +x "$TMP"
125154
mv -f "$TMP" "$TARGET"
126-
127-
# If we bootstrapped via the `mcp-server` entry point, the rune-mcp binary
128-
# must also exist before we can forward stdio to it — install it now.
129-
# (stderr, not stdout: stdout becomes the MCP channel after exec.)
130-
if [ "${1:-}" = "mcp-server" ] && [ ! -x "$RUNE_HOME/bin/rune-mcp" ]; then
131-
"$TARGET" install >&2 || { echo "rune: mcp-server bootstrap (install) failed" >&2; exit 127; }
132-
fi
155+
TMP=""
133156

134157
# Delegate to the freshly-installed Go binary
158+
cleanup
159+
trap - EXIT INT TERM
135160
exec "$TARGET" "$@"

0 commit comments

Comments
 (0)