Skip to content

Commit 520f5c0

Browse files
committed
Fix tests to use mcp-server lint
1 parent 0d5d6fa commit 520f5c0

File tree

2 files changed

+97
-55
lines changed

2 files changed

+97
-55
lines changed

.github/workflows/test-mcp-examples.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ jobs:
3434
- name: Install doc-tools dependencies
3535
run: npx --no-install doc-tools install-test-dependencies
3636

37+
- name: Install yq
38+
run: |
39+
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
40+
sudo chmod +x /usr/local/bin/yq
41+
3742
- name: Make test script executable
3843
run: chmod +x modules/ai-agents/examples/test-mcp-examples.sh
3944

modules/ai-agents/examples/test-mcp-examples.sh

Lines changed: 92 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#!/usr/bin/env bash
22
#
3-
# Automated testing script for Redpanda Connect MCP examples (Cloud)
3+
# Automated testing script for Redpanda Connect MCP examples
44
#
55
# Usage:
6-
# ./test-mcp-examples.sh # Test all examples
7-
# ./test-mcp-examples.sh weather_*.yaml # Test specific pattern
6+
# ./test-mcp-examples.sh
87

98
set -euo pipefail
109

@@ -17,95 +16,134 @@ NC='\033[0m'
1716

1817
# Counters
1918
TOTAL=0
20-
PASSED=0
21-
FAILED=0
2219
SKIPPED=0
2320
MCP_FAILS=0
2421

25-
echo "🧪 Redpanda Connect MCP Examples Test Suite (Cloud)"
26-
echo "===================================================="
22+
echo "🧪 Redpanda Connect MCP Examples Test Suite"
23+
echo "============================================"
2724
echo ""
2825

29-
# Determine what to test
30-
PATTERN="${1:-*.yaml}"
31-
32-
# Function to lint a config file
33-
lint_config() {
34-
local file=$1
35-
TOTAL=$((TOTAL + 1))
36-
37-
echo -n " Linting $(basename "$file")... "
38-
39-
# Skip environment variable checks for MCP examples as they may use ${secrets.X}
40-
if rpk connect lint --skip-env-var-check "$file" 2>&1 | grep -q "error"; then
41-
echo -e "${RED}FAILED${NC}"
42-
rpk connect lint --skip-env-var-check "$file" 2>&1 | sed 's/^/ /'
43-
FAILED=$((FAILED + 1))
44-
return 1
45-
else
46-
echo -e "${GREEN}PASSED${NC}"
47-
PASSED=$((PASSED + 1))
48-
return 0
49-
fi
50-
}
26+
# Run MCP server lint on the directory
27+
echo "Running rpk connect mcp-server lint..."
28+
LINT_OUTPUT="/tmp/mcp_lint_$$.txt"
29+
if ! rpk connect mcp-server lint --skip-env-var-check 2>&1 | tee "$LINT_OUTPUT" > /dev/null; then
30+
echo -e "${RED}❌ Linting failed${NC}"
31+
echo ""
32+
cat "$LINT_OUTPUT"
33+
rm -f "$LINT_OUTPUT"
34+
exit 1
35+
else
36+
echo -e "${GREEN}✅ Linting passed${NC}"
37+
rm -f "$LINT_OUTPUT"
38+
fi
39+
echo ""
5140

