-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_bridge.sh
More file actions
executable file
·152 lines (125 loc) · 6.14 KB
/
auto_bridge.sh
File metadata and controls
executable file
·152 lines (125 loc) · 6.14 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
#!/usr/bin/env bash
# =============================================================================
# auto_bridge.sh — Antigravity MCP Auto-Bridge
# Detects local MCP server configuration files and maps their settings to
# the Antigravity environment. Run this script once after cloning or any
# time your MCP server configuration changes.
# =============================================================================
set -euo pipefail
# ── Colour helpers ────────────────────────────────────────────────────────────
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'
CYAN='\033[0;36m'; BOLD='\033[1m'; RESET='\033[0m'
info() { echo -e "${CYAN}[INFO]${RESET} $*"; }
success() { echo -e "${GREEN}[OK]${RESET} $*"; }
warn() { echo -e "${YELLOW}[WARN]${RESET} $*"; }
error() { echo -e "${RED}[ERROR]${RESET} $*" >&2; }
header() { echo -e "\n${BOLD}${CYAN}$*${RESET}\n"; }
# ── Constants ─────────────────────────────────────────────────────────────────
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ENV_OUTPUT="${SCRIPT_DIR}/.env.mcp"
ANTIGRAVITY_CONFIG_DIR="${HOME}/.antigravity/mcp"
KNOWN_CONFIG_PATHS=(
"${SCRIPT_DIR}/mcp.json"
"${SCRIPT_DIR}/.mcp.json"
"${SCRIPT_DIR}/mcp-config.json"
"${HOME}/.config/mcp/config.json"
"${HOME}/.mcp/config.json"
"${HOME}/Library/Application Support/mcp/config.json" # macOS
"/etc/mcp/config.json" # Linux system-wide
)
header "Antigravity MCP Auto-Bridge v1.0"
# ── 1. Detect project root ────────────────────────────────────────────────────
info "Project root: ${SCRIPT_DIR}"
# ── 2. Scan for MCP config files ─────────────────────────────────────────────
header "Scanning for MCP server configurations…"
FOUND_CONFIGS=()
for cfg in "${KNOWN_CONFIG_PATHS[@]}"; do
if [[ -f "$cfg" ]]; then
success "Found config: $cfg"
FOUND_CONFIGS+=("$cfg")
else
info "No config at: $cfg"
fi
done
# Also check if a Claude / VS Code style mcp servers block exists
CLAUDE_CONFIG="${HOME}/Library/Application Support/Claude/claude_desktop_config.json"
if [[ -f "$CLAUDE_CONFIG" ]]; then
success "Found Claude Desktop config: ${CLAUDE_CONFIG}"
FOUND_CONFIGS+=("$CLAUDE_CONFIG")
fi
if [[ ${#FOUND_CONFIGS[@]} -eq 0 ]]; then
warn "No existing MCP config files detected. Generating a default template."
fi
# ── 3. Detect Node / npx availability ────────────────────────────────────────
header "Checking runtime dependencies…"
if command -v node &>/dev/null; then
NODE_VERSION="$(node --version)"
success "Node.js: ${NODE_VERSION}"
else
error "Node.js is not installed. Please install Node.js >= 18 to run MCP servers."
exit 1
fi
if command -v npx &>/dev/null; then
success "npx: $(npx --version)"
else
error "npx not found. Install a recent version of npm."
exit 1
fi
# ── 4. Detect built server ────────────────────────────────────────────────────
header "Checking build output…"
BUILT_SERVER="${SCRIPT_DIR}/dist/server.js"
if [[ -f "$BUILT_SERVER" ]]; then
success "Built server found: ${BUILT_SERVER}"
SERVER_CMD="node ${BUILT_SERVER}"
else
warn "Built server not found at ${BUILT_SERVER}."
warn "Run 'npm run build' first, or the bridge will use ts-node as a fallback."
SERVER_CMD="npx ts-node ${SCRIPT_DIR}/src/server.ts"
fi
# ── 5. Write Antigravity environment file ────────────────────────────────────
header "Writing Antigravity MCP environment settings → ${ENV_OUTPUT}"
cat > "${ENV_OUTPUT}" <<EOF
# ============================================================
# Antigravity MCP Bridge — Environment Settings
# Auto-generated by auto_bridge.sh on $(date -u +"%Y-%m-%dT%H:%M:%SZ")
# Do NOT commit this file — add .env.mcp to .gitignore
# ============================================================
# The command Antigravity will use to launch the MCP server
MCP_SERVER_COMMAND="${SERVER_CMD}"
# Transport type (stdio | sse)
MCP_TRANSPORT=stdio
# Server identity
MCP_SERVER_NAME=antigravity-mcp-bridge
MCP_SERVER_VERSION=1.0.0
# Path to the skills directory (used by Antigravity Manager)
MCP_SKILLS_DIR=${SCRIPT_DIR}/skills
# Optional: default SQLite database for the sqlite_skill
# SQLITE_DB_PATH=/path/to/your/database.db
# Number of found config files (informational)
MCP_DETECTED_CONFIGS=${#FOUND_CONFIGS[@]}
EOF
success "Environment file written."
# ── 6. Ensure Antigravity config directory exists ────────────────────────────
header "Setting up Antigravity config directory…"
mkdir -p "${ANTIGRAVITY_CONFIG_DIR}"
BRIDGE_LINK="${ANTIGRAVITY_CONFIG_DIR}/antigravity-mcp-bridge.json"
cat > "${BRIDGE_LINK}" <<EOF
{
"name": "antigravity-mcp-bridge",
"version": "1.0.0",
"transport": "stdio",
"command": "${SERVER_CMD}",
"skillsDir": "${SCRIPT_DIR}/skills",
"envFile": "${ENV_OUTPUT}",
"registeredAt": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
}
EOF
success "Bridge descriptor written to ${BRIDGE_LINK}"
# ── 7. Summary ────────────────────────────────────────────────────────────────
header "Summary"
echo -e " ${BOLD}Configs detected:${RESET} ${#FOUND_CONFIGS[@]}"
echo -e " ${BOLD}Server command:${RESET} ${SERVER_CMD}"
echo -e " ${BOLD}Env file:${RESET} ${ENV_OUTPUT}"
echo -e " ${BOLD}Antigravity dir:${RESET} ${ANTIGRAVITY_CONFIG_DIR}"
echo ""
success "Auto-bridge complete. You can now start Antigravity and import the sqlite_skill."