forked from RafaelCartenet/mcp-databricks-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.command
More file actions
executable file
·212 lines (181 loc) · 5.73 KB
/
setup.command
File metadata and controls
executable file
·212 lines (181 loc) · 5.73 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
#!/bin/bash
# Databricks MCP Server Setup for Cursor
# Double-click this file to install
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo ""
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} Databricks MCP Server Setup${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
# Get the directory where this script lives
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
MAIN_PY="$SCRIPT_DIR/main.py"
REQUIREMENTS="$SCRIPT_DIR/requirements.txt"
# Pre-configured values (same for all users)
DATABRICKS_HOST="dbc-d4dec202-4d5d.cloud.databricks.com"
DATABRICKS_WAREHOUSE_ID="dcb0351ff6ce7e58"
# Cursor config location
CURSOR_DIR="$HOME/.cursor"
MCP_JSON="$CURSOR_DIR/mcp.json"
# Check if main.py exists
if [ ! -f "$MAIN_PY" ]; then
echo -e "${RED}Error: main.py not found at $MAIN_PY${NC}"
echo "Make sure you're running this from the mcp-databricks-server folder."
echo ""
read -p "Press Enter to exit..."
exit 1
fi
# Find Python 3.10+ (check brew paths first, then system python3)
echo -e "${YELLOW}Checking Python...${NC}"
PYTHON_CMD=""
for candidate in /opt/homebrew/bin/python3 /usr/local/bin/python3 python3; do
if command -v "$candidate" &> /dev/null; then
MINOR=$("$candidate" -c "import sys; print(sys.version_info.minor)" 2>/dev/null || echo "0")
if [ "$MINOR" -ge 10 ]; then
PYTHON_CMD="$candidate"
break
fi
fi
done
if [ -z "$PYTHON_CMD" ]; then
FOUND_VERSION=$(python3 --version 2>/dev/null || echo "None")
echo -e "${RED}Error: Python 3.10 or newer is required, but found: $FOUND_VERSION${NC}"
echo ""
echo "To install a newer version:"
echo " Option 1: brew install python"
echo " Option 2: Download from https://www.python.org/downloads/"
echo ""
echo "After installing, verify with: python3 --version"
echo ""
read -p "Press Enter to exit..."
exit 1
fi
PYTHON_VERSION=$("$PYTHON_CMD" --version)
echo -e "${GREEN}Found: $PYTHON_VERSION ($PYTHON_CMD)${NC}"
echo ""
# Create virtual environment and install dependencies
VENV_DIR="$SCRIPT_DIR/.venv"
# Remove stale venv if it was created with an older Python
if [ -d "$VENV_DIR" ]; then
VENV_MINOR=$("$VENV_DIR/bin/python" -c "import sys; print(sys.version_info.minor)" 2>/dev/null || echo "0")
if [ "$VENV_MINOR" -lt 10 ]; then
echo -e "${YELLOW}Removing old virtual environment (Python 3.$VENV_MINOR)...${NC}"
rm -rf "$VENV_DIR"
fi
fi
echo -e "${YELLOW}Setting up virtual environment...${NC}"
if command -v uv &> /dev/null; then
echo "Using uv (fast)..."
uv venv "$VENV_DIR" --quiet 2>/dev/null || uv venv "$VENV_DIR"
uv pip install -r "$REQUIREMENTS" --quiet -p "$VENV_DIR"
else
echo "Using pip..."
"$PYTHON_CMD" -m venv "$VENV_DIR"
"$VENV_DIR/bin/pip" install -r "$REQUIREMENTS" --quiet
fi
# Use the venv's python for running the server
VENV_PYTHON="$VENV_DIR/bin/python"
echo -e "${GREEN}Dependencies installed!${NC}"
echo ""
# Prompt for Databricks token
echo -e "${YELLOW}You'll need your Databricks Personal Access Token.${NC}"
echo "To create one: Databricks UI → User Settings → Developer → Access Tokens"
echo ""
read -p "Paste your Databricks token here: " DATABRICKS_TOKEN
if [ -z "$DATABRICKS_TOKEN" ]; then
echo -e "${RED}Error: No token provided.${NC}"
echo ""
read -p "Press Enter to exit..."
exit 1
fi
# Validate token format (basic check)
if [[ ! "$DATABRICKS_TOKEN" =~ ^dapi ]]; then
echo -e "${YELLOW}Warning: Token doesn't start with 'dapi'. Make sure you copied the full token.${NC}"
read -p "Continue anyway? (y/n): " CONTINUE
if [ "$CONTINUE" != "y" ]; then
exit 1
fi
fi
echo ""
echo -e "${YELLOW}Configuring Cursor...${NC}"
# Create .cursor directory if needed
mkdir -p "$CURSOR_DIR"
# Build the new server config
NEW_SERVER_CONFIG=$(cat <<EOF
{
"command": "python3",
"args": ["$MAIN_PY"],
"env": {
"DATABRICKS_HOST": "$DATABRICKS_HOST",
"DATABRICKS_TOKEN": "$DATABRICKS_TOKEN",
"DATABRICKS_SQL_WAREHOUSE_ID": "$DATABRICKS_WAREHOUSE_ID"
}
}
EOF
)
# Check if mcp.json exists and merge, or create new
if [ -f "$MCP_JSON" ]; then
echo "Found existing mcp.json, merging..."
# Check if python3 can parse JSON (use it for merging)
MERGED=$(python3 << PYEOF
import json
import sys
try:
with open('$MCP_JSON', 'r') as f:
config = json.load(f)
except:
config = {}
if 'mcpServers' not in config:
config['mcpServers'] = {}
config['mcpServers']['databricks'] = {
"command": "$VENV_PYTHON",
"args": ["$MAIN_PY"],
"env": {
"DATABRICKS_HOST": "$DATABRICKS_HOST",
"DATABRICKS_TOKEN": "$DATABRICKS_TOKEN",
"DATABRICKS_SQL_WAREHOUSE_ID": "$DATABRICKS_WAREHOUSE_ID"
}
}
print(json.dumps(config, indent=2))
PYEOF
)
echo "$MERGED" > "$MCP_JSON"
else
echo "Creating new mcp.json..."
cat > "$MCP_JSON" << EOF
{
"mcpServers": {
"databricks": {
"command": "$VENV_PYTHON",
"args": ["$MAIN_PY"],
"env": {
"DATABRICKS_HOST": "$DATABRICKS_HOST",
"DATABRICKS_TOKEN": "$DATABRICKS_TOKEN",
"DATABRICKS_SQL_WAREHOUSE_ID": "$DATABRICKS_WAREHOUSE_ID"
}
}
}
}
EOF
fi
echo -e "${GREEN}Cursor configured!${NC}"
echo ""
# Success message
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN} Setup Complete!${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
echo "Next steps:"
echo " 1. Quit Cursor completely (Cmd+Q)"
echo " 2. Reopen Cursor"
echo " 3. Try asking: \"List my Databricks catalogs\""
echo ""
echo -e "${BLUE}Config saved to: $MCP_JSON${NC}"
echo ""
read -p "Press Enter to close..."