Skip to content

Commit dd1cbae

Browse files
committed
Address feedback
1 parent d542f7b commit dd1cbae

16 files changed

+652
-1844
lines changed

src/ModelContextProtocol/Configuration/McpServerBuilderExtensions.cs

+26-189
Large diffs are not rendered by default.

src/ModelContextProtocol/Protocol/Types/ResourceTemplate.cs

+23
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,27 @@ public record ResourceTemplate
6767
/// </remarks>
6868
[JsonPropertyName("annotations")]
6969
public Annotations? Annotations { get; init; }
70+
71+
/// <summary>Gets whether <see cref="UriTemplate"/> contains any template expressions.</summary>
72+
[JsonIgnore]
73+
public bool IsTemplated => UriTemplate.Contains('{');
74+
75+
/// <summary>Converts the <see cref="ResourceTemplate"/> into a <see cref="Resource"/>.</summary>
76+
/// <returns>A <see cref="Resource"/> if <see cref="IsTemplated"/> is <see langword="false"/>; otherwise, <see langword="null"/>.</returns>
77+
public Resource? AsResource()
78+
{
79+
if (IsTemplated)
80+
{
81+
return null;
82+
}
83+
84+
return new()
85+
{
86+
Uri = UriTemplate,
87+
Name = Name,
88+
Description = Description,
89+
MimeType = MimeType,
90+
Annotations = Annotations,
91+
};
92+
}
7093
}

src/ModelContextProtocol/Protocol/Types/ResourcesCapability.cs

+10-20
Original file line numberDiff line numberDiff line change
@@ -92,27 +92,17 @@ public class ResourcesCapability
9292
/// Gets or sets a collection of resources served by the server.
9393
/// </summary>
9494
/// <remarks>
95-
/// Resources will specified via <see cref="ResourceCollection"/> augment the <see cref="ListResourcesHandler"/> and
96-
/// <see cref="ReadResourceHandler"/>, if provided. ListResources requests will output information about every resource
97-
/// in <see cref="ResourceCollection"/> and then also any resources output by <see cref="ListResourcesHandler"/>, if it's
98-
/// non-<see langword="null"/>. ReadResource requests will first check <see cref="ResourceCollection"/> for the exact resource
99-
/// being requested, will then fall back to <see cref="ResourceTemplateCollection"/> if no exact match could be found, and if the resource
100-
/// is still not found, any specified <see cref="ReadResourceHandler"/> will be invoked as a fallback.
95+
/// <para>
96+
/// Resources specified via <see cref="ResourceCollection"/> augment the <see cref="ListResourcesHandler"/>, <see cref="ListResourceTemplatesHandler"/>
97+
/// and <see cref="ReadResourceHandler"/> handlers, if provided. Resources with template expressions in their URI templates are considered resource templates
98+
/// and are listed via ListResourceTemplate, whereas resources without template parameters are considered static resources and are listed with ListResources.
99+
/// </para>
100+
/// <para>
101+
/// ReadResource requests will first check the <see cref="ResourceCollection"/> for the exact resource being requested. If no match is found, they'll proceed to
102+
/// try to match the resource against each resource template in <see cref="ResourceCollection"/>. If no match is still found, the request will fall back to
103+
/// any handler registered for <see cref="ReadResourceHandler"/>.
104+
/// </para>
101105
/// </remarks>
102106
[JsonIgnore]
103107
public McpServerPrimitiveCollection<McpServerResource>? ResourceCollection { get; set; }
104-
105-
/// <summary>
106-
/// Gets or sets a collection of resource templates served by the server.
107-
/// </summary>
108-
/// <remarks>
109-
/// Resource templates will specified via <see cref="ResourceTemplateCollection"/> augment the <see cref="ListResourceTemplatesHandler"/> and
110-
/// <see cref="ReadResourceHandler"/>, if provided. ListResourceTemplates requests will output information about every resource template
111-
/// in <see cref="ResourceTemplateCollection"/> and then also any resources output by <see cref="ListResourceTemplatesHandler"/>, if it's
112-
/// non-<see langword="null"/>. ReadResource requests will first check <see cref="ResourceCollection"/> for the exact resource
113-
/// being requested, will then fall back to <see cref="ResourceTemplateCollection"/> if no exact match could be found, and if the resource
114-
/// is still not found, any specified <see cref="ReadResourceHandler"/> will be invoked as a fallback.
115-
/// </remarks>
116-
[JsonIgnore]
117-
public McpServerPrimitiveCollection<McpServerResourceTemplate>? ResourceTemplateCollection { get; set; }
118108
}

0 commit comments

Comments
 (0)