// C# Script to explore ModelContextProtocol SDK APIs
#r "nuget: ModelContextProtocol, 0.4.0-preview.3"

using System;
using System.Reflection;
using System.Linq;

// Load the ModelContextProtocol assembly
var mcpAssembly = Assembly.Load("ModelContextProtocol");

Console.WriteLine("=== ModelContextProtocol SDK API Exploration ===");
Console.WriteLine($"Assembly: {mcpAssembly.FullName}");
Console.WriteLine();

// Get all public types
var types = mcpAssembly.GetExportedTypes()
    .OrderBy(t => t.Namespace)
    .ThenBy(t => t.Name);

Console.WriteLine($"Total Public Types: {types.Count()}");
Console.WriteLine();

// Group by namespace
var namespaces = types.GroupBy(t => t.Namespace ?? "No Namespace");

foreach (var ns in namespaces)
{
    Console.WriteLine($"\n### Namespace: {ns.Key}");
    Console.WriteLine(new string('-', 60));

    foreach (var type in ns)
    {
        var typeKind = type.IsInterface ? "interface" :
                       type.IsClass && type.IsAbstract ? "abstract class" :
                       type.IsClass ? "class" :
                       type.IsEnum ? "enum" :
                       type.IsValueType ? "struct" : "type";

        Console.WriteLine($"  [{typeKind}] {type.Name}");

        // Show attributes
        var attrs = type.GetCustomAttributes(false);
        if (attrs.Any())
        {
            foreach (var attr in attrs)
            {
                Console.WriteLine($"    @{attr.GetType().Name}");
            }
        }
    }
}

// Look for specific patterns
Console.WriteLine("\n\n=== Looking for MCP-Specific Patterns ===");
Console.WriteLine(new string('-', 60));

// Look for Tool-related types
var toolTypes = types.Where(t => t.Name.Contains("Tool", StringComparison.OrdinalIgnoreCase));
Console.WriteLine($"\nTool-related types ({toolTypes.Count()}):");
foreach (var t in toolTypes)
{
    Console.WriteLine($"  - {t.FullName}");
}

// Look for Resource-related types
var resourceTypes = types.Where(t => t.Name.Contains("Resource", StringComparison.OrdinalIgnoreCase));
Console.WriteLine($"\nResource-related types ({resourceTypes.Count()}):");
foreach (var t in resourceTypes)
{
    Console.WriteLine($"  - {t.FullName}");
}

// Look for Attribute types
var attributeTypes = types.Where(t => t.Name.EndsWith("Attribute", StringComparison.OrdinalIgnoreCase));
Console.WriteLine($"\nAttribute types ({attributeTypes.Count()}):");
foreach (var t in attributeTypes)
{
    Console.WriteLine($"  - {t.Name}");
}

// Look for Server-related types
var serverTypes = types.Where(t => t.Name.Contains("Server", StringComparison.OrdinalIgnoreCase));
Console.WriteLine($"\nServer-related types ({serverTypes.Count()}):");
foreach (var t in serverTypes)
{
    Console.WriteLine($"  - {t.FullName}");
}

// Look for Client-related types
var clientTypes = types.Where(t => t.Name.Contains("Client", StringComparison.OrdinalIgnoreCase));
Console.WriteLine($"\nClient-related types ({clientTypes.Count()}):");
foreach (var t in clientTypes)
{
    Console.WriteLine($"  - {t.FullName}");
}

// Look for Transport-related types
var transportTypes = types.Where(t => t.Name.Contains("Transport", StringComparison.OrdinalIgnoreCase));
Console.WriteLine($"\nTransport-related types ({transportTypes.Count()}):");
foreach (var t in transportTypes)
{
    Console.WriteLine($"  - {t.FullName}");
}

Console.WriteLine("\n=== Exploration Complete ===");
