#!/usr/bin/env python3
"""
Direct test of tool loading from gateway discovery endpoint.
This bypasses the MCP protocol and directly tests the tool loading logic.
"""

import asyncio
import sys

from server import CoherenceMCPServer


async def test_tool_loading():
    """Test direct tool loading from gateway."""
    print("Testing tool loading from gateway...")

    # Create server instance
    server = CoherenceMCPServer()

    # Load tools
    await server.load_tools()

    # Check results
    print(f"Loaded {len(server.tools)} tools:")
    for tool_name, tool_data in server.tools.items():
        print(f"  - {tool_name}: {tool_data.get('description', 'No description')}")

    return len(server.tools) > 0


if __name__ == "__main__":
    try:
        success = asyncio.run(test_tool_loading())
        print(f"\n{'✅ Test passed' if success else '❌ Test failed'}")
        sys.exit(0 if success else 1)
    except Exception as e:
        print(f"\n❌ Test failed with error: {e}")
        sys.exit(1)
