-
Notifications
You must be signed in to change notification settings - Fork 907
Expand file tree
/
Copy pathtest_endpoints.sh
More file actions
executable file
·228 lines (191 loc) · 6.5 KB
/
Copy pathtest_endpoints.sh
File metadata and controls
executable file
·228 lines (191 loc) · 6.5 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
#!/bin/bash
set -e
echo "=================================================="
echo "MCP Registry Endpoint Test Script"
echo "=================================================="
echo "This script expects the MCP Registry server to be running locally."
echo "Please ensure the server is started using one of the following methods:"
echo " • Docker Compose: docker compose up"
echo " • Direct execution: go run ./cmd/registry"
echo " • Built binary: ./build/registry"
echo "=================================================="
echo ""
# Default values
HOST="http://localhost:8080"
ENDPOINT="all"
LIMIT=""
# Display usage information
function show_usage {
echo "Usage: $0 [options]"
echo "Options:"
echo " -h, --host Base URL of the MCP Registry service (default: http://localhost:8080)"
echo " -e, --endpoint Endpoint to test: health, servers, ping, all (default: all)"
echo " -l, --limit Test servers with specified limit parameter"
echo " --help Show this help message"
exit 1
}
# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo "Error: jq is required but not installed."
echo "Please install jq using your package manager, for example:"
echo " brew install jq (macOS)"
echo " apt-get install jq (Debian/Ubuntu)"
echo " yum install jq (CentOS/RHEL)"
exit 1
fi
# Parse command line arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
-h|--host) HOST="$2"; shift ;;
-e|--endpoint) ENDPOINT="$2"; shift ;;
-l|--limit) LIMIT="$2"; shift ;;
--help) show_usage ;;
*) echo "Unknown parameter: $1"; show_usage ;;
esac
shift
done
# Validate endpoint
if [[ "$ENDPOINT" != "health" && "$ENDPOINT" != "servers" && "$ENDPOINT" != "ping" && "$ENDPOINT" != "all" ]]; then
echo "Invalid endpoint: $ENDPOINT. Must be 'health', 'servers', 'ping', or 'all'."
exit 1
fi
# Test health endpoint
test_health() {
echo "Testing health endpoint: $HOST/v0/health"
# Get response and status code
http_response=$(curl -s "$HOST/v0/health")
status_code=$(curl -s -o /dev/null -w "%{http_code}" "$HOST/v0/health")
echo "Status Code: $status_code"
if [[ $status_code == 2* ]]; then
# Parse JSON response with jq
echo "Response:"
echo "$http_response" | jq '.'
echo "Health check successful"
echo "-------------------------------------"
return 0
else
echo "Response:"
echo "$http_response" | jq '.' 2>/dev/null || echo "$http_response"
echo "Health check failed"
echo "-------------------------------------"
return 1
fi
}
# Test servers endpoint
test_servers() {
echo "Testing servers endpoint: $HOST/v0/servers"
# Get response and status code
http_response=$(curl -s "$HOST/v0/servers")
status_code=$(curl -s -o /dev/null -w "%{http_code}" "$HOST/v0/servers")
echo "Status Code: $status_code"
if [[ $status_code == 2* ]]; then
# Parse and display JSON with jq
echo "Response Summary:"
echo "$http_response" | jq '.servers | length' | xargs echo "Total registries:"
# Display a prettier formatted summary
echo "Server Names:"
echo "$http_response" | jq -r '.servers[].server.name'
# Show the metadata with next cursor if available
echo -e "\nPagination Metadata:"
echo "$http_response" | jq '.metadata'
# Show more detailed output with all fields
echo -e "\nServer Details:"
echo "$http_response" | jq '.'
echo "Servers request successful"
echo "-------------------------------------"
return 0
else
echo "Response:"
echo "$http_response" | jq '.' 2>/dev/null || echo "$http_response"
echo "Servers request failed"
echo "-------------------------------------"
return 1
fi
}
# Test servers endpoint with limit
test_servers_with_limit() {
limit=$1
echo "Testing servers endpoint with limit: $HOST/v0/servers?limit=$limit"
# Get response and status code
http_response=$(curl -s "$HOST/v0/servers?limit=$limit")
status_code=$(curl -s -o /dev/null -w "%{http_code}" "$HOST/v0/servers?limit=$limit")
echo "Status Code: $status_code"
if [[ $status_code == 2* ]]; then
# Verify the response contains the right number of items (or not more than the limit)
item_count=$(echo "$http_response" | jq '.servers | length')
echo "Response has $item_count items (requested limit: $limit)"
# Verify we're not exceeding the limit
if [[ $item_count -gt $limit ]]; then
echo "ERROR: Response contains more items ($item_count) than the requested limit ($limit)"
return 1
fi
# Parse and display JSON with jq
echo "Response Summary:"
# Display a prettier formatted summary
echo "Server Names:"
echo "$http_response" | jq -r '.servers[].server.name'
# Show the metadata with next cursor if available
echo -e "\nPagination Metadata:"
echo "$http_response" | jq '.metadata'
# Show more detailed output with all fields
echo -e "\nServer Details:"
echo "$http_response" | jq '.'
echo "Servers request with limit successful"
echo "-------------------------------------"
return 0
else
echo "Response:"
echo "$http_response" | jq '.' 2>/dev/null || echo "$http_response"
echo "Servers request with limit failed"
echo "-------------------------------------"
return 1
fi
}
# Test ping endpoint
test_ping() {
echo "Testing ping endpoint: $HOST/v0/ping"
# Get response and status code
http_response=$(curl -s "$HOST/v0/ping")
status_code=$(curl -s -o /dev/null -w "%{http_code}" "$HOST/v0/ping")
echo "Status Code: $status_code"
if [[ $status_code == 2* ]]; then
# Parse JSON response with jq
echo "Response:"
echo "$http_response" | jq '.'
echo "Ping successful"
echo "-------------------------------------"
return 0
else
echo "Response:"
echo "$http_response" | jq '.' 2>/dev/null || echo "$http_response"
echo "Ping failed"
echo "-------------------------------------"
return 1
fi
}
# Run tests based on selected endpoint
success=0
if [[ "$ENDPOINT" == "health" || "$ENDPOINT" == "all" ]]; then
test_health
success=$((success + $?))
fi
if [[ "$ENDPOINT" == "servers" || "$ENDPOINT" == "all" ]]; then
if [ -n "$LIMIT" ]; then
test_servers_with_limit "$LIMIT"
else
test_servers
fi
success=$((success + $?))
fi
if [[ "$ENDPOINT" == "ping" || "$ENDPOINT" == "all" ]]; then
test_ping
success=$((success + $?))
fi
# Return overall success/failure
if [[ $success -eq 0 ]]; then
echo "All tests passed successfully!"
exit 0
else
echo "Some tests failed!"
exit 1
fi