#!/usr/bin/env python3
"""
Test MCP Tools Registration
"""

import sys
import os
from dotenv import load_dotenv

# Load environment
load_dotenv()

# Add src to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

try:
    from src.vultr_mcp.server import mcp
    
    print("MCP Server Tools Inspection")
    print("=" * 60)
    
    # Get registered tools (this depends on FastMCP internal structure)
    # FastMCP might store tools differently
    # Let's try to check if we can import the tool functions
    
    # List all functions with billing prefix
    import src.vultr_mcp.server as server_module
    
    print("Functions in server module:")
    for name in dir(server_module):
        if not name.startswith('_'):
            func = getattr(server_module, name)
            if callable(func) and hasattr(func, '__name__'):
                print(f"  - {name}")
    
    # Check if billing tools are registered by looking at mcp._tools
    # This is internal, but useful for debugging
    if hasattr(mcp, '_tools'):
        print(f"\nRegistered tools in mcp._tools: {len(mcp._tools)}")
        for tool_name, tool_info in mcp._tools.items():
            print(f"  - {tool_name}")
    
    # Alternative: check __dict__ for tool decorators
    print("\nChecking for billing tool functions:")
    billing_tools = [
        'billing_check_connection',
        'billing_list_servers', 
        'billing_search_customers',
        'billing_get_customer_details',
        'billing_get_summary'
    ]
    
    for tool_name in billing_tools:
        if hasattr(server_module, tool_name):
            print(f"  ✅ {tool_name} found")
        else:
            print(f"  ❌ {tool_name} NOT found")
    
    print("\n✅ MCP tools inspection completed")
    
except Exception as e:
    print(f"❌ Error: {e}")
    import traceback
    traceback.print_exc()
    sys.exit(1)