| 
 | 1 | +using ModelContextProtocol.Client;  | 
 | 2 | +using ModelContextProtocol.Tests.Utils;  | 
 | 3 | + | 
 | 4 | +namespace ModelContextProtocol.Tests;  | 
 | 5 | + | 
 | 6 | +/// <summary>  | 
 | 7 | +/// Tests for connecting to the Microsoft Learn MCP server.  | 
 | 8 | +/// These tests connect to a real external server and are marked as manual execution.  | 
 | 9 | +/// </summary>  | 
 | 10 | +public class MicrosoftLearnServerTests(ITestOutputHelper testOutputHelper) : LoggedTest(testOutputHelper)  | 
 | 11 | +{  | 
 | 12 | +    /// <summary>  | 
 | 13 | +    /// Tests connecting to the Microsoft Learn MCP server via streamable HTTP.  | 
 | 14 | +    /// This test requires internet connectivity and access to learn.microsoft.com.  | 
 | 15 | +    /// </summary>  | 
 | 16 | +    [Fact]  | 
 | 17 | +    [Trait("Execution", "Manual")]  | 
 | 18 | +    public async Task CanConnectToMicrosoftLearnServerViaStreamableHttp()  | 
 | 19 | +    {  | 
 | 20 | +        // Arrange  | 
 | 21 | +        var transportOptions = new HttpClientTransportOptions  | 
 | 22 | +        {  | 
 | 23 | +            Endpoint = new Uri("https://learn.microsoft.com/api/mcp"),  | 
 | 24 | +            TransportMode = HttpTransportMode.StreamableHttp,  | 
 | 25 | +            Name = "Microsoft Learn MCP Server",  | 
 | 26 | +        };  | 
 | 27 | + | 
 | 28 | +        // Act  | 
 | 29 | +        await using var transport = new HttpClientTransport(transportOptions, LoggerFactory);  | 
 | 30 | +        await using var client = await McpClient.CreateAsync(  | 
 | 31 | +            transport,  | 
 | 32 | +            loggerFactory: LoggerFactory,  | 
 | 33 | +            cancellationToken: TestContext.Current.CancellationToken);  | 
 | 34 | + | 
 | 35 | +        // Assert - verify we can list tools from the server  | 
 | 36 | +        var tools = await client.ListToolsAsync(cancellationToken: TestContext.Current.CancellationToken);  | 
 | 37 | +        Assert.NotNull(tools);  | 
 | 38 | +          | 
 | 39 | +        // The server should expose some tools - we don't assert specific tools as they may change  | 
 | 40 | +        TestOutputHelper.WriteLine($"Connected to Microsoft Learn MCP server successfully.");  | 
 | 41 | +        TestOutputHelper.WriteLine($"Server: {client.ServerInfo.Name} v{client.ServerInfo.Version}");  | 
 | 42 | +        TestOutputHelper.WriteLine($"Protocol version: {client.NegotiatedProtocolVersion}");  | 
 | 43 | +        TestOutputHelper.WriteLine($"Number of tools available: {tools.Count}");  | 
 | 44 | +          | 
 | 45 | +        if (tools.Count > 0)  | 
 | 46 | +        {  | 
 | 47 | +            TestOutputHelper.WriteLine("\nAvailable tools:");  | 
 | 48 | +            foreach (var tool in tools)  | 
 | 49 | +            {  | 
 | 50 | +                TestOutputHelper.WriteLine($"  - {tool.Name}: {tool.Description}");  | 
 | 51 | +            }  | 
 | 52 | +        }  | 
 | 53 | +    }  | 
 | 54 | + | 
 | 55 | +    /// <summary>  | 
 | 56 | +    /// Tests connecting to the Microsoft Learn MCP server and verifying server capabilities.  | 
 | 57 | +    /// This test requires internet connectivity and access to learn.microsoft.com.  | 
 | 58 | +    /// </summary>  | 
 | 59 | +    [Fact]  | 
 | 60 | +    [Trait("Execution", "Manual")]  | 
 | 61 | +    public async Task MicrosoftLearnServer_HasExpectedCapabilities()  | 
 | 62 | +    {  | 
 | 63 | +        // Arrange  | 
 | 64 | +        var transportOptions = new HttpClientTransportOptions  | 
 | 65 | +        {  | 
 | 66 | +            Endpoint = new Uri("https://learn.microsoft.com/api/mcp"),  | 
 | 67 | +            TransportMode = HttpTransportMode.StreamableHttp,  | 
 | 68 | +            Name = "Microsoft Learn MCP Server",  | 
 | 69 | +        };  | 
 | 70 | + | 
 | 71 | +        // Act  | 
 | 72 | +        await using var transport = new HttpClientTransport(transportOptions, LoggerFactory);  | 
 | 73 | +        await using var client = await McpClient.CreateAsync(  | 
 | 74 | +            transport,  | 
 | 75 | +            loggerFactory: LoggerFactory,  | 
 | 76 | +            cancellationToken: TestContext.Current.CancellationToken);  | 
 | 77 | + | 
 | 78 | +        // Assert - verify basic server info  | 
 | 79 | +        Assert.NotNull(client.ServerInfo);  | 
 | 80 | +        Assert.False(string.IsNullOrEmpty(client.ServerInfo.Name), "Server should have a name");  | 
 | 81 | +        Assert.False(string.IsNullOrEmpty(client.NegotiatedProtocolVersion), "Should have negotiated a protocol version");  | 
 | 82 | + | 
 | 83 | +        // Log server capabilities  | 
 | 84 | +        TestOutputHelper.WriteLine($"Server: {client.ServerInfo.Name}");  | 
 | 85 | +        if (!string.IsNullOrEmpty(client.ServerInfo.Version))  | 
 | 86 | +        {  | 
 | 87 | +            TestOutputHelper.WriteLine($"Version: {client.ServerInfo.Version}");  | 
 | 88 | +        }  | 
 | 89 | +        TestOutputHelper.WriteLine($"Protocol: {client.NegotiatedProtocolVersion}");  | 
 | 90 | +          | 
 | 91 | +        TestOutputHelper.WriteLine("\nCapabilities:");  | 
 | 92 | +        TestOutputHelper.WriteLine($"  - Tools: {client.ServerCapabilities.Tools is not null}");  | 
 | 93 | +        TestOutputHelper.WriteLine($"  - Prompts: {client.ServerCapabilities.Prompts is not null}");  | 
 | 94 | +        TestOutputHelper.WriteLine($"  - Resources: {client.ServerCapabilities.Resources is not null}");  | 
 | 95 | +    }  | 
 | 96 | +}  | 
0 commit comments