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
·184 lines (157 loc) · 4.7 KB
/
setup.command
File metadata and controls
executable file
·184 lines (157 loc) · 4.7 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
#!/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
# Check Python 3
echo -e "${YELLOW}Checking Python...${NC}"
if ! command -v python3 &> /dev/null; then
echo -e "${RED}Error: Python 3 is not installed.${NC}"
echo "Please install Python 3 from https://www.python.org/downloads/"
echo ""
read -p "Press Enter to exit..."
exit 1
fi
PYTHON_VERSION=$(python3 --version)
echo -e "${GREEN}Found: $PYTHON_VERSION${NC}"
echo ""
# Create virtual environment and install dependencies
VENV_DIR="$SCRIPT_DIR/.venv"
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..."
python3 -m venv "$VENV_DIR"
"$VENV_DIR/bin/pip" install -r "$REQUIREMENTS" --quiet
fi
# Use the venv's python for running the server
PYTHON_CMD="$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": "$PYTHON_CMD",
"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": "$PYTHON_CMD",
"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..."