#!/usr/bin/env bash
# Real demos for P168 "MCP Servers: Full Tutorial for Beginners". Made on the Mac (Docker Desktop + Claude Code).
# Maple Street Motors, a used car lot. Two containers from stock Ubuntu 24.04 (lab/Dockerfile) on one network:
#   office: the lot's office PC, where Linda builds the MCP server (uv is installed on camera);
#   sales:  the sales desk PC Rob uses, with Node.js for the MCP Inspector, to reach the office PC over the network.
# Linda's laptop is this Mac: Claude Code (on its plan login, never an API key) and the MCP Inspector's web page run
# here, in ~/mcp-lab/car-lot, a copy of the same project folder. Every command is typed into a real interactive bash
# in a pty (demo_driver.py); every error, answer and time is real.
set -euo pipefail
cd "$(dirname "$0")"
P=ce-p168
cleanup() {
  docker rm -f -v $P-office $P-sales >/dev/null 2>&1 || true
  docker network rm $P-net >/dev/null 2>&1 || true
  pkill -f "modelcontextprotocol/inspector" 2>/dev/null || true
}
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
docker build -q -t $P-office --target office lab >/dev/null
docker build -q -t $P-sales --target sales lab >/dev/null
docker network create $P-net >/dev/null
docker run -d --name $P-office --hostname office --network $P-net --network-alias office $P-office >/dev/null
docker run -d --name $P-sales --hostname sales-desk --network $P-net $P-sales >/dev/null
[ -n "${NODRIVER:-}" ] || python3 demo_driver.py $P
