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.
This commit is contained in:
parent
fe6b401014
commit
0cbcad7447
3 changed files with 18 additions and 14 deletions
16
src/ModelContextProtocol/Protocol/Types/Annotated.cs
Normal file
16
src/ModelContextProtocol/Protocol/Types/Annotated.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ModelContextProtocol.Protocol.Types;
|
||||
|
||||
/// <summary>
|
||||
/// Base for objects that include optional annotations for the client. The client can use annotations to inform how objects are used or displayed.
|
||||
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json">See the schema for details</see>
|
||||
/// </summary>
|
||||
public abstract record Annotated
|
||||
{
|
||||
/// <summary>
|
||||
/// Optional annotations for the resource.
|
||||
/// </summary>
|
||||
[JsonPropertyName("annotations")]
|
||||
public Annotations? Annotations { get; init; }
|
||||
}
|
||||
34
src/ModelContextProtocol/Protocol/Types/Resource.cs
Normal file
34
src/ModelContextProtocol/Protocol/Types/Resource.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ModelContextProtocol.Protocol.Types;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a known resource that the server is capable of reading.
|
||||
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json">See the schema for details</see>
|
||||
/// </summary>
|
||||
public record Resource : Annotated
|
||||
{
|
||||
/// <summary>
|
||||
/// The URI of this resource.
|
||||
/// </summary>
|
||||
[JsonPropertyName("uri")]
|
||||
public required string Uri { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// A human-readable name for this resource.
|
||||
/// </summary>
|
||||
[JsonPropertyName("name")]
|
||||
public required string Name { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// A description of what this resource represents.
|
||||
/// </summary>
|
||||
[JsonPropertyName("description")]
|
||||
public string? Description { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The MIME type of this resource, if known.
|
||||
/// </summary>
|
||||
[JsonPropertyName("mimeType")]
|
||||
public string? MimeType { get; init; }
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ namespace ModelContextProtocol.Protocol.Types;
|
|||
/// Represents a known resource template that the server is capable of reading.
|
||||
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json">See the schema for details</see>
|
||||
/// </summary>
|
||||
public record ResourceTemplate
|
||||
public record ResourceTemplate : Annotated
|
||||
{
|
||||
/// <summary>
|
||||
/// The URI template (according to RFC 6570) that can be used to construct resource URIs.
|
||||
|
|
@ -33,10 +33,4 @@ public record ResourceTemplate
|
|||
/// </summary>
|
||||
[JsonPropertyName("mimeType")]
|
||||
public string? MimeType { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional annotations for the resource template.
|
||||
/// </summary>
|
||||
[JsonPropertyName("annotations")]
|
||||
public Annotations? Annotations { get; init; }
|
||||
}
|
||||
Loading…
Reference in a new issue