import json

print("=== Testing DNS Functionality in Vultr MCP Server ===\n")

# Read server.py
with open('src/vultr_mcp/server.py', 'r') as f:
    content = f.read()

# 1. Check DNS tools in tools list
tools_section_start = content.find('@app.get("/tools")')
tools_section_end = content.find('return tools', tools_section_start)
tools_section = content[tools_section_start:tools_section_end]

dns_tools_in_list = []
for line in tools_section.split('\n'):
    if 'name="list_dns_domains"' in line or \
       'name="create_dns_domain"' in line or \
       'name="delete_dns_domain"' in line or \
       'name="get_dns_domain"' in line or \
       'name="list_dns_records"' in line or \
       'name="create_dns_record"' in line or \
       'name="update_dns_record"' in line or \
       'name="delete_dns_record"' in line:
        # Extract tool name
        if 'name=' in line:
            name = line.split('name=')[1].split('"')[1]
            dns_tools_in_list.append(name)

print(f"1. DNS Tools in /tools endpoint: {len(dns_tools_in_list)} tools")
for tool in sorted(dns_tools_in_list):
    print(f"   ✓ {tool}")

# 2. Check DNS tool handling in call_tool function
dns_tools_in_handler = []
lines = content.split('\n')
for i, line in enumerate(lines):
    if 'elif request.name ==' in line and 'dns' in line.lower():
        tool_name = line.split('"')[1]
        dns_tools_in_handler.append(tool_name)

print(f"\n2. DNS Tools in call_tool handler: {len(dns_tools_in_handler)} tools")
for tool in sorted(dns_tools_in_handler):
    print(f"   ✓ {tool}")

# 3. Check DNS resources
dns_resources = []
for line in lines:
    if 'uri="vultr://dns' in line:
        uri = line.split('uri="')[1].split('"')[0]
        dns_resources.append(uri)

print(f"\n3. DNS Resources in /resources endpoint: {len(dns_resources)} resources")
for resource in sorted(dns_resources):
    print(f"   ✓ {resource}")

# 4. Check DNS prompts
dns_prompts = []
for line in lines:
    if 'name="manage_dns"' in line:
        dns_prompts.append('manage_dns')

print(f"\n4. DNS Prompts in /prompts endpoint: {len(dns_prompts)} prompts")
for prompt in dns_prompts:
    print(f"   ✓ {prompt}")

# 5. Verify all DNS tools are properly connected
print("\n5. Verification Summary:")
all_dns_tools = [
    'list_dns_domains',
    'create_dns_domain',
    'delete_dns_domain',
    'get_dns_domain',
    'list_dns_records',
    'create_dns_record',
    'update_dns_record',
    'delete_dns_record'
]

missing_in_list = [t for t in all_dns_tools if t not in dns_tools_in_list]
missing_in_handler = [t for t in all_dns_tools if t not in dns_tools_in_handler]

if not missing_in_list and not missing_in_handler:
    print("   ✓ All 8 DNS tools are properly implemented!")
else:
    if missing_in_list:
        print(f"   ✗ Missing in tools list: {missing_in_list}")
    if missing_in_handler:
        print(f"   ✗ Missing in call_tool handler: {missing_in_handler}")

print("\n=== DNS Functionality Test Complete ===")
