Skip to content

Commit 54c7829

Browse files
Apply suggestions from code review
Co-authored-by: Stephen Toub <[email protected]>
1 parent 25d54a6 commit 54c7829

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

src/ModelContextProtocol/Protocol/Types/Resource.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public record Resource
4242
/// This can be used by Hosts to display file sizes and estimate context window usage.
4343
/// </summary>
4444
[JsonPropertyName("size")]
45-
4645
public long? Size { get; init; }
4746

4847
/// <summary>

src/ModelContextProtocol/Protocol/Types/ResourceContents.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,15 @@ public class ResourceContentsConverter : JsonConverter<ResourceContents>
5252
string? blob = null;
5353
string? text = null;
5454

55-
while (reader.Read())
55+
while (reader.Read() && reader.TokenType != JsonTokenType.EndObject)
5656
{
57-
if (reader.TokenType == JsonTokenType.EndObject)
58-
{
59-
break;
60-
}
61-
62-
string? propertyName = reader.GetString();
63-
64-
if (propertyName == null)
57+
if (reader.TokenType != JsonTokenType.PropertyName)
6558
{
6659
continue;
6760
}
6861

62+
string propertyName = reader.GetString();
63+
6964
switch (propertyName)
7065
{
7166
case "uri":
@@ -94,6 +89,7 @@ public class ResourceContentsConverter : JsonConverter<ResourceContents>
9489
Blob = blob
9590
};
9691
}
92+
9793
if (text is not null)
9894
{
9995
return new TextResourceContents
@@ -103,6 +99,7 @@ public class ResourceContentsConverter : JsonConverter<ResourceContents>
10399
Text = text
104100
};
105101
}
102+
106103
return null;
107104
}
108105

@@ -118,6 +115,7 @@ public override void Write(Utf8JsonWriter writer, ResourceContents value, JsonSe
118115
writer.WriteStartObject();
119116
writer.WriteString("uri", value.Uri);
120117
writer.WriteString("mimeType", value.MimeType);
118+
Debug.Assert(value is BlobResourceContents or TextResourceContents);
121119
if (value is BlobResourceContents blobResource)
122120
{
123121
writer.WriteString("blob", blobResource.Blob);

tests/ModelContextProtocol.Tests/Server/McpServerResourceTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using ModelContextProtocol.Server;
44

55
namespace ModelContextProtocol.Tests.Server;
6+
67
public class McpServerResourceTests
78
{
89
[Fact]

0 commit comments

Comments
 (0)