-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·446 lines (382 loc) · 13.2 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·446 lines (382 loc) · 13.2 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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
#!/usr/bin/env bash
#
# install.sh -- Setup helper for ocis-mcp-server
#
# Detects your OS, checks for required tools (Go, Docker, Claude Desktop,
# Ollama, mcphost), and offers to build the server and write config files.
#
# Safe: always asks before writing anything. Works on macOS, Linux, and WSL.
set -euo pipefail
# ─── Colors ───────────────────────────────────────────────────────────────────
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
BOLD='\033[1m'
NC='\033[0m' # No Color
ok() { printf "${GREEN}[OK]${NC} %s\n" "$1"; }
warn() { printf "${YELLOW}[MISS]${NC} %s\n" "$1"; }
info() { printf "${BLUE}[INFO]${NC} %s\n" "$1"; }
err() { printf "${RED}[ERR]${NC} %s\n" "$1"; }
ask_yes_no() {
local prompt="$1"
local answer
printf "${BOLD}%s [y/N]: ${NC}" "$prompt"
read -r answer
case "$answer" in
[yY]|[yY][eE][sS]) return 0 ;;
*) return 1 ;;
esac
}
# ─── Detect OS ────────────────────────────────────────────────────────────────
detect_os() {
case "$(uname -s)" in
Darwin)
OS="macos"
;;
Linux)
if grep -qiE '(microsoft|wsl)' /proc/version 2>/dev/null; then
OS="wsl"
else
OS="linux"
fi
;;
MINGW*|MSYS*|CYGWIN*)
OS="windows"
;;
*)
OS="unknown"
;;
esac
}
# ─── Claude Desktop config path per OS ────────────────────────────────────────
claude_config_path() {
case "$OS" in
macos)
echo "$HOME/Library/Application Support/Claude/claude_desktop_config.json"
;;
linux|wsl)
echo "$HOME/.config/Claude/claude_desktop_config.json"
;;
windows)
echo "$APPDATA/Claude/claude_desktop_config.json"
;;
*)
echo ""
;;
esac
}
# ─── mcphost config path ─────────────────────────────────────────────────────
mcphost_config_path() {
echo "$HOME/.mcphost/config.json"
}
# ─── Check tools ──────────────────────────────────────────────────────────────
HAS_GO=false
HAS_DOCKER=false
HAS_CLAUDE=false
HAS_OLLAMA=false
HAS_MCPHOST=false
HAS_BINARY=false
check_tools() {
echo ""
printf "${BOLD}Checking your system...${NC}\n"
echo ""
# OS
detect_os
case "$OS" in
macos) info "Operating system: macOS" ;;
linux) info "Operating system: Linux" ;;
wsl) info "Operating system: Windows (WSL)" ;;
windows) info "Operating system: Windows (Git Bash / MSYS)" ;;
*) warn "Operating system: unknown ($(uname -s))" ;;
esac
echo ""
# Go
if command -v go &>/dev/null; then
local go_version
go_version=$(go version | awk '{print $3}' | sed 's/go//')
ok "Go is installed (version $go_version)"
HAS_GO=true
else
warn "Go is not installed -- get it from https://go.dev/dl/"
fi
# Docker
if command -v docker &>/dev/null; then
ok "Docker is installed"
HAS_DOCKER=true
else
warn "Docker is not installed -- get it from https://docs.docker.com/get-docker/"
fi
# Claude Desktop
case "$OS" in
macos)
if [ -d "/Applications/Claude.app" ]; then
ok "Claude Desktop is installed"
HAS_CLAUDE=true
else
warn "Claude Desktop is not installed -- get it from https://claude.ai/download"
fi
;;
linux|wsl)
if command -v claude-desktop &>/dev/null || \
[ -f "/usr/bin/claude-desktop" ] || \
[ -f "$HOME/.local/bin/claude-desktop" ] || \
snap list claude-desktop &>/dev/null 2>&1 || \
flatpak list 2>/dev/null | grep -qi claude; then
ok "Claude Desktop is installed"
HAS_CLAUDE=true
else
warn "Claude Desktop is not found -- check https://claude.ai/download"
fi
;;
windows)
if [ -f "$LOCALAPPDATA/Programs/claude-desktop/Claude.exe" ] 2>/dev/null || \
[ -f "$PROGRAMFILES/Claude/Claude.exe" ] 2>/dev/null; then
ok "Claude Desktop is installed"
HAS_CLAUDE=true
else
warn "Claude Desktop not detected -- get it from https://claude.ai/download"
fi
;;
*)
warn "Cannot detect Claude Desktop on this OS"
;;
esac
# Ollama
if command -v ollama &>/dev/null; then
ok "Ollama is installed"
HAS_OLLAMA=true
else
warn "Ollama is not installed -- get it from https://ollama.com/"
fi
# mcphost
if command -v mcphost &>/dev/null; then
ok "mcphost is installed"
HAS_MCPHOST=true
else
warn "mcphost is not installed -- run: go install github.com/mark3labs/mcphost@latest"
fi
# ocis-mcp-server binary
if [ -f "./ocis-mcp-server" ] || [ -f "./bin/ocis-mcp-server" ]; then
ok "ocis-mcp-server binary found"
HAS_BINARY=true
elif [ -f "./ocis-mcp-server.exe" ] || [ -f "./bin/ocis-mcp-server.exe" ]; then
ok "ocis-mcp-server.exe binary found"
HAS_BINARY=true
else
warn "ocis-mcp-server binary not built yet"
fi
echo ""
}
# ─── Build ────────────────────────────────────────────────────────────────────
build_server() {
if [ "$HAS_BINARY" = true ]; then
info "Binary already exists. Skipping build."
return
fi
if [ "$HAS_GO" = false ]; then
info "Go is not installed, cannot build from source."
if [ "$HAS_DOCKER" = true ]; then
info "You can use Docker instead. See the README for Docker instructions."
fi
return
fi
if ask_yes_no "Build ocis-mcp-server from source?"; then
echo ""
info "Building..."
if go build -o ocis-mcp-server ./cmd/ocis-mcp-server; then
ok "Built successfully: $(pwd)/ocis-mcp-server"
HAS_BINARY=true
else
err "Build failed. Check the error messages above."
fi
fi
}
# ─── Prompt for credentials ──────────────────────────────────────────────────
OCIS_URL=""
TOKEN_USER=""
TOKEN_VALUE=""
SERVER_PATH=""
ask_credentials() {
echo ""
printf "${BOLD}Let's set up your oCIS connection.${NC}\n"
echo ""
printf "Enter your oCIS server URL (e.g. https://ocis.example.com): "
read -r OCIS_URL
if [ -z "$OCIS_URL" ]; then
err "oCIS URL is required. Skipping config setup."
return 1
fi
printf "Enter your app token username (e.g. admin): "
read -r TOKEN_USER
if [ -z "$TOKEN_USER" ]; then
err "Username is required. Skipping config setup."
return 1
fi
printf "Enter your app token value: "
read -rs TOKEN_VALUE
echo ""
if [ -z "$TOKEN_VALUE" ]; then
err "Token is required. Skipping config setup."
return 1
fi
# Determine server path
if [ -f "$(pwd)/ocis-mcp-server" ]; then
SERVER_PATH="$(pwd)/ocis-mcp-server"
elif [ -f "$(pwd)/bin/ocis-mcp-server" ]; then
SERVER_PATH="$(pwd)/bin/ocis-mcp-server"
elif [ -f "$(pwd)/ocis-mcp-server.exe" ]; then
SERVER_PATH="$(pwd)/ocis-mcp-server.exe"
else
printf "Enter the full path to ocis-mcp-server binary: "
read -r SERVER_PATH
fi
return 0
}
# ─── Write Claude Desktop config ─────────────────────────────────────────────
write_claude_config() {
if [ "$HAS_CLAUDE" = false ]; then
return
fi
echo ""
local config_file
config_file=$(claude_config_path)
if [ -z "$config_file" ]; then
warn "Could not determine Claude Desktop config path for this OS."
return
fi
if [ -f "$config_file" ]; then
info "Claude Desktop config already exists at: $config_file"
if ! ask_yes_no "Overwrite it?"; then
info "Skipping Claude Desktop config."
return
fi
else
if ! ask_yes_no "Write Claude Desktop config to $config_file?"; then
return
fi
fi
if [ -z "$OCIS_URL" ]; then
if ! ask_credentials; then
return
fi
fi
# Escape backslashes for Windows paths in JSON
local json_path
json_path=$(echo "$SERVER_PATH" | sed 's/\\/\\\\/g')
mkdir -p "$(dirname "$config_file")"
cat > "$config_file" <<JSONEOF
{
"mcpServers": {
"ocis": {
"command": "$json_path",
"env": {
"OCIS_MCP_OCIS_URL": "$OCIS_URL",
"OCIS_MCP_APP_TOKEN_USER": "$TOKEN_USER",
"OCIS_MCP_APP_TOKEN_VALUE": "$TOKEN_VALUE"
}
}
}
}
JSONEOF
ok "Wrote Claude Desktop config to: $config_file"
info "Restart Claude Desktop to pick up the changes."
}
# ─── Write mcphost config ────────────────────────────────────────────────────
write_mcphost_config() {
if [ "$HAS_OLLAMA" = false ]; then
return
fi
echo ""
local config_file
config_file=$(mcphost_config_path)
if [ -f "$config_file" ]; then
info "mcphost config already exists at: $config_file"
if ! ask_yes_no "Overwrite it?"; then
info "Skipping mcphost config."
return
fi
else
if ! ask_yes_no "Write mcphost config to $config_file?"; then
return
fi
fi
if [ -z "$OCIS_URL" ]; then
if ! ask_credentials; then
return
fi
fi
local json_path
json_path=$(echo "$SERVER_PATH" | sed 's/\\/\\\\/g')
mkdir -p "$(dirname "$config_file")"
cat > "$config_file" <<JSONEOF
{
"mcpServers": {
"ocis": {
"command": "$json_path",
"env": {
"OCIS_MCP_OCIS_URL": "$OCIS_URL",
"OCIS_MCP_APP_TOKEN_USER": "$TOKEN_USER",
"OCIS_MCP_APP_TOKEN_VALUE": "$TOKEN_VALUE"
}
}
}
}
JSONEOF
ok "Wrote mcphost config to: $config_file"
if [ "$HAS_MCPHOST" = true ]; then
echo ""
info "You're all set! Run this to start chatting:"
echo ""
echo " mcphost --model ollama:llama3.2"
echo ""
else
echo ""
info "Install mcphost to use Ollama with MCP:"
echo ""
echo " go install github.com/mark3labs/mcphost@latest"
echo " mcphost --model ollama:llama3.2"
echo ""
fi
}
# ─── Summary ──────────────────────────────────────────────────────────────────
print_summary() {
echo ""
printf "${BOLD}────────────────────────────────────${NC}\n"
printf "${BOLD} Setup Complete!${NC}\n"
printf "${BOLD}────────────────────────────────────${NC}\n"
echo ""
if [ "$HAS_CLAUDE" = true ]; then
info "Claude Desktop: Restart the app, then ask Claude about your oCIS files."
fi
if [ "$HAS_OLLAMA" = true ] && [ "$HAS_MCPHOST" = true ]; then
info "Ollama: Run mcphost --model ollama:llama3.2 to start chatting."
fi
echo ""
info "For the full guide, see: GETTING_STARTED.md"
info "For advanced config, see: README.md"
echo ""
}
# ─── Main ─────────────────────────────────────────────────────────────────────
main() {
echo ""
printf "${BOLD}ocis-mcp-server Setup${NC}\n"
printf "${BOLD}=====================${NC}\n"
check_tools
build_server
# Only offer config if at least one client is detected
if [ "$HAS_CLAUDE" = true ] || [ "$HAS_OLLAMA" = true ]; then
write_claude_config
write_mcphost_config
print_summary
else
echo ""
info "No AI client detected (Claude Desktop or Ollama)."
info "Install one of them first, then run this script again."
echo ""
info " Claude Desktop: https://claude.ai/download"
info " Ollama: https://ollama.com/"
echo ""
fi
}
main "$@"