Skip to main content
Glama

MCP Self-Learning Server

test-full-integration.shโ€ข8.49 kB
#!/bin/bash # Full Integration Test Script for MCP Self-Learning Server # Tests all components: CLI, API, clients, integrations, and systemd service set -e # Exit on any error echo "๐Ÿงช MCP Self-Learning Server - Full Integration Test Suite" echo "========================================================" echo # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Test counters TOTAL_TESTS=0 PASSED_TESTS=0 FAILED_TESTS=0 # Function to run a test run_test() { local test_name="$1" local test_command="$2" local expected_output="$3" TOTAL_TESTS=$((TOTAL_TESTS + 1)) echo -n "[$TOTAL_TESTS] Testing $test_name... " if output=$(eval "$test_command" 2>&1); then if [[ -z "$expected_output" ]] || echo "$output" | grep -q "$expected_output"; then echo -e "${GREEN}โœ… PASS${NC}" PASSED_TESTS=$((PASSED_TESTS + 1)) return 0 else echo -e "${RED}โŒ FAIL${NC} (Expected: $expected_output)" echo " Output: $output" FAILED_TESTS=$((FAILED_TESTS + 1)) return 1 fi else echo -e "${RED}โŒ FAIL${NC}" echo " Error: $output" FAILED_TESTS=$((FAILED_TESTS + 1)) return 1 fi } # Function to check if service is running check_service() { curl -s http://localhost:8765/health > /dev/null 2>&1 } # Function to wait for service wait_for_service() { local max_attempts=30 local attempt=1 echo -n "Waiting for service to start" while [ $attempt -le $max_attempts ]; do if check_service; then echo -e " ${GREEN}โœ…${NC}" return 0 fi echo -n "." sleep 1 attempt=$((attempt + 1)) done echo -e " ${RED}โŒ Timeout${NC}" return 1 } echo "๐Ÿ”ง Phase 1: Global Installation Tests" echo "------------------------------------" run_test "Global CLI Installation" "which mcp-learn" "mcp-learn" run_test "Version Command" "mcp-learn --version" "1.0.0" run_test "Help Command" "mcp-learn --help" "MCP Self-Learning Server CLI" run_test "Health Check Command" "mcp-learn health" "health check" echo echo "๐Ÿฅ Phase 2: Service Management Tests" echo "-----------------------------------" # Stop any existing API server pkill -f "mcp-learn api" 2>/dev/null || true sleep 2 # Test systemd service run_test "Service Status Check" "systemctl --user is-active mcp-self-learning.service || echo 'inactive'" "active" if ! check_service; then echo "Service not running, starting it..." systemctl --user start mcp-self-learning.service wait_for_service fi run_test "Service Health Check" "curl -s http://localhost:8765/health | jq -r .status" "healthy" run_test "Service Status Check" "curl -s http://localhost:8765/status | jq -r .running" "true" echo echo "๐ŸŒ Phase 3: REST API Tests" echo "-------------------------" run_test "Health Endpoint" "curl -s http://localhost:8765/health | jq -r .status" "healthy" run_test "Status Endpoint" "curl -s http://localhost:8765/status | jq -r .running" "true" # Test analyze endpoint ANALYZE_DATA='{"interaction":{"type":"integration_test","input":"test input","output":"test output","success":true}}' run_test "Analyze Endpoint" "curl -s -X POST http://localhost:8765/analyze -H 'Content-Type: application/json' -d '$ANALYZE_DATA' | jq -r .success" "true" run_test "Insights Endpoint" "curl -s http://localhost:8765/insights | jq -r .success" "true" run_test "Metrics Endpoint" "curl -s http://localhost:8765/metrics | jq -r .success" "true" echo echo "๐Ÿ“ฑ Phase 4: CLI Commands with Service Running" echo "--------------------------------------------" run_test "Status Command" "mcp-learn status | head -1" "Checking status" run_test "Analyze Command" "mcp-learn analyze --type 'test' --input 'CLI test' --output 'CLI result' --success | head -1" "Analyzing pattern" run_test "Insights Command" "mcp-learn insights | head -1" "Fetching insights" echo echo "๐ŸŸข Phase 5: Node.js Client Library Test" echo "--------------------------------------" # Create temporary Node.js test cat > test-temp-client.js << 'EOF' import SelfLearningClient from './lib/self-learning-client.js'; const client = new SelfLearningClient({ port: 8765 }); try { const connected = await client.connect(); if (connected) { const health = await client.getHealth(); console.log(health.status); } else { console.log('failed'); } } catch (error) { console.log('error'); } EOF run_test "Node.js Client Connection" "timeout 10 node test-temp-client.js" "healthy" rm -f test-temp-client.js echo echo "๐Ÿ Phase 6: Python Client Library Test" echo "--------------------------------------" # Create temporary Python test cat > test-temp-python.py << 'EOF' import sys import asyncio sys.path.insert(0, './lib') async def test(): try: from self_learning_client import SelfLearningClient client = SelfLearningClient(base_url="http://localhost:8765") connected = await client.connect() if connected: health = await client.get_health() print(health['status']) await client.disconnect() else: print('failed') except Exception as e: print('error') asyncio.run(test()) EOF # Use virtual environment if it exists if [ -d "test-env" ]; then run_test "Python Client Connection" "source test-env/bin/activate && timeout 10 python3 test-temp-python.py" "healthy" else echo "[$((TOTAL_TESTS + 1))] Testing Python Client Connection... ${YELLOW}โญ๏ธ SKIP${NC} (Virtual env not available)" TOTAL_TESTS=$((TOTAL_TESTS + 1)) fi rm -f test-temp-python.py echo echo "๐Ÿค– Phase 7: Claudio Integration Test" echo "-----------------------------------" # Create temporary Claudio test cat > test-temp-claudio.js << 'EOF' import { ClaudioMCPLearningTools } from './integrations/claudio-mcp-tools.js'; try { const tools = new ClaudioMCPLearningTools(); await tools.initialize(); const definitions = tools.getToolDefinitions(); console.log(definitions.length); await tools.cleanup(); } catch (error) { console.log('error'); } EOF run_test "Claudio Integration" "timeout 15 node test-temp-claudio.js" "6" rm -f test-temp-claudio.js echo echo "๐Ÿ’พ Phase 8: Data Persistence Test" echo "--------------------------------" # Test data persistence by adding data, restarting service, and checking if data persists BEFORE_RESTART=$(curl -s http://localhost:8765/insights | jq -r '.insights.knowledgeItems') run_test "Data Before Restart" "echo '$BEFORE_RESTART' | grep -E '^[0-9]+$'" "" # Restart service echo "Restarting service to test persistence..." systemctl --user restart mcp-self-learning.service wait_for_service AFTER_RESTART=$(curl -s http://localhost:8765/insights | jq -r '.insights.knowledgeItems') run_test "Data After Restart" "echo '$AFTER_RESTART' | grep -E '^[0-9]+$'" "" echo echo "๐Ÿ”„ Phase 9: Load Test (Basic)" echo "----------------------------" echo "Running concurrent requests..." for i in {1..5}; do curl -s http://localhost:8765/health > /dev/null & done wait run_test "Service Still Responsive" "curl -s http://localhost:8765/health | jq -r .status" "healthy" echo echo "๐Ÿงน Phase 10: Cleanup Test" echo "------------------------" run_test "Stop Service" "systemctl --user stop mcp-self-learning.service; sleep 2; echo 'stopped'" "stopped" run_test "Service Stopped" "systemctl --user is-active mcp-self-learning.service || echo 'inactive'" "inactive" # Restart for any follow-up usage systemctl --user start mcp-self-learning.service wait_for_service echo echo "๐Ÿ“Š Test Results Summary" echo "=======================" echo -e "Total Tests: ${BLUE}$TOTAL_TESTS${NC}" echo -e "Passed: ${GREEN}$PASSED_TESTS${NC}" echo -e "Failed: ${RED}$FAILED_TESTS${NC}" if [ $FAILED_TESTS -eq 0 ]; then echo -e "\n${GREEN}๐ŸŽ‰ ALL TESTS PASSED!${NC}" echo -e "${GREEN}โœ… MCP Self-Learning Server is fully functional${NC}" echo echo "๐Ÿš€ System Ready for Production Use!" echo " โ€ข Global CLI: mcp-learn" echo " โ€ข REST API: http://localhost:8765" echo " โ€ข Systemd Service: mcp-self-learning.service" echo " โ€ข Claudio Integration: Ready" echo " โ€ข Claudia Integration: Ready" exit 0 else echo -e "\n${RED}โŒ Some tests failed${NC}" echo "Please check the output above for details" exit 1 fi

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/saralegui-solutions/mcp-self-learning-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server