feat(script): update publish test script
This commit is contained in:
parent
7edc35812f
commit
022dbab85d
1 changed files with 112 additions and 67 deletions
|
|
@ -2,6 +2,20 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
echo "=================================================="
|
||||||
|
echo "MCP Registry Publish 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/main.go"
|
||||||
|
echo " • Built binary: ./build/registry"
|
||||||
|
echo ""
|
||||||
|
echo "REQUIRED: Set the BEARER_TOKEN environment variable with a valid GitHub token"
|
||||||
|
echo "Example: export BEARER_TOKEN=your_github_token_here"
|
||||||
|
echo "=================================================="
|
||||||
|
echo ""
|
||||||
|
|
||||||
# Default values
|
# Default values
|
||||||
HOST="http://localhost:8080"
|
HOST="http://localhost:8080"
|
||||||
VERBOSE=false
|
VERBOSE=false
|
||||||
|
|
@ -13,9 +27,20 @@ function show_usage {
|
||||||
echo " -h, --host Base URL of the MCP Registry service (default: http://localhost:8080)"
|
echo " -h, --host Base URL of the MCP Registry service (default: http://localhost:8080)"
|
||||||
echo " -v, --verbose Show verbose output including full request payload"
|
echo " -v, --verbose Show verbose output including full request payload"
|
||||||
echo " --help Show this help message"
|
echo " --help Show this help message"
|
||||||
|
echo ""
|
||||||
|
echo "Environment Variables:"
|
||||||
|
echo " BEARER_TOKEN Required: GitHub token for authentication"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Check if bearer token is set
|
||||||
|
if [[ -z "$BEARER_TOKEN" ]]; then
|
||||||
|
echo "Error: BEARER_TOKEN environment variable is not set."
|
||||||
|
echo "Please set your GitHub token as an environment variable:"
|
||||||
|
echo " export BEARER_TOKEN=your_github_token_here"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Check if jq is installed
|
# Check if jq is installed
|
||||||
if ! command -v jq &> /dev/null; then
|
if ! command -v jq &> /dev/null; then
|
||||||
echo "Error: jq is required but not installed."
|
echo "Error: jq is required but not installed."
|
||||||
|
|
@ -27,19 +52,14 @@ if ! command -v jq &> /dev/null; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if the API is running
|
# Check if the API is running
|
||||||
echo "Checking if the API is running at $HOST..."
|
echo "Checking if the MCP Registry API is running at $HOST..."
|
||||||
health_check=$(curl -s -o /dev/null -w "%{http_code}" "$HOST/v0/health" 2>/dev/null)
|
health_check=$(curl -s -o /dev/null -w "%{http_code}" "$HOST/v0/health" 2>/dev/null)
|
||||||
if [[ "$health_check" != "200" ]]; then
|
if [[ "$health_check" != "200" ]]; then
|
||||||
echo "Warning: API might not be running at $HOST (health check returned $health_check)"
|
echo "Error: MCP Registry API is not running at $HOST (health check returned $health_check)"
|
||||||
echo "Do you want to continue anyway? (y/n)"
|
echo "Please start the server using one of the methods mentioned above and try again."
|
||||||
read -r proceed
|
exit 1
|
||||||
if [[ ! "$proceed" =~ ^[Yy]$ ]]; then
|
|
||||||
echo "Exiting. Please start the API and try again."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "Continuing as requested..."
|
|
||||||
else
|
else
|
||||||
echo "API is running at $HOST"
|
echo "✓ MCP Registry API is running at $HOST"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Parse command line arguments
|
# Parse command line arguments
|
||||||
|
|
@ -56,46 +76,51 @@ done
|
||||||
# Create a temporary file for our JSON payload
|
# Create a temporary file for our JSON payload
|
||||||
PAYLOAD_FILE=$(mktemp)
|
PAYLOAD_FILE=$(mktemp)
|
||||||
|
|
||||||
# Create sample server detail payload
|
# Create sample server detail payload based on current model structure
|
||||||
cat > "$PAYLOAD_FILE" << EOF
|
cat > "$PAYLOAD_FILE" << EOF
|
||||||
{
|
{
|
||||||
"name": "Test MCP Server",
|
"name": "io.github.example/test-mcp-server",
|
||||||
"description": "A test server for MCP Registry",
|
"description": "A test server for MCP Registry validation - published at $(date)",
|
||||||
"version_detail": {
|
|
||||||
"version": "1.0.2",
|
|
||||||
"release_date": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")",
|
|
||||||
"is_latest": true
|
|
||||||
},
|
|
||||||
"repository": {
|
"repository": {
|
||||||
"url": "https://github.com/example/test-mcp-server",
|
"url": "https://github.com/example/test-mcp-server",
|
||||||
"branch": "main"
|
"source": "github",
|
||||||
|
"id": "example/test-mcp-server"
|
||||||
},
|
},
|
||||||
"registries": [
|
"version_detail": {
|
||||||
|
"version": "1.0.$(date +%s)"
|
||||||
|
},
|
||||||
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "npm",
|
"registry_name": "npm",
|
||||||
"package_name": "test-mcp-server",
|
"name": "test-mcp-server",
|
||||||
"license": "MIT",
|
"version": "1.0.$(date +%s)",
|
||||||
"command_arguments": {
|
"runtime_hint": "node",
|
||||||
"sub_commands": [
|
"runtime_arguments": [
|
||||||
{
|
{
|
||||||
"name": "start",
|
"type": "positional",
|
||||||
"description": "Start the server"
|
"name": "config",
|
||||||
}
|
"description": "Configuration file path",
|
||||||
],
|
"format": "file_path",
|
||||||
"environment_variables": [
|
"is_required": false,
|
||||||
{
|
"default": "./config.json"
|
||||||
"name": "PORT",
|
}
|
||||||
"description": "Port to run the server on",
|
],
|
||||||
"required": false
|
"environment_variables": [
|
||||||
}
|
{
|
||||||
]
|
"name": "PORT",
|
||||||
}
|
"description": "Port to run the server on",
|
||||||
}
|
"format": "number",
|
||||||
],
|
"is_required": false,
|
||||||
"remotes": [
|
"default": "3000"
|
||||||
{
|
},
|
||||||
"transport_type": "http",
|
{
|
||||||
"url": "http://example.com/api"
|
"name": "API_KEY",
|
||||||
|
"description": "API key for external service",
|
||||||
|
"format": "string",
|
||||||
|
"is_required": true,
|
||||||
|
"is_secret": true
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -110,17 +135,16 @@ fi
|
||||||
|
|
||||||
# Test publish endpoint
|
# Test publish endpoint
|
||||||
echo "Testing publish endpoint: $HOST/v0/publish"
|
echo "Testing publish endpoint: $HOST/v0/publish"
|
||||||
|
echo "Using Bearer Token: ${BEARER_TOKEN:0:10}..." # Show only first 10 chars for security
|
||||||
|
|
||||||
# Get response and status code in a single request
|
# Get response and status code in a single request
|
||||||
response_file=$(mktemp)
|
response_file=$(mktemp)
|
||||||
headers_file=$(mktemp)
|
headers_file=$(mktemp)
|
||||||
|
|
||||||
# Get token for authentication (or use dummy token for testing)
|
|
||||||
AUTH_TOKEN=${AUTH_TOKEN:-"test_token"}
|
|
||||||
|
|
||||||
# Execute curl with response body to file and headers+status to another file
|
# Execute curl with response body to file and headers+status to another file
|
||||||
curl -s -X POST \
|
curl -s -X POST \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "Authorization: Bearer ${AUTH_TOKEN}" \
|
-H "Authorization: Bearer ${BEARER_TOKEN}" \
|
||||||
-d "@$PAYLOAD_FILE" \
|
-d "@$PAYLOAD_FILE" \
|
||||||
-D "$headers_file" \
|
-D "$headers_file" \
|
||||||
-o "$response_file" \
|
-o "$response_file" \
|
||||||
|
|
@ -143,33 +167,54 @@ if [[ "${status_code:0:1}" == "2" ]]; then
|
||||||
echo "Response:"
|
echo "Response:"
|
||||||
echo "$http_response" | jq '.' 2>/dev/null || echo "$http_response"
|
echo "$http_response" | jq '.' 2>/dev/null || echo "$http_response"
|
||||||
|
|
||||||
# Extract the server ID from the response
|
# Check for server added message and extract UUID
|
||||||
server_id=$(echo "$http_response" | jq -r '.id')
|
message=$(echo "$http_response" | jq -r '.message // empty' 2>/dev/null)
|
||||||
|
server_id=$(echo "$http_response" | jq -r '.id // .server_id // empty' 2>/dev/null)
|
||||||
|
|
||||||
echo "Publish successful with ID: $server_id"
|
# Validate the response contains success indicators
|
||||||
|
success_indicators=0
|
||||||
|
|
||||||
# If we got a valid ID, verify it was actually created by calling the servers endpoint
|
if [[ ! -z "$message" && "$message" != "null" ]]; then
|
||||||
if [[ ! -z "$server_id" && "$server_id" != "null" ]]; then
|
echo "✓ Success message received: $message"
|
||||||
echo "-------------------------------------"
|
if [[ "$message" == *"server"* && ("$message" == *"added"* || "$message" == *"published"* || "$message" == *"created"*) ]]; then
|
||||||
echo "Verifying server was published by checking servers endpoint..."
|
((success_indicators++))
|
||||||
verify_response=$(curl -s "$HOST/v0/servers/$server_id")
|
echo "✓ Message indicates server was successfully added"
|
||||||
echo "Response from servers endpoint:"
|
fi
|
||||||
echo "$verify_response" | jq '.' 2>/dev/null || echo "$verify_response"
|
fi
|
||||||
echo "-------------------------------------"
|
|
||||||
echo "Server verification response:"
|
if [[ ! -z "$server_id" && "$server_id" != "null" && "$server_id" != "empty" ]]; then
|
||||||
echo "$verify_response" | jq '.' 2>/dev/null || echo "$verify_response"
|
echo "✓ Server UUID received: $server_id"
|
||||||
echo "Server verification successful"
|
# Validate UUID format (basic check for UUID pattern)
|
||||||
|
if [[ "$server_id" =~ ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$ ]]; then
|
||||||
|
((success_indicators++))
|
||||||
|
echo "✓ Server ID appears to be a valid UUID format"
|
||||||
|
else
|
||||||
|
echo "⚠ Server ID format may not be a standard UUID: $server_id"
|
||||||
|
((success_indicators++)) # Still count as success if we got an ID
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $success_indicators -ge 2 ]]; then
|
||||||
|
echo ""
|
||||||
|
echo "🎉 PUBLISH TEST PASSED!"
|
||||||
|
echo " ✓ Server successfully published with ID: $server_id"
|
||||||
|
echo " ✓ Success message: $message"
|
||||||
else
|
else
|
||||||
echo "Error: No valid server ID returned from publish response"
|
echo ""
|
||||||
echo "Response:"
|
echo "❌ PUBLISH TEST FAILED!"
|
||||||
echo "$http_response" | jq '.' 2>/dev/null || echo "$http_response"
|
echo " Expected: Success message about server being added AND a server UUID"
|
||||||
|
echo " Received: message='$message', id='$server_id'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "Response:"
|
echo ""
|
||||||
|
echo "❌ PUBLISH TEST FAILED!"
|
||||||
|
echo " Expected: 2xx status code"
|
||||||
|
echo " Received: $status_code"
|
||||||
|
echo " Response:"
|
||||||
echo "$http_response" | jq '.' 2>/dev/null || echo "$http_response"
|
echo "$http_response" | jq '.' 2>/dev/null || echo "$http_response"
|
||||||
echo "Publish failed"
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "-------------------------------------"
|
echo "-------------------------------------"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue