-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·256 lines (235 loc) · 6.87 KB
/
install.sh
File metadata and controls
executable file
·256 lines (235 loc) · 6.87 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
#!/usr/bin/env bash
set -euo pipefail
REPO="gambletan/cortex"
INSTALL_DIR="${HOME}/.local/bin"
LITE=false
IDE=""
usage() {
cat <<EOF
Usage: install.sh [OPTIONS]
Install cortex-mcp-server from GitHub Releases.
Options:
--lite Download lite version (no embedding model, <5MB)
--ide <target> Auto-configure MCP for IDE: claude|claude-desktop|cursor|windsurf|all
--dir <path> Install directory (default: ~/.local/bin)
-h, --help Show this help
Examples:
curl -fsSL https://github.com/ghraw/${REPO}/main/install.sh | bash
curl -fsSL https://github.com/ghraw/${REPO}/main/install.sh | bash -s -- --ide claude
curl -fsSL https://github.com/ghraw/${REPO}/main/install.sh | bash -s -- --lite --ide all
EOF
exit 0
}
while [[ $# -gt 0 ]]; do
case "$1" in
--lite) LITE=true; shift ;;
--ide) IDE="$2"; shift 2 ;;
--dir) INSTALL_DIR="$2"; shift 2 ;;
-h|--help) usage ;;
*) echo "Unknown option: $1"; usage ;;
esac
done
# Detect OS and architecture
OS="$(uname -s)"
ARCH="$(uname -m)"
case "${OS}" in
Darwin) OS_SUFFIX="darwin" ;;
Linux) OS_SUFFIX="linux" ;;
*) echo "Unsupported OS: ${OS}"; exit 1 ;;
esac
case "${ARCH}" in
arm64|aarch64) ARCH_SUFFIX="arm64" ;;
x86_64) ARCH_SUFFIX="x86_64" ;;
*) echo "Unsupported architecture: ${ARCH}"; exit 1 ;;
esac
SUFFIX="${OS_SUFFIX}-${ARCH_SUFFIX}"
if [ "${LITE}" = true ]; then
TARBALL="cortex-mcp-server-lite-${SUFFIX}.tar.gz"
else
TARBALL="cortex-mcp-server-${SUFFIX}.tar.gz"
fi
# Get latest release tag
echo "Fetching latest release..."
LATEST=$(curl -fsSL "https://github.com/ghapi/repos/${REPO}/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "${LATEST}" ]; then
echo "Failed to fetch latest release. Check https://github.com/${REPO}/releases"
exit 1
fi
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${LATEST}/${TARBALL}"
echo "Downloading ${TARBALL} (${LATEST})..."
mkdir -p "${INSTALL_DIR}"
TMP=$(mktemp -d)
trap "rm -rf ${TMP}" EXIT
curl -fsSL "${DOWNLOAD_URL}" -o "${TMP}/${TARBALL}"
tar xzf "${TMP}/${TARBALL}" -C "${TMP}"
mv "${TMP}/cortex-mcp-server" "${INSTALL_DIR}/cortex-mcp-server"
chmod +x "${INSTALL_DIR}/cortex-mcp-server"
echo "Installed cortex-mcp-server to ${INSTALL_DIR}/cortex-mcp-server"
# Verify install
if "${INSTALL_DIR}/cortex-mcp-server" info >/dev/null 2>&1; then
echo "Verification: OK"
else
echo "Verification: binary runs but info command may need a DB"
fi
# IDE configuration
configure_ide() {
local ide="$1"
local binary="${INSTALL_DIR}/cortex-mcp-server"
local db_path="${HOME}/.cortex/memory.db"
case "${ide}" in
claude)
# Use claude CLI to register MCP server (global scope)
if command -v claude >/dev/null 2>&1; then
claude mcp add cortex-memory --scope user -- "${binary}" "${db_path}" 2>/dev/null && \
echo "Registered cortex-memory MCP server (claude mcp add --scope user)" || \
echo "Warning: 'claude mcp add' failed — register manually: claude mcp add cortex-memory --scope user -- ${binary} ${db_path}"
else
echo "Claude Code CLI not found. Register manually:"
echo " claude mcp add cortex-memory --scope user -- ${binary} ${db_path}"
fi
# Ensure ~/.cortex directory exists
mkdir -p "${HOME}/.cortex"
;;
claude-desktop)
local config_dir
case "$(uname -s)" in
Darwin) config_dir="${HOME}/Library/Application Support/Claude" ;;
*) config_dir="${HOME}/.config/claude" ;;
esac
local config_file="${config_dir}/claude_desktop_config.json"
mkdir -p "${config_dir}"
if [ -f "${config_file}" ]; then
python3 -c "
import json
try:
with open('${config_file}') as f:
config = json.load(f)
except (json.JSONDecodeError, FileNotFoundError):
config = {}
config.setdefault('mcpServers', {})
config['mcpServers']['cortex-memory'] = {
'command': '${binary}',
'args': ['${db_path}']
}
with open('${config_file}', 'w') as f:
json.dump(config, f, indent=2)
print('Configured Claude Desktop MCP: ${config_file}')
"
else
cat > "${config_file}" <<CONF
{
"mcpServers": {
"cortex-memory": {
"command": "${binary}",
"args": ["${db_path}"]
}
}
}
CONF
echo "Created Claude Desktop MCP config: ${config_file}"
fi
;;
cursor)
local config_file="${HOME}/.cursor/mcp.json"
mkdir -p "$(dirname "${config_file}")"
if [ -f "${config_file}" ]; then
python3 -c "
import json
try:
with open('${config_file}') as f:
config = json.load(f)
except (json.JSONDecodeError, FileNotFoundError):
config = {}
config.setdefault('mcpServers', {})
config['mcpServers']['cortex-memory'] = {
'command': '${binary}',
'args': ['${db_path}']
}
with open('${config_file}', 'w') as f:
json.dump(config, f, indent=2)
print('Configured Cursor MCP: ${config_file}')
"
else
cat > "${config_file}" <<CONF
{
"mcpServers": {
"cortex-memory": {
"command": "${binary}",
"args": ["${db_path}"]
}
}
}
CONF
echo "Created Cursor MCP config: ${config_file}"
fi
;;
windsurf)
local config_file="${HOME}/.windsurf/mcp.json"
mkdir -p "$(dirname "${config_file}")"
if [ -f "${config_file}" ]; then
python3 -c "
import json
try:
with open('${config_file}') as f:
config = json.load(f)
except (json.JSONDecodeError, FileNotFoundError):
config = {}
config.setdefault('mcpServers', {})
config['mcpServers']['cortex-memory'] = {
'command': '${binary}',
'args': ['${db_path}']
}
with open('${config_file}', 'w') as f:
json.dump(config, f, indent=2)
print('Configured Windsurf MCP: ${config_file}')
"
else
cat > "${config_file}" <<CONF
{
"mcpServers": {
"cortex-memory": {
"command": "${binary}",
"args": ["${db_path}"]
}
}
}
CONF
echo "Created Windsurf MCP config: ${config_file}"
fi
;;
*)
echo "Unknown IDE: ${ide}"
return 1
;;
esac
}
if [ -n "${IDE}" ]; then
if [ "${IDE}" = "all" ]; then
for target in claude claude-desktop cursor windsurf; do
configure_ide "${target}" || true
done
else
configure_ide "${IDE}"
fi
fi
# Check PATH
if ! echo "${PATH}" | grep -q "${INSTALL_DIR}"; then
echo ""
echo "NOTE: ${INSTALL_DIR} is not in your PATH."
echo "Add this to your shell profile:"
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
fi
echo ""
echo "============================================"
echo " Cortex installed successfully!"
echo "============================================"
echo ""
if [ -n "${IDE}" ]; then
echo "Next steps:"
echo " 1. Start a new Claude Code session"
echo " 2. Say: \"Enable cross-device memory sync\""
echo " 3. Save the passphrase for your other devices"
echo ""
fi
echo "If you find Cortex useful, please star the repo:"
echo " https://github.com/${REPO}"