#!/bin/bash
# Script to test the MCP server's example functionality
# Set the base URL for the MCP server
BASE_URL="http://localhost:8000"
# Function to test an example endpoint
test_example() {
local endpoint=$1
local name=$2
local category=$3
echo "Testing $category example: $name"
response=$(curl -s "$BASE_URL/jsonrpc" \
-H "Content-Type: application/json" \
-d "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/call\",\"params\":{\"name\":\"$endpoint\",\"params\":{\"${category}_name\":\"$name\"}}}")
# Check if the response contains an error
if echo "$response" | grep -q "error"; then
echo "❌ Error retrieving $category example '$name':"
echo "$response" | jq '.error'
else
echo "✅ Successfully retrieved $category example '$name'"
# Uncomment to see the actual example content
# echo "$response" | jq '.result'
fi
echo ""
}
# Function to test listing examples
test_list_examples() {
echo "Testing list_available_examples"
response=$(curl -s "$BASE_URL/jsonrpc" \
-H "Content-Type: application/json" \
-d "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/call\",\"params\":{\"name\":\"list_available_examples\",\"params\":{}}}")
# Check if the response contains an error
if echo "$response" | grep -q "error"; then
echo "❌ Error listing available examples:"
echo "$response" | jq '.error'
else
echo "✅ Successfully listed available examples"
echo "Categories found:"
echo "$response" | jq '.result | keys[]'
# Count examples in each category
for category in $(echo "$response" | jq -r '.result | keys[]'); do
count=$(echo "$response" | jq ".result.\"$category\" | length")
echo " - $category: $count examples"
done
fi
echo ""
}
# Main test sequence
echo "==== Testing MCP Server Example Functionality ===="
echo "Server URL: $BASE_URL"
echo ""
# Test listing examples
test_list_examples
# Test component examples
test_example "get_component_example" "Button" "component"
test_example "get_component_example" "Card" "component"
# Test hook examples
test_example "get_hook_example" "useAuth" "hook"
test_example "get_hook_example" "useForm" "hook"
# Test service examples
test_example "get_service_example" "ApiService" "service"
test_example "get_service_example" "AuthService" "service"
# Test screen examples
test_example "get_screen_example" "Login" "screen"
test_example "get_screen_example" "Home" "screen"
# Test theme examples
test_example "get_theme_example" "colors" "theme"
test_example "get_theme_example" "typography" "theme"
echo "==== Test Complete ===="