-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathvalidate-mcp-integrations.sh
More file actions
executable file
·298 lines (246 loc) · 7.95 KB
/
validate-mcp-integrations.sh
File metadata and controls
executable file
·298 lines (246 loc) · 7.95 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
#!/usr/bin/env bash
# shellcheck disable=SC2317
# 🔍 MCP Integrations Validation Script
# Validates and tests all MCP integrations for proper functionality
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
source "${SCRIPT_DIR}/shared-constants.sh"
set -euo pipefail
print_header() {
local msg="$1"
echo -e "${PURPLE}$msg${NC}"
return 0
}
# Test results tracking
declare -i total_tests=0
declare -i passed_tests=0
declare -i failed_tests=0
# Test function wrapper
run_test() {
local test_name="$1"
local test_command="$2"
((++total_tests))
print_info "Testing: $test_name"
if bash -c "$test_command" &>/dev/null; then
print_success "$test_name: PASSED"
((++passed_tests))
return 0
else
print_error "$test_name: FAILED"
((++failed_tests))
return 1
fi
return 0
}
# Test Node.js and npm
test_prerequisites() {
print_header "Testing Prerequisites"
run_test "Node.js availability" "command -v node"
run_test "npm availability" "command -v npm"
if command -v node &>/dev/null; then
local node_version
node_version=$(node --version)
print_info "Node.js version: $node_version"
fi
if command -v npm &>/dev/null; then
local npm_version
npm_version=$(npm --version)
print_info "npm version: $npm_version"
fi
return 0
}
# Test Chrome DevTools MCP
test_chrome_devtools() {
print_header "Testing Chrome DevTools MCP"
run_test "Chrome DevTools MCP package" "npm list -g chrome-devtools-mcp || npm info chrome-devtools-mcp"
# Test Chrome availability
local chrome_paths=(
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
"/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary"
"/usr/bin/google-chrome"
"/usr/bin/google-chrome-stable"
"/usr/bin/chromium-browser"
)
local chrome_found=false
for chrome_path in "${chrome_paths[@]}"; do
if [[ -x "$chrome_path" ]]; then
print_success "Chrome found: $chrome_path"
chrome_found=true
break
fi
done
if [[ "$chrome_found" == false ]]; then
print_warning "Chrome not found in standard locations"
fi
return 0
}
# Test Playwright MCP
test_playwright() {
print_header "Testing Playwright MCP"
run_test "Playwright MCP package" "npm list -g playwright-mcp || npm info playwright-mcp"
run_test "Playwright package" "npm list -g playwright || npm info playwright"
# Test browser installations
if command -v npx &>/dev/null; then
print_info "Checking Playwright browser installations..."
if npx playwright --version &>/dev/null; then
print_success "Playwright CLI available"
else
print_warning "Playwright CLI not available"
fi
fi
return 0
}
# Test API connectivity
test_api_connectivity() {
print_header "Testing API Connectivity"
# Test Ahrefs API
if [[ -n "${AHREFS_API_KEY:-}" ]]; then
run_test "Ahrefs API connectivity" "curl -s -H 'Authorization: Bearer $AHREFS_API_KEY' https://apiv2.ahrefs.com/v2/subscription_info"
print_success "Ahrefs API key configured"
else
print_warning "Ahrefs API key not configured (AHREFS_API_KEY)"
fi
# Test Perplexity API
if [[ -n "${PERPLEXITY_API_KEY:-}" ]]; then
run_test "Perplexity API connectivity" "curl -s -H 'Authorization: Bearer $PERPLEXITY_API_KEY' https://api.perplexity.ai/chat/completions"
print_success "Perplexity API key configured"
else
print_warning "Perplexity API key not configured (PERPLEXITY_API_KEY)"
fi
# Test Cloudflare API
if [[ -n "${CLOUDFLARE_API_TOKEN:-}" && -n "${CLOUDFLARE_ACCOUNT_ID:-}" ]]; then
run_test "Cloudflare API connectivity" "curl -s -H 'Authorization: Bearer $CLOUDFLARE_API_TOKEN' https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID"
print_success "Cloudflare API credentials configured"
else
print_warning "Cloudflare API credentials not configured (CLOUDFLARE_API_TOKEN, CLOUDFLARE_ACCOUNT_ID)"
fi
return 0
}
# Validate a single JSON file directly (bypasses bash -c quoting issues)
# Uses jq if available, falls back to python3 -c with proper argument passing
validate_json_file() {
local file="$1"
if command -v jq &>/dev/null; then
jq empty "$file" 2>/dev/null
return $?
elif command -v python3 &>/dev/null; then
python3 -c "import json, sys; json.load(open(sys.argv[1]))" "$file" 2>/dev/null
return $?
else
# No JSON validator available — skip rather than false-fail
return 0
fi
}
# Test MCP configurations
test_mcp_configurations() {
print_header "Testing MCP Configurations"
local config_dir="configs/mcp-templates"
if [[ -d "$config_dir" ]]; then
print_success "MCP templates directory exists"
# Check for JSON validator availability
if ! command -v jq &>/dev/null && ! command -v python3 &>/dev/null; then
print_warning "No JSON validator found (install jq or python3)"
fi
# Validate each configuration file directly (not via bash -c)
for config_file in "$config_dir"/*.json; do
if [[ -f "$config_file" ]]; then
local filename
filename=$(basename "$config_file")
((++total_tests))
print_info "Testing: JSON validation: $filename"
if validate_json_file "$config_file"; then
print_success "JSON validation: $filename: PASSED"
((++passed_tests))
else
print_error "JSON validation: $filename: FAILED"
((++failed_tests))
fi
fi
done
else
print_error "MCP templates directory not found: $config_dir"
fi
return 0
}
# Test Context7 MCP
test_context7() {
print_header "Testing Context7 MCP"
# Test remote MCP URL reachability
run_test "Context7 MCP URL reachability" "curl -s --connect-timeout 10 -o /dev/null -w '%{http_code}' https://mcp.context7.com/mcp | grep -qE '^[23]'"
# Test Context7 MCP npm package availability
run_test "Context7 MCP package" "npm list -g @context7/mcp-server || npm info @context7/mcp-server"
# Validate context7-mcp-config.json.txt template if it exists
local config_template="configs/context7-mcp-config.json.txt"
if [[ -f "$config_template" ]]; then
run_test "Context7 config template JSON validation" "jq . >/dev/null < \"$config_template\""
print_success "Context7 config template found: $config_template"
else
print_warning "Context7 config template not found: $config_template"
fi
return 0
}
# Test network connectivity
test_network() {
print_header "Testing Network Connectivity"
run_test "Internet connectivity" "curl -s --connect-timeout 5 https://www.google.com"
run_test "npm registry" "curl -s --connect-timeout 5 https://registry.npmjs.org/"
run_test "GitHub connectivity" "curl -s --connect-timeout 5 https://api.github.com"
return 0
}
# Generate validation report
generate_report() {
print_header "Validation Report"
echo
print_info "Total tests run: $total_tests"
print_success "Tests passed: $passed_tests"
if [[ $failed_tests -gt 0 ]]; then
print_error "Tests failed: $failed_tests"
else
print_success "Tests failed: $failed_tests"
fi
echo
local success_rate
success_rate=$((passed_tests * 100 / total_tests))
if [[ $success_rate -ge 90 ]]; then
print_success "Overall status: EXCELLENT ($success_rate% success rate)"
elif [[ $success_rate -ge 75 ]]; then
print_success "Overall status: GOOD ($success_rate% success rate)"
elif [[ $success_rate -ge 50 ]]; then
print_warning "Overall status: NEEDS ATTENTION ($success_rate% success rate)"
else
print_error "Overall status: CRITICAL ISSUES ($success_rate% success rate)"
fi
echo
if [[ $failed_tests -gt 0 ]]; then
print_info "Next steps:"
print_info "1. Review failed tests above"
print_info "2. Check .agents/MCP-TROUBLESHOOTING.md for solutions"
print_info "3. Run setup script: bash .agents/scripts/setup-mcp-integrations.sh"
print_info "4. Configure missing API keys"
else
print_success "All MCP integrations are ready to use!"
print_info "Check .agents/MCP-INTEGRATIONS.md for usage examples"
fi
return 0
}
# Main validation function
main() {
print_header "MCP Integrations Validation"
echo
test_prerequisites
echo
test_network
echo
test_chrome_devtools
echo
test_playwright
echo
test_api_connectivity
echo
test_context7
echo
test_mcp_configurations
echo
generate_report
return 0
}
main "$@"