-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·197 lines (171 loc) · 6.56 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·197 lines (171 loc) · 6.56 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
#!/usr/bin/env bash
set -euo pipefail
# ─── Colors & helpers ────────────────────────────────────────────
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
DIM='\033[2m'
NC='\033[0m'
info() { printf " ${GREEN}✓${NC} %s\n" "$1"; }
warn() { printf " ${YELLOW}!${NC} %s\n" "$1"; }
fail() { printf "\n ${RED}✗${NC} %s\n\n" "$1"; exit 1; }
ask() { printf " ${CYAN}?${NC} %s" "$1"; }
# ─── Header ──────────────────────────────────────────────────────
echo ""
printf " ${BOLD}WrenAI MCP — Claude Code Installer${NC}\n"
echo " ==================================="
echo ""
# ─── Guard: needs interactive terminal ───────────────────────────
if [ ! -t 0 ]; then
fail "Interactive terminal required.
Run: bash <(curl -fsSL https://raw.githubusercontent.com/canner/wrenai-mcp/main/install.sh)"
fi
# ─── Step 1: Node.js ────────────────────────────────────────────
printf " ${BOLD}[1/4] Checking Node.js ...${NC}\n"
NODE_CMD=""
if command -v node &>/dev/null; then
NODE_VERSION=$(node -v | sed 's/v//')
MAJOR=$(echo "$NODE_VERSION" | cut -d. -f1)
if [ "$MAJOR" -ge 18 ]; then
NODE_CMD=$(command -v node)
info "Node.js v${NODE_VERSION} — ${DIM}${NODE_CMD}${NC}"
else
fail "Node.js v${NODE_VERSION} found but >= 18 is required.
Install: https://nodejs.org"
fi
else
fail "Node.js not found.
Install Node.js 18+: https://nodejs.org"
fi
# ─── Step 2: Locate repo ────────────────────────────────────────
echo ""
printf " ${BOLD}[2/4] Locating wrenai-mcp ...${NC}\n"
REPO_DIR=""
# Try: script's own directory (./install.sh)
SCRIPT_DIR=""
if [ -n "${BASH_SOURCE[0]:-}" ]; then
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd)" || true
fi
if [ -n "$SCRIPT_DIR" ] && [ -f "$SCRIPT_DIR/mcp-proxy.mjs" ]; then
REPO_DIR="$SCRIPT_DIR"
fi
# Try: current directory
if [ -z "$REPO_DIR" ] && [ -f "$(pwd)/mcp-proxy.mjs" ]; then
REPO_DIR="$(pwd)"
fi
# Try: ./wrenai-mcp subdirectory
if [ -z "$REPO_DIR" ] && [ -f "$(pwd)/wrenai-mcp/mcp-proxy.mjs" ]; then
REPO_DIR="$(pwd)/wrenai-mcp"
fi
if [ -n "$REPO_DIR" ]; then
info "Found at ${REPO_DIR}"
else
warn "Not found in current directory."
echo ""
echo " 1) Clone into ./wrenai-mcp ${DIM}(recommended)${NC}"
echo " 2) Enter path to existing clone"
echo ""
ask "Choose [1/2] (default 1): "
read -r REPO_CHOICE
REPO_CHOICE="${REPO_CHOICE:-1}"
if [ "$REPO_CHOICE" = "2" ]; then
ask "Path: "
read -r CUSTOM_PATH
CUSTOM_PATH="${CUSTOM_PATH/#\~/$HOME}"
CUSTOM_PATH="${CUSTOM_PATH%/}"
[ -f "$CUSTOM_PATH/mcp-proxy.mjs" ] || fail "mcp-proxy.mjs not found at ${CUSTOM_PATH}"
REPO_DIR="$CUSTOM_PATH"
else
echo ""
echo " Cloning ..."
git clone --depth 1 https://github.com/canner/wrenai-mcp.git "$(pwd)/wrenai-mcp"
REPO_DIR="$(pwd)/wrenai-mcp"
fi
info "Repository at ${REPO_DIR}"
fi
PROXY_PATH="${REPO_DIR}/mcp-proxy.mjs"
# Final check: mcp-proxy.mjs must exist
if [ ! -f "$PROXY_PATH" ]; then
fail "mcp-proxy.mjs not found at ${PROXY_PATH}
The repo may be incomplete. Try re-cloning:
git clone https://github.com/canner/wrenai-mcp.git"
fi
info "Proxy: ${DIM}${PROXY_PATH}${NC}"
# ─── Step 3: Credentials ────────────────────────────────────────
echo ""
printf " ${BOLD}[3/4] WrenAI credentials${NC}\n"
echo ""
printf " Open ${CYAN}WrenAI → Settings → API${NC} to find:\n"
echo " • MCP URL — looks like https://app.getwren.ai/api/mcp/cm..."
echo " • API Key — create one under API Keys"
echo ""
ask "MCP endpoint URL: "
read -r MCP_URL
[ -n "$MCP_URL" ] || fail "MCP URL is required."
echo ""
ask "API Key (input hidden): "
read -rs API_KEY
echo ""
[ -n "$API_KEY" ] || fail "API Key is required."
# Show masked key for confirmation
MASKED="${API_KEY:0:4}...${API_KEY: -4}"
printf " ${DIM} → key: %s${NC}\n" "$MASKED"
# ─── Step 4: Configure ──────────────────────────────────────────
echo ""
printf " ${BOLD}[4/4] Configuring Claude Code ...${NC}\n"
echo ""
echo " 1) Global — available in all projects ${DIM}(recommended)${NC}"
echo " 2) Project — only in current directory"
echo ""
ask "Scope [1/2] (default 1): "
read -r SCOPE_CHOICE
SCOPE_CHOICE="${SCOPE_CHOICE:-1}"
if [ "$SCOPE_CHOICE" = "2" ]; then
SCOPE="project"
else
SCOPE="user"
fi
if command -v claude &>/dev/null; then
# Use the official CLI — handles config merging automatically
claude mcp remove wrenai --scope "$SCOPE" 2>/dev/null || true
claude mcp add wrenai --scope "$SCOPE" -t stdio -- \
"$NODE_CMD" "$PROXY_PATH" "$MCP_URL" "$API_KEY"
info "MCP server registered ${DIM}(scope: ${SCOPE})${NC}"
else
# Fallback: write .mcp.json with proper merging
warn "'claude' CLI not in PATH — writing .mcp.json instead"
if [ "$SCOPE" = "project" ]; then
CONFIG_FILE="$(pwd)/.mcp.json"
else
mkdir -p "$HOME/.claude"
CONFIG_FILE="$HOME/.claude/.mcp.json"
fi
# Use Node.js for safe JSON merging (handles special chars in API key)
"$NODE_CMD" -e "
const fs = require('fs');
const p = process.argv[1];
let cfg = {};
try { cfg = JSON.parse(fs.readFileSync(p, 'utf8')); } catch {}
cfg.mcpServers = cfg.mcpServers || {};
cfg.mcpServers.wrenai = {
type: 'stdio',
command: process.argv[2],
args: [process.argv[3], process.argv[4], process.argv[5]]
};
fs.writeFileSync(p, JSON.stringify(cfg, null, 2) + '\n');
" "$CONFIG_FILE" "$NODE_CMD" "$PROXY_PATH" "$MCP_URL" "$API_KEY"
info "Config written to ${CONFIG_FILE}"
fi
# ─── Done ────────────────────────────────────────────────────────
echo ""
printf " ${GREEN}${BOLD}Setup complete!${NC}\n"
echo ""
echo " Next steps:"
echo " 1. Restart Claude Code (or open a new session)"
echo " 2. Optionally install the analyst skill:"
printf " ${CYAN}/install canner/wrenai-mcp${NC}\n"
echo " 3. Try it out:"
printf " ${CYAN}/wrenai-analyst tell me about my data${NC}\n"
echo ""