Repository navigation
Expand file tree
/
Copy pathsetup-docker.sh
More file actions
executable file
·390 lines (334 loc) · 14.5 KB
/
Copy pathsetup-docker.sh
File metadata and controls
executable file
·390 lines (334 loc) · 14.5 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
#!/bin/bash
# Exit on any error, undefined variables, and pipe failures
set -euo pipefail
# Modern Docker setup script for Zen MCP Server with Redis
# This script sets up the complete Docker environment including Redis for conversation threading
# Spinner function for long-running operations
show_spinner() {
local pid=$1
local message=$2
local spinner_chars="⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"
local delay=0.1
# Hide cursor
tput civis 2>/dev/null || true
while kill -0 $pid 2>/dev/null; do
for (( i=0; i<${#spinner_chars}; i++ )); do
printf "\r%s %s" "${spinner_chars:$i:1}" "$message"
sleep $delay
if ! kill -0 $pid 2>/dev/null; then
break 2
fi
done
done
# Show cursor and clear line
tput cnorm 2>/dev/null || true
printf "\r"
}
# Function to run command with spinner
run_with_spinner() {
local message=$1
local command=$2
printf "%s" "$message"
eval "$command" >/dev/null 2>&1 &
local pid=$!
show_spinner $pid "$message"
wait $pid
local result=$?
if [ $result -eq 0 ]; then
printf "\r✅ %s\n" "${message#* }"
else
printf "\r❌ %s failed\n" "${message#* }"
return $result
fi
}
# Extract version from config.py
VERSION=$(grep -E '^__version__ = ' config.py 2>/dev/null | sed 's/__version__ = "\(.*\)"/\1/' || echo "unknown")
echo "Setting up Zen MCP Server v$VERSION..."
echo ""
# Get the current working directory (absolute path)
CURRENT_DIR=$(pwd)
# Check if .env already exists
if [ -f .env ]; then
echo "✅ .env file already exists!"
echo ""
else
# Copy from .env.example and customize
if [ ! -f .env.example ]; then
echo "❌ .env.example file not found! This file should exist in the project directory."
exit 1
fi
# Copy .env.example to .env
cp .env.example .env
echo "✅ Created .env from .env.example"
# Customize the API keys if they're set in environment
if [ -n "${GEMINI_API_KEY:-}" ]; then
# Replace the placeholder API key with the actual value
if command -v sed >/dev/null 2>&1; then
sed -i.bak "s/your_gemini_api_key_here/$GEMINI_API_KEY/" .env && rm .env.bak
echo "✅ Updated .env with existing GEMINI_API_KEY from environment"
else
echo "⚠️ Found GEMINI_API_KEY in environment, but sed not available. Please update .env manually."
fi
fi
if [ -n "${OPENAI_API_KEY:-}" ]; then
# Replace the placeholder API key with the actual value
if command -v sed >/dev/null 2>&1; then
sed -i.bak "s/your_openai_api_key_here/$OPENAI_API_KEY/" .env && rm .env.bak
echo "✅ Updated .env with existing OPENAI_API_KEY from environment"
else
echo "⚠️ Found OPENAI_API_KEY in environment, but sed not available. Please update .env manually."
fi
fi
if [ -n "${OPENROUTER_API_KEY:-}" ]; then
# Replace the placeholder API key with the actual value
if command -v sed >/dev/null 2>&1; then
sed -i.bak "s/your_openrouter_api_key_here/$OPENROUTER_API_KEY/" .env && rm .env.bak
echo "✅ Updated .env with existing OPENROUTER_API_KEY from environment"
else
echo "⚠️ Found OPENROUTER_API_KEY in environment, but sed not available. Please update .env manually."
fi
fi
# Update WORKSPACE_ROOT to use current user's home directory
if command -v sed >/dev/null 2>&1; then
sed -i.bak "s|WORKSPACE_ROOT=/Users/your-username|WORKSPACE_ROOT=$HOME|" .env && rm .env.bak
echo "✅ Updated WORKSPACE_ROOT to $HOME"
fi
echo "✅ Created .env file with Redis configuration"
echo ""
fi
# Check if Docker and Docker Compose are installed
if ! command -v docker &> /dev/null; then
echo "❌ Docker is not installed. Please install Docker first."
echo " Visit: https://docs.docker.com/get-docker/"
exit 1
fi
if ! command -v docker-compose &> /dev/null && ! docker compose version &> /dev/null; then
echo "❌ Docker Compose is not installed. Please install Docker Compose first."
echo " Visit: https://docs.docker.com/compose/install/"
exit 1
fi
# Check if Docker daemon is running
if ! docker info &> /dev/null; then
echo "❌ Docker daemon is not running. Please start Docker."
exit 1
fi
# Use modern docker compose syntax if available, fall back to docker-compose
COMPOSE_CMD="docker compose"
if ! docker compose version &> /dev/null; then
COMPOSE_CMD="docker-compose"
fi
# Check if at least one API key or custom URL is properly configured
source .env 2>/dev/null || true
VALID_GEMINI_KEY=false
VALID_OPENAI_KEY=false
VALID_OPENROUTER_KEY=false
VALID_CUSTOM_URL=false
# Check if GEMINI_API_KEY is set and not the placeholder
if [ -n "${GEMINI_API_KEY:-}" ] && [ "$GEMINI_API_KEY" != "your_gemini_api_key_here" ]; then
VALID_GEMINI_KEY=true
echo "✅ GEMINI_API_KEY found"
fi
# Check if OPENAI_API_KEY is set and not the placeholder
if [ -n "${OPENAI_API_KEY:-}" ] && [ "$OPENAI_API_KEY" != "your_openai_api_key_here" ]; then
VALID_OPENAI_KEY=true
echo "✅ OPENAI_API_KEY found"
fi
# Check if OPENROUTER_API_KEY is set and not the placeholder
if [ -n "${OPENROUTER_API_KEY:-}" ] && [ "$OPENROUTER_API_KEY" != "your_openrouter_api_key_here" ]; then
VALID_OPENROUTER_KEY=true
echo "✅ OPENROUTER_API_KEY found"
fi
# Check if CUSTOM_API_URL is set and not empty (custom API key is optional)
if [ -n "${CUSTOM_API_URL:-}" ]; then
VALID_CUSTOM_URL=true
echo "✅ CUSTOM_API_URL found: $CUSTOM_API_URL"
fi
# Require at least one valid API key or custom URL
if [ "$VALID_GEMINI_KEY" = false ] && [ "$VALID_OPENAI_KEY" = false ] && [ "$VALID_OPENROUTER_KEY" = false ] && [ "$VALID_CUSTOM_URL" = false ]; then
echo ""
echo "❌ ERROR: At least one valid API key or custom URL is required!"
echo ""
echo "Please edit the .env file and set at least one of:"
echo " - GEMINI_API_KEY (get from https://makersuite.google.com/app/apikey)"
echo " - OPENAI_API_KEY (get from https://platform.openai.com/api-keys)"
echo " - OPENROUTER_API_KEY (get from https://openrouter.ai/)"
echo " - CUSTOM_API_URL (for local models like Ollama, vLLM, etc.)"
echo ""
echo "Example:"
echo " GEMINI_API_KEY=your-actual-api-key-here"
echo " OPENAI_API_KEY=sk-your-actual-openai-key-here"
echo " OPENROUTER_API_KEY=sk-or-your-actual-openrouter-key-here"
echo " CUSTOM_API_URL=http://host.docker.internal:11434/v1 # Ollama (use host.docker.internal, NOT localhost!)"
echo ""
exit 1
fi
echo ""
# Stop and remove existing containers
run_with_spinner "🛑 Stopping existing docker containers..." "$COMPOSE_CMD down --remove-orphans" || true
# Clean up any old containers with different naming patterns
OLD_CONTAINERS_FOUND=false
# Check for old Gemini MCP containers (for migration)
if docker ps -a --format "{{.Names}}" | grep -q "^gemini-mcp-server-gemini-mcp-1$" 2>/dev/null || false; then
OLD_CONTAINERS_FOUND=true
echo " - Cleaning up old container: gemini-mcp-server-gemini-mcp-1"
docker stop gemini-mcp-server-gemini-mcp-1 >/dev/null 2>&1 || true
docker rm gemini-mcp-server-gemini-mcp-1 >/dev/null 2>&1 || true
fi
if docker ps -a --format "{{.Names}}" | grep -q "^gemini-mcp-server$" 2>/dev/null || false; then
OLD_CONTAINERS_FOUND=true
echo " - Cleaning up old container: gemini-mcp-server"
docker stop gemini-mcp-server >/dev/null 2>&1 || true
docker rm gemini-mcp-server >/dev/null 2>&1 || true
fi
# Check for current old containers (from recent versions)
if docker ps -a --format "{{.Names}}" | grep -q "^gemini-mcp-log-monitor$" 2>/dev/null || false; then
OLD_CONTAINERS_FOUND=true
echo " - Cleaning up old container: gemini-mcp-log-monitor"
docker stop gemini-mcp-log-monitor >/dev/null 2>&1 || true
docker rm gemini-mcp-log-monitor >/dev/null 2>&1 || true
fi
# Check for old Redis container
if docker ps -a --format "{{.Names}}" | grep -q "^gemini-mcp-server-redis-1$" 2>/dev/null || false; then
OLD_CONTAINERS_FOUND=true
echo " - Cleaning up old container: gemini-mcp-server-redis-1"
docker stop gemini-mcp-server-redis-1 >/dev/null 2>&1 || true
docker rm gemini-mcp-server-redis-1 >/dev/null 2>&1 || true
fi
if docker ps -a --format "{{.Names}}" | grep -q "^gemini-mcp-redis$" 2>/dev/null || false; then
OLD_CONTAINERS_FOUND=true
echo " - Cleaning up old container: gemini-mcp-redis"
docker stop gemini-mcp-redis >/dev/null 2>&1 || true
docker rm gemini-mcp-redis >/dev/null 2>&1 || true
fi
# Check for old images
if docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "^gemini-mcp-server-gemini-mcp:latest$" 2>/dev/null || false; then
OLD_CONTAINERS_FOUND=true
echo " - Cleaning up old image: gemini-mcp-server-gemini-mcp:latest"
docker rmi gemini-mcp-server-gemini-mcp:latest >/dev/null 2>&1 || true
fi
if docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "^gemini-mcp-server:latest$" 2>/dev/null || false; then
OLD_CONTAINERS_FOUND=true
echo " - Cleaning up old image: gemini-mcp-server:latest"
docker rmi gemini-mcp-server:latest >/dev/null 2>&1 || true
fi
# Check for current old network (if it exists)
if docker network ls --format "{{.Name}}" | grep -q "^gemini-mcp-server_default$" 2>/dev/null || false; then
OLD_CONTAINERS_FOUND=true
echo " - Cleaning up old network: gemini-mcp-server_default"
docker network rm gemini-mcp-server_default >/dev/null 2>&1 || true
fi
# Only show cleanup messages if something was actually cleaned up
# Build and start services
if ! run_with_spinner "🔨 Building Zen MCP Server image..." "$COMPOSE_CMD build"; then
echo "❌ Failed to build Docker image. Run '$COMPOSE_CMD build' manually to see errors."
exit 1
fi
if ! run_with_spinner "Starting server (Redis + Zen MCP)..." "$COMPOSE_CMD up -d"; then
echo "❌ Failed to start services. Run '$COMPOSE_CMD up -d' manually to see errors."
exit 1
fi
echo "✅ Services started successfully!"
# Function to show configuration steps - only if CLI not already set up
show_configuration_steps() {
echo ""
echo "🔄 Next steps:"
NEEDS_KEY_UPDATE=false
if grep -q "your_gemini_api_key_here" .env 2>/dev/null || grep -q "your_openai_api_key_here" .env 2>/dev/null || grep -q "your_openrouter_api_key_here" .env 2>/dev/null; then
NEEDS_KEY_UPDATE=true
fi
if [ "$NEEDS_KEY_UPDATE" = true ]; then
echo "1. Edit .env and replace placeholder API keys with actual ones"
echo " - GEMINI_API_KEY: your-gemini-api-key-here"
echo " - OPENAI_API_KEY: your-openai-api-key-here"
echo " - OPENROUTER_API_KEY: your-openrouter-api-key-here (optional)"
echo "2. Restart services: $COMPOSE_CMD restart"
echo "3. Copy the configuration below to your Claude Desktop config if required:"
else
echo "1. Copy the configuration below to your Claude Desktop config if required:"
fi
echo ""
echo "===== CLAUDE DESKTOP CONFIGURATION ====="
echo "{"
echo " \"mcpServers\": {"
echo " \"zen\": {"
echo " \"command\": \"docker\","
echo " \"args\": ["
echo " \"exec\","
echo " \"-i\","
echo " \"zen-mcp-server\","
echo " \"python\","
echo " \"server.py\""
echo " ]"
echo " }"
echo " }"
echo "}"
echo "==========================================="
}
# Function to automatically configure Claude Code CLI
# Returns: 0 if already configured, 1 if CLI not found, 2 if configured/skipped
setup_claude_code_cli() {
# Check if claude command exists
if ! command -v claude &> /dev/null; then
echo "⚠️ Claude Code CLI not found. Install it to use with CLI:"
echo " npm install -g @anthropic-ai/claude-code"
echo ""
echo "📋 Manual MCP configuration for Claude Code CLI:"
echo "claude mcp add zen -s user -- docker exec -i zen-mcp-server python server.py"
return 1
fi
# Get current MCP list and check if zen-mcp-server already exists
if claude mcp list 2>/dev/null | grep -q "zen-mcp-server" 2>/dev/null; then
echo ""
return 0 # Already configured
else
echo ""
echo "🔧 Configuring Claude Code CLI..."
echo ""
echo -n "Would you like to add the Zen MCP Server to Claude Code CLI now? [Y/n]: "
read -r response
# Default to yes if empty response (just pressed enter)
if [[ -z "$response" || "$response" =~ ^[Yy]$ ]]; then
echo " - Adding Zen MCP Server to Claude Code CLI..."
if claude mcp add zen -s user -- docker exec -i zen-mcp-server python server.py >/dev/null 2>&1; then
echo "✅ Zen MCP Server added to Claude Code CLI successfully!"
echo " Use 'claude' command to start a session with the MCP server"
else
echo "⚠️ Failed to add MCP server automatically. You can add it manually:"
echo " claude mcp add zen -s user -- docker exec -i zen-mcp-server python server.py"
fi
else
echo " - Skipped adding MCP server. You can add it manually later:"
echo " claude mcp add zen -s user -- docker exec -i zen-mcp-server python server.py"
fi
echo ""
return 2 # Configured or skipped
fi
}
# Set up Claude Code CLI automatically
setup_claude_code_cli
CLI_STATUS=$?
# Only show configuration details if zen is NOT already configured
if [ $CLI_STATUS -ne 0 ]; then
# Show configuration steps
show_configuration_steps
echo ""
echo "===== CLAUDE CODE CLI CONFIGURATION ====="
echo "# Useful Claude Code CLI commands:"
echo "claude # Start interactive session"
echo "claude mcp list # List your MCP servers"
echo "claude mcp remove zen -s user # Remove if needed"
echo "==========================================="
echo ""
echo "📁 Config file locations:"
echo " macOS: ~/Library/Application Support/Claude/claude_desktop_config.json"
echo ' Windows (WSL): /mnt/c/Users/USERNAME/AppData/Roaming/Claude/claude_desktop_config.json'
echo ""
fi
echo "🔧 Useful commands:"
echo " Start services: $COMPOSE_CMD up -d"
echo " Stop services: $COMPOSE_CMD down"
echo " View logs: $COMPOSE_CMD logs -f"
echo " Restart services: $COMPOSE_CMD restart"
echo " Service status: $COMPOSE_CMD ps"
echo ""
echo "Happy Clauding!"