Skip MCP_API_KEY generation in tunnel mode

start.sh previously generated and persisted an MCP_API_KEY to .env
unconditionally on first run. In tunnel mode (POKE_TUNNEL=1, the
default) the local server runs unauthenticated and the Poke tunnel
handles auth — generating a key there is at best useless and at worst
overwrites the user's pre-set key, causing 421 errors at the tunnel.

Move .env loading and POKE_TUNNEL resolution above the generation
block, and skip generation entirely when POKE_TUNNEL=1. Re-source .env
after a successful generation so the rest of the script sees the new
value.

Fixes #9
This commit is contained in:
Kacper Kwapisz
2026-04-29 09:27:59 +02:00
parent a2b859dd89
commit 83a3c482ec
+18 -10
View File
@@ -207,10 +207,23 @@ PYEOF
fi fi
fi fi
# 4. MCP_API_KEY — generate once and persist to .env # ── Load .env early so POKE_TUNNEL is visible to the MCP_API_KEY logic below ──
if [ ! -f .env ] \ if [ -f .env ]; then
set -a
source .env
set +a
fi
# Tunnel-mode detection must happen BEFORE the MCP_API_KEY block: in tunnel
# mode (POKE_TUNNEL=1, the default) the local server runs unauthenticated and
# the tunnel handles auth, so we must NOT generate a key — doing so previously
# overwrote user-supplied keys and broke working setups (issue #9).
POKE_TUNNEL="${POKE_TUNNEL:-1}"
# 4. MCP_API_KEY — generate once and persist to .env (skipped in tunnel mode)
if [ "${POKE_TUNNEL}" != "1" ] && { [ ! -f .env ] \
|| grep -Eq '^[[:space:]]*MCP_API_KEY=your-secret-key-here' .env 2>/dev/null \ || grep -Eq '^[[:space:]]*MCP_API_KEY=your-secret-key-here' .env 2>/dev/null \
|| ! grep -Eq '^[[:space:]]*MCP_API_KEY=.+' .env 2>/dev/null; then || ! grep -Eq '^[[:space:]]*MCP_API_KEY=.+' .env 2>/dev/null; }; then
RANDOM_KEY=$(python3 -c " RANDOM_KEY=$(python3 -c "
import secrets, string import secrets, string
alphabet = string.ascii_letters + string.digits alphabet = string.ascii_letters + string.digits
@@ -233,18 +246,13 @@ PYEOF
fi fi
echo " ✓ MCP_API_KEY generated and saved to .env" echo " ✓ MCP_API_KEY generated and saved to .env"
echo "" echo ""
fi # Re-source so the freshly generated key is visible to the rest of the script
# ── Load .env ─────────────────────────────────────────────────────────────────
if [ -f .env ]; then
set -a set -a
source .env source .env
set +a set +a
fi fi
# ── Tunnel-mode detection ───────────────────────────────────────────────────── # ── Tunnel-mode enforcement ───────────────────────────────────────────────────
POKE_TUNNEL="${POKE_TUNNEL:-1}"
if [ "${POKE_TUNNEL}" != "1" ]; then if [ "${POKE_TUNNEL}" != "1" ]; then
: "${MCP_API_KEY:?MCP_API_KEY is not set — add it to .env or export it}" : "${MCP_API_KEY:?MCP_API_KEY is not set — add it to .env or export it}"
else else