-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart_cloud.sh
More file actions
executable file
·129 lines (109 loc) · 3.79 KB
/
start_cloud.sh
File metadata and controls
executable file
·129 lines (109 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env bash
# Start SPICEBridge MCP server with a named Cloudflare tunnel for cloud access.
#
# Permanent URL: https://spicebridge.clanker-lover.work/mcp
#
# Usage:
# ./start_cloud.sh # default port 8000
# PORT=9000 ./start_cloud.sh # custom port
set -euo pipefail
PORT="${PORT:-8000}"
HOST="${HOST:-127.0.0.1}"
TRANSPORT="${TRANSPORT:-streamable-http}"
# --- Preflight checks ---
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$SCRIPT_DIR"
VENV_PYTHON="$PROJECT_DIR/.venv/bin/python"
if [ ! -x "$VENV_PYTHON" ]; then
echo "ERROR: Virtual environment not found at $PROJECT_DIR/.venv"
echo " Run: python -m venv .venv && .venv/bin/pip install -e '.[dev]'"
exit 1
fi
if ! command -v cloudflared &>/dev/null; then
echo "ERROR: cloudflared not found on PATH"
echo ""
echo "Install options:"
echo " Debian/Ubuntu: curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null"
echo " echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared $(lsb_release -cs) main' | sudo tee /etc/apt/sources.list.d/cloudflared.list"
echo " sudo apt update && sudo apt install cloudflared"
echo ""
echo " Binary: https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/"
exit 1
fi
# Check for cloudflared config
if [ ! -f "$HOME/.cloudflared/config.yml" ]; then
echo "ERROR: Cloudflare tunnel config not found at ~/.cloudflared/config.yml"
echo ""
echo "Run the setup wizard to create one:"
echo " spicebridge setup-cloud"
echo ""
echo "Or for a quick tunnel (no config needed):"
echo " spicebridge setup-cloud --quick"
exit 1
fi
# --- API key generation ---
if [ -z "${SPICEBRIDGE_API_KEY:-}" ]; then
SPICEBRIDGE_API_KEY=$("$VENV_PYTHON" -c "import secrets; print(secrets.token_urlsafe(32))")
echo "Generated API key: $SPICEBRIDGE_API_KEY"
fi
export SPICEBRIDGE_API_KEY
# --- Cleanup on exit ---
SERVER_PID=""
TUNNEL_PID=""
cleanup() {
echo ""
echo "Shutting down..."
[ -n "$TUNNEL_PID" ] && kill "$TUNNEL_PID" 2>/dev/null || true
[ -n "$SERVER_PID" ] && kill "$SERVER_PID" 2>/dev/null || true
wait 2>/dev/null || true
echo "Done."
}
trap cleanup EXIT INT TERM
# --- Start MCP server ---
echo "Starting SPICEBridge MCP server on $HOST:$PORT ($TRANSPORT)..."
FASTMCP_PORT="$PORT" FASTMCP_HOST="$HOST" "$VENV_PYTHON" -m spicebridge --transport "$TRANSPORT" &
SERVER_PID=$!
# Wait for server to be ready
echo "Waiting for server..."
for i in $(seq 1 30); do
if curl -sf -H "Authorization: Bearer $SPICEBRIDGE_API_KEY" "http://$HOST:$PORT/mcp" -o /dev/null --max-time 1 2>/dev/null; then
echo "Server ready."
break
fi
if ! kill -0 "$SERVER_PID" 2>/dev/null; then
echo "ERROR: Server process exited unexpectedly."
exit 1
fi
sleep 0.5
done
# --- Start Cloudflare tunnel ---
echo "Starting Cloudflare named tunnel..."
cloudflared tunnel run spicebridge &
TUNNEL_PID=$!
sleep 3
TUNNEL_URL="https://spicebridge.clanker-lover.work"
echo ""
echo "========================================="
echo " SPICEBridge cloud MCP server is running"
echo "========================================="
echo ""
echo "Permanent URL: $TUNNEL_URL/mcp"
echo "API Key: $SPICEBRIDGE_API_KEY"
echo ""
echo "MCP client config (add to your client's settings):"
echo ""
echo " {"
echo " \"mcpServers\": {"
echo " \"spicebridge\": {"
echo " \"url\": \"$TUNNEL_URL/mcp\","
echo " \"headers\": {"
echo " \"Authorization\": \"Bearer $SPICEBRIDGE_API_KEY\""
echo " }"
echo " }"
echo " }"
echo " }"
echo ""
echo "Press Ctrl+C to stop."
echo ""
# Wait for either process to exit
wait