-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
145 lines (131 loc) · 4.61 KB
/
setup.sh
File metadata and controls
145 lines (131 loc) · 4.61 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
#!/bin/bash
set -e
echo "=================================="
echo "Code Review MCP Server Setup"
echo "=================================="
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
IMAGE_NAME="code-review-mcp:latest"
REQUIRED_VARS="LLM_BASE_URL LLM_API_KEY LLM_MODEL"
# Never echo or log these; use safe_display when showing var status
SENSITIVE_VARS="LLM_API_KEY"
# Check if Docker is installed
if ! command -v docker &> /dev/null; then
echo -e "${RED}Error: Docker is not installed${NC}"
echo "Please install Docker from https://docs.docker.com/get-docker/"
exit 1
fi
# Check if Docker Compose is installed (v1 or v2)
if command -v docker-compose &> /dev/null; then
COMPOSE_CMD="docker-compose"
elif docker compose version &> /dev/null; then
COMPOSE_CMD="docker compose"
else
echo -e "${RED}Error: Docker Compose is not installed${NC}"
echo "Please install Docker Compose from https://docs.docker.com/compose/install/"
exit 1
fi
echo -e "${GREEN}✓ Docker and $COMPOSE_CMD found${NC}"
echo ""
# Load .env if it exists (so we can check vars later)
if [ -f .env ]; then
set -a
# shellcheck source=/dev/null
source .env 2>/dev/null || true
set +a
fi
# Returns 0 if all required LLM_* vars are set and non-empty
check_llm_vars() {
for var in $REQUIRED_VARS; do
eval "val=\${$var}"
[ -z "$val" ] && return 1
done
return 0
}
# Safe display for a var: never show API key or other sensitive values
safe_display() {
local var="$1"
case " $SENSITIVE_VARS " in
*" $var "*) echo "[set]" ;;
*) eval "echo \"\${$var}\"" ;;
esac
}
# Ensure we have config: .env with required vars, or LLM_* in environment
if [ ! -f .env ]; then
if check_llm_vars; then
echo "No .env file found, but LLM_* variables are set in the environment."
echo "Creating .env from current environment..."
# Write to .env only; never echo sensitive values to stdout
{
echo "# Generated by setup.sh from environment"
for var in $REQUIRED_VARS PROJECT_DIR; do
eval "val=\${$var}"
if [ -n "$val" ]; then
echo "${var}=${val}"
fi
done
[ -z "$PROJECT_DIR" ] && echo "PROJECT_DIR=./example-project"
} > .env
echo -e "${GREEN}✓ .env created (LLM_BASE_URL, LLM_API_KEY, LLM_MODEL, PROJECT_DIR)${NC}"
else
echo "Creating .env file..."
cp env.example .env
echo -e "${YELLOW}⚠ Please edit .env and set:${NC}"
echo " 1. LLM_BASE_URL - your LLM proxy base URL (OpenAI-compatible)"
echo " 2. LLM_API_KEY - API key for your LLM proxy (sk-KEY)"
echo " 3. LLM_MODEL - model name (e.g. gpt-4, claude-3-sonnet)"
echo " 4. PROJECT_DIR - absolute path to your project directory"
echo ""
read -r -p "Press Enter to open .env in editor (${EDITOR:-nano})..."
"${EDITOR:-nano}" .env
# Re-load so build sees them
set -a
# shellcheck source=/dev/null
source .env 2>/dev/null || true
set +a
if ! check_llm_vars; then
echo -e "${RED}Error: .env is missing required variables (LLM_BASE_URL, LLM_API_KEY, LLM_MODEL)${NC}"
exit 1
fi
fi
else
echo -e "${GREEN}✓ .env file exists${NC}"
if ! check_llm_vars; then
echo -e "${YELLOW}⚠ .env exists but one or more of LLM_BASE_URL, LLM_API_KEY, LLM_MODEL are unset.${NC}"
read -r -p "Open .env to fix? [y/N] " resp
case "$resp" in
[yY]*) "${EDITOR:-nano}" .env ;;
*) echo "Build may fail until .env is configured." ;;
esac
fi
fi
echo ""
# Always build image with no cache so we get a fresh build each time
echo "Building Docker image $IMAGE_NAME (--no-cache)..."
$COMPOSE_CMD build --no-cache
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ Docker image built successfully${NC}"
else
echo -e "${RED}✗ Failed to build Docker image${NC}"
exit 1
fi
echo ""
echo "=================================="
echo "Setup Complete!"
echo "=================================="
echo ""
echo "Next steps:"
echo "1. Verify .env (LLM_BASE_URL, LLM_API_KEY, LLM_MODEL, PROJECT_DIR)"
echo "2. Test the server: $COMPOSE_CMD up"
echo "3. Configure Cursor IDE:"
echo " - Copy cursor-mcp-config.json settings"
echo " - Set LLM_* env vars and workspace path"
echo " - Add to Cursor's MCP server configuration"
echo ""
echo "Local dev (optional): install UV, then uv sync && uv run python src/server.py"
echo "For detailed instructions, see README.md"
echo ""