scripts/lmcp-install-macos.sh: fix for real-world Homebrew
Original draft assumed `brew install lua luasocket` works. It doesn't: luasocket isn't a brew formula (install via luarocks), and default `lua` is 5.5 while the rest of the fleet is on 5.4. Fix tested on riemann (Intel Mac, macOS 14.8.3): - Pin to lua@5.4 (keg-only brew formula) — matches fleet library paths. - Install luasocket via luarocks into the user-local rocks tree. - Source brew shellenv ourselves so non-login bash shells can find brew. - Bake LUA_PATH / LUA_CPATH into the LaunchAgent plist so the service resolves `require 'socket'` from ~/.luarocks/. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Install lmcp on macOS via Homebrew.
|
# Install lmcp on macOS via Homebrew.
|
||||||
#
|
#
|
||||||
# Idempotent. Pulls lua + luasocket from brew, copies lmcp library files
|
# Pins to lua@5.4 (keg-only brew formula) to keep library paths aligned
|
||||||
# into brew's share/lua/5.4/ tree, mints a Bearer token (or reuses an
|
# with the rest of the fleet (Arch/ALARM, Debian). Installs luasocket via
|
||||||
# existing one at $(brew --prefix)/etc/lmcp/token), installs a LaunchAgent,
|
# luarocks into the user-local rocks tree (~/.luarocks/) and bakes the
|
||||||
# starts the service, and prints the token for Claude Code MCP config.
|
# required LUA_PATH / LUA_CPATH into the LaunchAgent plist so the service
|
||||||
|
# can `require 'socket'`.
|
||||||
#
|
#
|
||||||
# Usage (from lmcp repo root):
|
# Usage (from lmcp repo root):
|
||||||
# ./scripts/lmcp-install-macos.sh
|
# ./scripts/lmcp-install-macos.sh
|
||||||
@@ -16,37 +17,55 @@
|
|||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
PREFIX=$(brew --prefix)
|
# brew is only on PATH in login shells by default; source its env explicitly
|
||||||
REPO=${REPO:-$(cd "$(dirname "$0")/.." && pwd)}
|
# so this works under a plain non-login bash too.
|
||||||
LABEL="de.reauktion.marfrit.lmcp"
|
if ! command -v brew >/dev/null 2>&1; then
|
||||||
PLIST="$HOME/Library/LaunchAgents/$LABEL.plist"
|
for candidate in /opt/homebrew/bin/brew /usr/local/bin/brew; do
|
||||||
TOKEN_FILE="$PREFIX/etc/lmcp/token"
|
if [ -x "$candidate" ]; then
|
||||||
PORT="${LMCP_PORT:-8080}"
|
eval "$("$candidate" shellenv)"
|
||||||
NAME="${LMCP_NAME:-$(hostname -s)-tools}"
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
command -v brew >/dev/null 2>&1 || { echo "error: Homebrew not found"; exit 1; }
|
||||||
|
|
||||||
|
REPO=${REPO:-$(cd "$(dirname "$0")/.." && pwd)}
|
||||||
for f in lmcp.lua json.lua server.lua example_server.lua; do
|
for f in lmcp.lua json.lua server.lua example_server.lua; do
|
||||||
[ -f "$REPO/$f" ] || { echo "error: $REPO/$f not found — run from lmcp repo root or set REPO="; exit 1; }
|
[ -f "$REPO/$f" ] || { echo "error: $REPO/$f not found — run from lmcp repo root or set REPO="; exit 1; }
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "==> brew install lua + luasocket"
|
echo "==> brew install lua@5.4 luarocks"
|
||||||
brew install --quiet lua luasocket
|
brew install --quiet lua@5.4 luarocks
|
||||||
|
|
||||||
LUA="$PREFIX/bin/lua"
|
LUA54_PREFIX=$(brew --prefix lua@5.4)
|
||||||
[ -x "$LUA" ] || { echo "error: $LUA not executable after brew install"; exit 1; }
|
LUA54=$LUA54_PREFIX/bin/lua5.4
|
||||||
|
BREW_PREFIX=$(brew --prefix)
|
||||||
|
[ -x "$LUA54" ] || { echo "error: $LUA54 missing after brew install"; exit 1; }
|
||||||
|
|
||||||
echo "==> install library files into $PREFIX/share/lua/5.4/"
|
echo "==> luarocks install luasocket (user-local, pinned to lua@5.4)"
|
||||||
install -d "$PREFIX/share/lua/5.4"
|
luarocks --lua-version 5.4 --lua-dir "$LUA54_PREFIX" install --local luasocket
|
||||||
install -m 644 "$REPO/lmcp.lua" "$PREFIX/share/lua/5.4/lmcp.lua"
|
|
||||||
install -m 644 "$REPO/json.lua" "$PREFIX/share/lua/5.4/json.lua"
|
|
||||||
install -m 644 "$REPO/server.lua" "$PREFIX/share/lua/5.4/server.lua"
|
|
||||||
install -m 755 "$REPO/example_server.lua" "$PREFIX/bin/lmcp-example"
|
|
||||||
|
|
||||||
# Token: retain existing, otherwise mint 32 bytes of hex.
|
LR_PATH=$(luarocks --lua-version 5.4 --lua-dir "$LUA54_PREFIX" path --lr-path)
|
||||||
|
LR_CPATH=$(luarocks --lua-version 5.4 --lua-dir "$LUA54_PREFIX" path --lr-cpath)
|
||||||
|
DEFAULT_LUA_P="$BREW_PREFIX/share/lua/5.4/?.lua;$BREW_PREFIX/share/lua/5.4/?/init.lua;$BREW_PREFIX/lib/lua/5.4/?.lua;$BREW_PREFIX/lib/lua/5.4/?/init.lua;./?.lua;./?/init.lua"
|
||||||
|
DEFAULT_LUA_CP="$BREW_PREFIX/lib/lua/5.4/?.so;./?.so"
|
||||||
|
FULL_LUA_P="$DEFAULT_LUA_P;$LR_PATH"
|
||||||
|
FULL_LUA_CP="$DEFAULT_LUA_CP;$LR_CPATH"
|
||||||
|
|
||||||
|
echo "==> install library files into $BREW_PREFIX/share/lua/5.4/"
|
||||||
|
install -d "$BREW_PREFIX/share/lua/5.4"
|
||||||
|
install -m 644 "$REPO/lmcp.lua" "$BREW_PREFIX/share/lua/5.4/lmcp.lua"
|
||||||
|
install -m 644 "$REPO/json.lua" "$BREW_PREFIX/share/lua/5.4/json.lua"
|
||||||
|
install -m 644 "$REPO/server.lua" "$BREW_PREFIX/share/lua/5.4/server.lua"
|
||||||
|
install -m 755 "$REPO/example_server.lua" "$BREW_PREFIX/bin/lmcp-example"
|
||||||
|
|
||||||
|
# Token: retain existing, mint new otherwise
|
||||||
|
TOKEN_FILE="$BREW_PREFIX/etc/lmcp/token"
|
||||||
|
install -d -m 755 "$BREW_PREFIX/etc/lmcp"
|
||||||
if [ -r "$TOKEN_FILE" ]; then
|
if [ -r "$TOKEN_FILE" ]; then
|
||||||
TOKEN=$(cat "$TOKEN_FILE")
|
TOKEN=$(cat "$TOKEN_FILE")
|
||||||
echo "==> reusing token from $TOKEN_FILE"
|
echo "==> reusing token from $TOKEN_FILE"
|
||||||
else
|
else
|
||||||
install -d -m 700 "$(dirname "$TOKEN_FILE")"
|
|
||||||
TOKEN=$(openssl rand -hex 32)
|
TOKEN=$(openssl rand -hex 32)
|
||||||
umask 077
|
umask 077
|
||||||
printf '%s\n' "$TOKEN" > "$TOKEN_FILE"
|
printf '%s\n' "$TOKEN" > "$TOKEN_FILE"
|
||||||
@@ -54,6 +73,11 @@ else
|
|||||||
echo "==> minted new token, stored at $TOKEN_FILE (0600)"
|
echo "==> minted new token, stored at $TOKEN_FILE (0600)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
LABEL="de.reauktion.marfrit.lmcp"
|
||||||
|
PLIST="$HOME/Library/LaunchAgents/$LABEL.plist"
|
||||||
|
PORT="${LMCP_PORT:-8080}"
|
||||||
|
NAME="${LMCP_NAME:-$(hostname -s)-tools}"
|
||||||
|
|
||||||
echo "==> write LaunchAgent $PLIST"
|
echo "==> write LaunchAgent $PLIST"
|
||||||
mkdir -p "$HOME/Library/LaunchAgents"
|
mkdir -p "$HOME/Library/LaunchAgents"
|
||||||
cat > "$PLIST" <<PLIST
|
cat > "$PLIST" <<PLIST
|
||||||
@@ -65,8 +89,8 @@ cat > "$PLIST" <<PLIST
|
|||||||
<string>$LABEL</string>
|
<string>$LABEL</string>
|
||||||
<key>ProgramArguments</key>
|
<key>ProgramArguments</key>
|
||||||
<array>
|
<array>
|
||||||
<string>$LUA</string>
|
<string>$LUA54</string>
|
||||||
<string>$PREFIX/share/lua/5.4/server.lua</string>
|
<string>$BREW_PREFIX/share/lua/5.4/server.lua</string>
|
||||||
</array>
|
</array>
|
||||||
<key>EnvironmentVariables</key>
|
<key>EnvironmentVariables</key>
|
||||||
<dict>
|
<dict>
|
||||||
@@ -76,6 +100,10 @@ cat > "$PLIST" <<PLIST
|
|||||||
<string>$NAME</string>
|
<string>$NAME</string>
|
||||||
<key>LMCP_TOKEN</key>
|
<key>LMCP_TOKEN</key>
|
||||||
<string>$TOKEN</string>
|
<string>$TOKEN</string>
|
||||||
|
<key>LUA_PATH</key>
|
||||||
|
<string>$FULL_LUA_P</string>
|
||||||
|
<key>LUA_CPATH</key>
|
||||||
|
<string>$FULL_LUA_CP</string>
|
||||||
</dict>
|
</dict>
|
||||||
<key>RunAtLoad</key>
|
<key>RunAtLoad</key>
|
||||||
<true/>
|
<true/>
|
||||||
@@ -94,12 +122,12 @@ echo "==> (re)load LaunchAgent"
|
|||||||
launchctl unload "$PLIST" 2>/dev/null || true
|
launchctl unload "$PLIST" 2>/dev/null || true
|
||||||
launchctl load "$PLIST"
|
launchctl load "$PLIST"
|
||||||
|
|
||||||
sleep 1
|
sleep 2
|
||||||
echo "==> smoke test (unauth expected 401, Bearer expected 200)"
|
echo "==> smoke test (unauth expected 401, Bearer expected 200)"
|
||||||
unauth=$(curl -s -o /dev/null -w '%{http_code}' -X POST "http://127.0.0.1:$PORT/mcp" \
|
unauth=$(curl -s -o /dev/null -w '%{http_code}' --max-time 3 -X POST "http://127.0.0.1:$PORT/mcp" \
|
||||||
-H 'Content-Type: application/json' \
|
-H 'Content-Type: application/json' \
|
||||||
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' || echo "000")
|
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' || echo "000")
|
||||||
auth=$(curl -s -X POST "http://127.0.0.1:$PORT/mcp" \
|
auth=$(curl -s --max-time 3 -X POST "http://127.0.0.1:$PORT/mcp" \
|
||||||
-H "Authorization: Bearer $TOKEN" \
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
-H 'Content-Type: application/json' \
|
-H 'Content-Type: application/json' \
|
||||||
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' || true)
|
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' || true)
|
||||||
@@ -121,7 +149,7 @@ Add to Claude Code ~/.claude.json on the client machine:
|
|||||||
|
|
||||||
"$NAME": {
|
"$NAME": {
|
||||||
"type": "http",
|
"type": "http",
|
||||||
"url": "http://$(hostname -s).local:$PORT/mcp",
|
"url": "http://$(hostname -s).fritz.box:$PORT/mcp",
|
||||||
"headers": { "Authorization": "Bearer $TOKEN" }
|
"headers": { "Authorization": "Bearer $TOKEN" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user