-
Notifications
You must be signed in to change notification settings - Fork 681
Expand file tree
/
Copy pathMicrosoftLearnMcpServerTests.cs
More file actions
100 lines (85 loc) · 3.41 KB
/
MicrosoftLearnMcpServerTests.cs
File metadata and controls
100 lines (85 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using ModelContextProtocol.Client;
using ModelContextProtocol.Protocol;
using ModelContextProtocol.Tests.Utils;
namespace ModelContextProtocol.Tests;
/// <summary>
/// Integration tests for connecting to the Microsoft Learn MCP server.
/// These tests connect to a live external service and are marked as Manual execution.
/// </summary>
public class MicrosoftLearnMcpServerTests(ITestOutputHelper testOutputHelper) : LoggedTest(testOutputHelper)
{
private const string MicrosoftLearnMcpEndpoint = "https://learn.microsoft.com/api/mcp";
private Task<McpClient> CreateClientAsync(CancellationToken cancellationToken = default)
{
var transportOptions = new HttpClientTransportOptions
{
Endpoint = new Uri(MicrosoftLearnMcpEndpoint),
Name = "Microsoft Learn MCP Server",
TransportMode = HttpTransportMode.StreamableHttp,
};
var clientOptions = new McpClientOptions
{
ClientInfo = new() { Name = "CSharpSdkIntegrationTest", Version = "1.0.0" }
};
return McpClient.CreateAsync(
new HttpClientTransport(transportOptions),
clientOptions,
loggerFactory: LoggerFactory,
cancellationToken: cancellationToken);
}
[Fact]
[Trait("Execution", "Manual")]
public async Task ConnectAndInitialize_MicrosoftLearnServer_WithStreamableHttp()
{
// Act
await using var client = await CreateClientAsync(TestContext.Current.CancellationToken);
// Assert
Assert.NotNull(client);
Assert.NotNull(client.ServerCapabilities);
Assert.NotNull(client.ServerInfo);
Assert.NotNull(client.NegotiatedProtocolVersion);
}
[Fact]
[Trait("Execution", "Manual")]
public async Task ListTools_MicrosoftLearnServer()
{
// Act
await using var client = await CreateClientAsync(TestContext.Current.CancellationToken);
var tools = await client.ListToolsAsync(cancellationToken: TestContext.Current.CancellationToken);
// Assert
Assert.NotNull(tools);
Assert.NotEmpty(tools);
}
[Fact]
[Trait("Execution", "Manual")]
public async Task ListResources_MicrosoftLearnServer()
{
// Act
await using var client = await CreateClientAsync(TestContext.Current.CancellationToken);
var resources = await client.ListResourcesAsync(TestContext.Current.CancellationToken);
// Assert
Assert.NotNull(resources);
// Microsoft Learn server may or may not have resources, so we don't assert NotEmpty
}
[Fact]
[Trait("Execution", "Manual")]
public async Task ListPrompts_MicrosoftLearnServer()
{
// Act
await using var client = await CreateClientAsync(TestContext.Current.CancellationToken);
var prompts = await client.ListPromptsAsync(TestContext.Current.CancellationToken);
// Assert
Assert.NotNull(prompts);
// Microsoft Learn server may or may not have prompts, so we don't assert NotEmpty
}
[Fact]
[Trait("Execution", "Manual")]
public async Task PingServer_MicrosoftLearnServer()
{
// Act
await using var client = await CreateClientAsync(TestContext.Current.CancellationToken);
await client.PingAsync(TestContext.Current.CancellationToken);
// Assert - if we get here without exception, ping was successful
Assert.True(true);
}
}