-
Notifications
You must be signed in to change notification settings - Fork 689
Expand file tree
/
Copy pathResourceTemplate.cs
More file actions
125 lines (112 loc) · 4.46 KB
/
ResourceTemplate.cs
File metadata and controls
125 lines (112 loc) · 4.46 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using ModelContextProtocol.Server;
namespace ModelContextProtocol.Protocol;
/// <summary>
/// Represents a known resource template that the server is capable of reading.
/// </summary>
/// <remarks>
/// Resource templates provide metadata about resources available on the server,
/// including how to construct URIs for those resources.
/// </remarks>
public sealed class ResourceTemplate : IBaseMetadata
{
/// <inheritdoc />
[JsonPropertyName("name")]
public required string Name { get; set; }
/// <inheritdoc />
[JsonPropertyName("title")]
public string? Title { get; set; }
/// <summary>
/// Gets or sets the URI template (according to RFC 6570) that can be used to construct resource URIs.
/// </summary>
[JsonPropertyName("uriTemplate")]
public required string UriTemplate { get; init; }
/// <summary>
/// Gets or sets a description of what this resource template represents.
/// </summary>
/// <remarks>
/// <para>
/// This description helps clients understand the purpose and content of resources
/// that can be generated from this template. It can be used by client applications
/// to provide context about available resource types or to display in user interfaces.
/// </para>
/// <para>
/// For AI models, this description can serve as a hint about when and how to use
/// the resource template, enhancing the model's ability to generate appropriate URIs.
/// </para>
/// </remarks>
[JsonPropertyName("description")]
public string? Description { get; init; }
/// <summary>
/// Gets or sets the MIME type of this resource template, if known.
/// </summary>
/// <remarks>
/// <para>
/// Specifies the expected format of resources that can be generated from this template.
/// This helps clients understand what type of content to expect when accessing resources
/// created using this template.
/// </para>
/// <para>
/// Common MIME types include "text/plain" for plain text, "application/pdf" for PDF documents,
/// "image/png" for PNG images, or "application/json" for JSON data.
/// </para>
/// </remarks>
[JsonPropertyName("mimeType")]
public string? MimeType { get; init; }
/// <summary>
/// Gets or sets optional annotations for the resource template.
/// </summary>
/// <remarks>
/// These annotations can be used to specify the intended audience (<see cref="Role.User"/>, <see cref="Role.Assistant"/>, or both)
/// and the priority level of the resource template. Clients can use this information to filter
/// or prioritize resource templates for different roles.
/// </remarks>
[JsonPropertyName("annotations")]
public Annotations? Annotations { get; init; }
/// <summary>
/// Gets or sets an optional list of icons for this resource template.
/// </summary>
/// <remarks>
/// This can be used by clients to display the resource template's icon in a user interface.
/// </remarks>
[JsonPropertyName("icons")]
public IList<Icon>? Icons { get; set; }
/// <summary>
/// Gets or sets metadata reserved by MCP for protocol-level metadata.
/// </summary>
/// <remarks>
/// Implementations must not make assumptions about its contents.
/// </remarks>
[JsonPropertyName("_meta")]
public JsonObject? Meta { get; init; }
/// <summary>Gets whether <see cref="UriTemplate"/> contains any template expressions.</summary>
[JsonIgnore]
public bool IsTemplated => UriTemplate.Contains('{');
/// <summary>
/// Gets or sets the callable server resource corresponding to this metadata if any.
/// </summary>
[JsonIgnore]
public McpServerResource? McpServerResource { get; set; }
/// <summary>Converts the <see cref="ResourceTemplate"/> into a <see cref="Resource"/>.</summary>
/// <returns>A <see cref="Resource"/> if <see cref="IsTemplated"/> is <see langword="false"/>; otherwise, <see langword="null"/>.</returns>
public Resource? AsResource()
{
if (IsTemplated)
{
return null;
}
return new()
{
Uri = UriTemplate,
Name = Name,
Title = Title,
Description = Description,
MimeType = MimeType,
Annotations = Annotations,
Icons = Icons,
Meta = Meta,
McpServerResource = McpServerResource,
};
}
}