-
Notifications
You must be signed in to change notification settings - Fork 677
Expand file tree
/
Copy pathClientCapabilitiesTests.cs
More file actions
100 lines (87 loc) · 3.75 KB
/
ClientCapabilitiesTests.cs
File metadata and controls
100 lines (87 loc) · 3.75 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.Protocol;
using System.Text.Json;
namespace ModelContextProtocol.Tests.Protocol;
public static class ClientCapabilitiesTests
{
[Fact]
public static void ClientCapabilities_SerializationRoundTrip_PreservesAllProperties()
{
var original = new ClientCapabilities
{
Roots = new RootsCapability { ListChanged = true },
Sampling = new SamplingCapability
{
Context = new SamplingContextCapability(),
Tools = new SamplingToolsCapability()
},
Elicitation = new ElicitationCapability
{
Form = new FormElicitationCapability(),
Url = new UrlElicitationCapability()
},
Tasks = new McpTasksCapability(),
Extensions = new Dictionary<string, object>
{
["io.modelcontextprotocol/test"] = new object()
}
};
string json = JsonSerializer.Serialize(original, McpJsonUtilities.DefaultOptions);
var deserialized = JsonSerializer.Deserialize<ClientCapabilities>(json, McpJsonUtilities.DefaultOptions);
Assert.NotNull(deserialized);
Assert.NotNull(deserialized.Roots);
Assert.True(deserialized.Roots.ListChanged);
Assert.NotNull(deserialized.Sampling);
Assert.NotNull(deserialized.Sampling.Context);
Assert.NotNull(deserialized.Sampling.Tools);
Assert.NotNull(deserialized.Elicitation);
Assert.NotNull(deserialized.Elicitation.Form);
Assert.NotNull(deserialized.Elicitation.Url);
Assert.NotNull(deserialized.Tasks);
Assert.NotNull(deserialized.Extensions);
Assert.True(deserialized.Extensions.ContainsKey("io.modelcontextprotocol/test"));
}
[Fact]
public static void ClientCapabilities_SerializationRoundTrip_WithMinimalProperties()
{
var original = new ClientCapabilities();
string json = JsonSerializer.Serialize(original, McpJsonUtilities.DefaultOptions);
var deserialized = JsonSerializer.Deserialize<ClientCapabilities>(json, McpJsonUtilities.DefaultOptions);
Assert.NotNull(deserialized);
Assert.Null(deserialized.Experimental);
Assert.Null(deserialized.Roots);
Assert.Null(deserialized.Sampling);
Assert.Null(deserialized.Elicitation);
Assert.Null(deserialized.Tasks);
Assert.Null(deserialized.Extensions);
}
[Fact]
public static void ClientCapabilities_Extensions_DeserializesFromJson()
{
string json = """
{
"extensions": {
"io.modelcontextprotocol/oauth-client-credentials": {},
"io.modelcontextprotocol/test-extension": {
"setting1": "value1",
"setting2": 42
}
}
}
""";
var deserialized = JsonSerializer.Deserialize<ClientCapabilities>(json, McpJsonUtilities.DefaultOptions);
Assert.NotNull(deserialized);
Assert.NotNull(deserialized.Extensions);
Assert.Equal(2, deserialized.Extensions.Count);
Assert.True(deserialized.Extensions.ContainsKey("io.modelcontextprotocol/oauth-client-credentials"));
Assert.True(deserialized.Extensions.ContainsKey("io.modelcontextprotocol/test-extension"));
}
[Fact]
public static void ClientCapabilities_Extensions_EmptyObjectDeserializesAsEmptyDictionary()
{
string json = """{"extensions": {}}""";
var deserialized = JsonSerializer.Deserialize<ClientCapabilities>(json, McpJsonUtilities.DefaultOptions);
Assert.NotNull(deserialized);
Assert.NotNull(deserialized.Extensions);
Assert.Empty(deserialized.Extensions);
}
}