Skip to content

Commit 0cbcad7

Browse files
authored
Refactor Resource/ResourceTemplate to subclass Annotated (#50)
The `Resource` and `ResourceTemplate` types should derive from a base `Annotated` type having the `Annotations` property as per the [spec](https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.ts#L821) This small change makes the C# types match the schema more closely. Also renamed Resources.cs to Resource.cs to reflect the type name.
1 parent fe6b401 commit 0cbcad7

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace ModelContextProtocol.Protocol.Types;
4+
5+
/// <summary>
6+
/// Base for objects that include optional annotations for the client. The client can use annotations to inform how objects are used or displayed.
7+
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json">See the schema for details</see>
8+
/// </summary>
9+
public abstract record Annotated
10+
{
11+
/// <summary>
12+
/// Optional annotations for the resource.
13+
/// </summary>
14+
[JsonPropertyName("annotations")]
15+
public Annotations? Annotations { get; init; }
16+
}

src/ModelContextProtocol/Protocol/Types/Resources.cs renamed to src/ModelContextProtocol/Protocol/Types/Resource.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace ModelContextProtocol.Protocol.Types;
66
/// Represents a known resource that the server is capable of reading.
77
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json">See the schema for details</see>
88
/// </summary>
9-
public record Resource
9+
public record Resource : Annotated
1010
{
1111
/// <summary>
1212
/// The URI of this resource.
@@ -31,10 +31,4 @@ public record Resource
3131
/// </summary>
3232
[JsonPropertyName("mimeType")]
3333
public string? MimeType { get; init; }
34-
35-
/// <summary>
36-
/// Optional annotations for the resource.
37-
/// </summary>
38-
[JsonPropertyName("annotations")]
39-
public Annotations? Annotations { get; init; }
4034
}

src/ModelContextProtocol/Protocol/Types/ResourceTemplate.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace ModelContextProtocol.Protocol.Types;
88
/// Represents a known resource template that the server is capable of reading.
99
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json">See the schema for details</see>
1010
/// </summary>
11-
public record ResourceTemplate
11+
public record ResourceTemplate : Annotated
1212
{
1313
/// <summary>
1414
/// The URI template (according to RFC 6570) that can be used to construct resource URIs.
@@ -33,10 +33,4 @@ public record ResourceTemplate
3333
/// </summary>
3434
[JsonPropertyName("mimeType")]
3535
public string? MimeType { get; init; }
36-
37-
/// <summary>
38-
/// Optional annotations for the resource template.
39-
/// </summary>
40-
[JsonPropertyName("annotations")]
41-
public Annotations? Annotations { get; init; }
4236
}

0 commit comments

Comments
 (0)