#!/bin/bash
# MCP Server Smoke Test
# Verifies that the MCP server module loads correctly and basic tools work

set -e

echo "=== MCP Server Smoke Test ==="
echo ""

# Test 1: Verify MCP module loads
echo "1. Testing MCP module loading..."
python -c "
from local_deep_research.mcp.server import mcp, list_strategies, get_configuration
print('   MCP server module loaded successfully')
print(f'   Server name: {mcp.name}')

# Test discovery tools
result = list_strategies()
assert result['status'] == 'success', f'list_strategies failed: {result}'
print(f'   list_strategies: {len(result[\"strategies\"])} strategies available')

config = get_configuration()
assert config['status'] == 'success', f'get_configuration failed: {config}'
print('   get_configuration: works correctly')
"
echo "   PASSED"
echo ""

# Test 2: Verify MCP server startup
echo "2. Testing MCP server startup..."
timeout 5 python -m local_deep_research.mcp 2>&1 || {
    exit_code=$?
    if [ $exit_code -eq 124 ]; then
        echo "   Server started correctly (timed out waiting for STDIO input as expected)"
        echo "   PASSED"
    else
        echo "   FAILED: MCP server failed to start with exit code $exit_code"
        exit 1
    fi
}

echo ""
echo "=== All MCP smoke tests passed ==="
