3 Commits

Author SHA1 Message Date
RNL
4cf7d0114d added mcp server setup guide 2026-08-31 23:35:02 +10:00
RNL
6c16e66add fixed CSRF_TRUSTED_ORIGINS not set when setup 2026-08-31 22:55:23 +10:00
RNL
6f681f8083 added verbose arg for verbose install 2026-08-31 22:29:27 +10:00
4 changed files with 70 additions and 13 deletions

View File

@@ -304,7 +304,15 @@ Bambu-Run exposes printer status, print history, and filament inventory as
read-only [MCP](https://modelcontextprotocol.io/) tools, so an AI agent (e.g.
Claude Desktop, Claude Code) can query your printer directly.
Install the extra:
**Native install (`setup.sh`):** if you declined MCP during setup (or ran
`setup.sh` before MCP support existed), enable it any time with:
```bash
./native/bambu-run.sh enable-mcp # install deps, create + start the systemd service
./native/bambu-run.sh disable-mcp # stop and remove it
```
**Manual / library install:** install the extra:
```bash
pip install 'bambu-run[mcp]'

View File

@@ -37,6 +37,38 @@ case "${1:-help}" in
fi
journalctl --user $JOURNAL_UNITS -f --no-hostname
;;
enable-mcp)
if [ -f "$SERVICE_DIR/bambu-run-mcp.service" ]; then
echo "MCP server already enabled."
else
echo "Installing MCP dependencies..."
"$VENV_DIR/bin/pip" install --quiet ".[mcp]"
sed "s|{{REPO_DIR}}|$REPO_DIR|g; s|{{VENV_DIR}}|$VENV_DIR|g" \
"$REPO_DIR/native/bambu-run-mcp.service" > "$SERVICE_DIR/bambu-run-mcp.service"
systemctl --user daemon-reload
systemctl --user enable bambu-run-mcp.service
systemctl --user start bambu-run-mcp.service
PI_IP=$(hostname -I 2>/dev/null | awk '{print $1}')
echo "MCP server enabled on port 8808."
echo
echo " Claude Desktop config:"
echo " {\"mcpServers\":{\"bambu-run\":{\"url\":\"http://${PI_IP:-localhost}:8808/sse\"}}}"
fi
;;
disable-mcp)
if [ ! -f "$SERVICE_DIR/bambu-run-mcp.service" ]; then
echo "MCP server is not enabled."
else
systemctl --user stop bambu-run-mcp.service 2>/dev/null || true
systemctl --user disable bambu-run-mcp.service 2>/dev/null || true
rm -f "$SERVICE_DIR/bambu-run-mcp.service"
systemctl --user daemon-reload
echo "MCP server disabled."
fi
;;
update)
echo "Pulling latest code..."
cd "$REPO_DIR" && git pull
@@ -60,7 +92,7 @@ case "${1:-help}" in
echo "Update complete."
;;
help|*)
echo "Usage: $0 {start|stop|restart|status|logs|update}"
echo "Usage: $0 {start|stop|restart|status|logs|update|enable-mcp|disable-mcp}"
echo
echo " start Start web + collector services"
echo " stop Stop web + collector services"
@@ -68,5 +100,7 @@ case "${1:-help}" in
echo " status Show service status"
echo " logs Tail live logs (Ctrl+C to stop)"
echo " update Pull latest code, install deps, migrate, restart"
echo " enable-mcp Install and start the MCP server for AI agent access"
echo " disable-mcp Stop and remove the MCP server service"
;;
esac

View File

@@ -1,8 +1,21 @@
#!/usr/bin/env bash
# Bambu-Run Native Setup — single entry point for Raspberry Pi (or any Linux)
# Usage: git clone ... && cd Bambu-Run && bash setup.sh
# Usage: git clone ... && cd Bambu-Run && bash setup.sh [-v|--verbose]
# -v, --verbose show full pip install output instead of --quiet
set -euo pipefail
VERBOSE=0
for arg in "$@"; do
case "$arg" in
-v|--verbose) VERBOSE=1 ;;
esac
done
PIP_QUIET_FLAG="--quiet"
if [ "$VERBOSE" -eq 1 ]; then
PIP_QUIET_FLAG=""
fi
REPO_DIR="$(cd "$(dirname "$0")" && pwd)"
VENV_DIR="$REPO_DIR/.venv"
ENV_FILE="$REPO_DIR/.env"
@@ -98,8 +111,8 @@ else:
print(' opencv stub already exists')
"
"$VENV_DIR/bin/pip" install --quiet --upgrade pip
"$VENV_DIR/bin/pip" install --quiet ".[standalone]"
"$VENV_DIR/bin/pip" install $PIP_QUIET_FLAG --upgrade pip
"$VENV_DIR/bin/pip" install $PIP_QUIET_FLAG ".[standalone]"
# ── 3. Interactive .env ───────────────────────────────────────────────────────
@@ -208,7 +221,7 @@ MCP_ENABLED=false
read -rp "Enable MCP server for AI agent access (Claude Desktop, Claude Code, etc.)? [y/N] " ENABLE_MCP
if [[ "$ENABLE_MCP" =~ ^[Yy] ]]; then
green "Installing MCP dependencies..."
"$VENV_DIR/bin/pip" install --quiet ".[mcp]"
"$VENV_DIR/bin/pip" install $PIP_QUIET_FLAG ".[mcp]"
sed "s|{{REPO_DIR}}|$REPO_DIR|g; s|{{VENV_DIR}}|$VENV_DIR|g" \
"$REPO_DIR/native/bambu-run-mcp.service" > "$SERVICE_DIR/bambu-run-mcp.service"

View File

@@ -124,7 +124,9 @@ PRINTER_IP = os.environ.get("PRINTER_IP", "")
ACCESS_TOKEN = os.environ.get("ACCESS_TOKEN", "")
PRINTER_SERIAL = os.environ.get("PRINTER_SERIAL", "")
CSRF_TRUSTED_ORIGINS = os.environ.get("CSRF_TRUSTED_ORIGINS", "").split(",")
CSRF_TRUSTED_ORIGINS = [
origin for origin in os.environ.get("CSRF_TRUSTED_ORIGINS", "").split(",") if origin
]
# Logging
LOGGING = {