5241
# Function to validate MCP metadata
5342
validate_mcp_metadata() {
5443
local file=$1
5544

5645
echo -n " Validating MCP metadata... "
5746

58-
# Check if file has MCP metadata
59-
if ! grep -q "meta:" "$file" || ! grep -q "mcp:" "$file"; then
47+
# Determine which YAML parser to use
48+
local use_yq=true
49+
if ! command -v yq &> /dev/null; then
50+
use_yq=false
51+
if ! command -v python3 &> /dev/null; then
52+
echo -e "${RED}FAILED${NC} (neither yq nor python3 available)"
53+
MCP_FAILS=$((MCP_FAILS + 1))
54+
return 1
55+
fi
56+
fi
57+
58+
# Check if .meta.mcp exists
59+
local mcp_exists
60+
if $use_yq; then
61+
mcp_exists=$(yq eval '.meta.mcp' "$file" 2>/dev/null)
62+
else
63+
mcp_exists=$(python3 -c "
64+
import yaml
65+
try:
66+
with open('$file') as f:
67+
doc = yaml.safe_load(f)
68+
meta = doc.get('meta', {}) if doc else {}
69+
mcp = meta.get('mcp')
70+
print('null' if mcp is None else 'exists')
71+
except:
72+
print('null')
73+
" 2>/dev/null)
74+
fi
75+
76+
if [[ "$mcp_exists" == "null" || -z "$mcp_exists" ]]; then
6077
echo -e "${YELLOW}SKIPPED${NC} (no MCP metadata)"
6178
SKIPPED=$((SKIPPED + 1))
6279
return 0
6380
fi
6481

65-
# Check for required MCP fields
66-
local has_enabled
67-
local has_description
68-
has_enabled=$(grep -c "enabled: true" "$file" || echo 0)
69-
has_description=$(grep -c "description:" "$file" || echo 0)
82+
# Read .meta.mcp.enabled
83+
local enabled
84+
if $use_yq; then
85+
enabled=$(yq eval '.meta.mcp.enabled' "$file" 2>/dev/null)
86+
else
87+
enabled=$(python3 -c "
88+
import yaml
89+
try:
90+
with open('$file') as f:
91+
doc = yaml.safe_load(f)
92+
enabled = doc.get('meta', {}).get('mcp', {}).get('enabled')
93+
print('null' if enabled is None else str(enabled).lower())
94+
except:
95+
print('null')
96+
" 2>/dev/null)
97+
fi
7098

71-
if [[ $has_enabled -eq 0 ]]; then
99+
if [[ "$enabled" != "true" ]]; then
72100
echo -e "${YELLOW}WARNING${NC} (mcp.enabled not set to true)"
73101
return 0
74102
fi
75103

76-
if [[ $has_description -eq 0 ]]; then
104+
# Read .meta.mcp.description
105+
local description
106+
if $use_yq; then
107+
description=$(yq eval '.meta.mcp.description' "$file" 2>/dev/null)
108+
else
109+
description=$(python3 -c "
110+
import yaml
111+
try:
112+
with open('$file') as f:
113+
doc = yaml.safe_load(f)
114+
desc = doc.get('meta', {}).get('mcp', {}).get('description')
115+
print('null' if desc is None or desc == '' else str(desc))
116+
except:
117+
print('null')
118+
" 2>/dev/null)
119+
fi
120+
121+
if [[ "$description" == "null" || -z "$description" ]]; then
77122
echo -e "${RED}FAILED${NC} (missing description)"
123+
MCP_FAILS=$((MCP_FAILS + 1))
78124
return 1
79125
fi
80126

81127
echo -e "${GREEN}PASSED${NC}"
82128
return 0
83129
}
84130

85-
# Find and test all matching files
86-
for file in $PATTERN; do
131+
# Validate MCP metadata for each file
132+
for file in *.yaml; do
87133
if [[ -f "$file" ]]; then
134+
TOTAL=$((TOTAL + 1))
88135
echo ""
89-
echo -e "${BLUE}📄 Testing: $file${NC}"
90-
91-
# Lint the config
92-
if lint_config "$file"; then
93-
# Validate MCP metadata
94-
if ! validate_mcp_metadata "$file"; then
95-
MCP_FAILS=$((MCP_FAILS + 1))
96-
fi
97-
fi
136+
echo -e "${BLUE}📄 Validating: $file${NC}"
137+
validate_mcp_metadata "$file"
98138
fi
99139
done
100140

101141
# Summary
102142
echo ""
103-
echo "===================================================="
143+
echo "============================================"
104144
echo "📊 Test Summary"
105-
echo "===================================================="
145+
echo "============================================"
106146
echo "Total configs tested: $TOTAL"
107-
echo -e "Passed: ${GREEN}$PASSED${NC}"
108-
echo -e "Failed: ${RED}$FAILED${NC}"
109147
if [[ $MCP_FAILS -gt 0 ]]; then
110148
echo -e "MCP validation failures: ${RED}$MCP_FAILS${NC}"
111149
fi
@@ -114,8 +152,7 @@ if [[ $SKIPPED -gt 0 ]]; then
114152
fi
115153
echo ""
116154

117-
TOTAL_FAILURES=$((FAILED + MCP_FAILS))
118-
if [[ $TOTAL_FAILURES -gt 0 ]]; then
155+
if [[ $MCP_FAILS -gt 0 ]]; then
119156
echo -e "${RED}❌ Some tests failed${NC}"
120157
exit 1
121158
else

0 commit comments

Comments
 (0)