using Microsoft.Extensions.AI;
using Microsoft.Extensions.DependencyInjection;
using ModelContextProtocol.Protocol;
namespace ModelContextProtocol.Server;
///
/// Indicates that a method or property should be considered an .
///
///
///
/// This attribute is applied to methods or properties that should be exposed as resources in the Model Context Protocol. When a class
/// containing methods marked with this attribute is registered with McpServerBuilderExtensions,
/// these methods or properties become available as resources that can be called by MCP clients.
///
///
/// When methods are provided directly to , the attribute is not required.
///
///
/// Read resource requests do not contain separate arguments, only a URI. However, for templated resources, portions of that URI may be considered
/// as arguments and may be bound to parameters. Further, resource methods may accept parameters that will be bound to arguments based on their type.
///
/// -
///
/// parameters are automatically bound to a provided by the
/// and that respects any s sent by the client for this operation's
/// .
///
///
/// -
///
/// parameters are bound from the for this request.
///
///
/// -
///
/// parameters are bound directly to the instance associated
/// with this request's . Such parameters may be used to understand
/// what server is being used to process the request, and to interact with the client issuing the request to that server.
///
///
/// -
///
/// parameters accepting values
/// are bound to an instance manufactured to forward progress notifications
/// from the resource to the client. If the client included a in their request, progress reports issued
/// to this instance will propagate to the client as notifications with
/// that token. If the client did not include a , the instance will ignore any progress reports issued to it.
///
///
/// -
///
/// When the is constructed, it may be passed an via
/// . Any parameter that can be satisfied by that
/// according to will be resolved from the provided to the
/// resource invocation rather than from the argument collection.
///
///
/// -
///
/// Any parameter attributed with will similarly be resolved from the
/// provided to the resource invocation rather than from the argument collection.
///
///
/// -
///
/// All other parameters are bound from the data in the URI.
///
///
///
///
///
/// Return values from a method are used to create the that is sent back to the client:
///
///
/// -
///
/// Wrapped in a list containing the single .
///
/// -
///
/// Converted to a list containing a single .
///
/// -
///
/// Converted to a list containing a single .
///
/// -
///
/// Converted to a list containing a single .
///
/// -
/// of
/// Returned directly as a list of .
///
/// -
/// of
/// Converted to a list containing a for each and a for each .
///
/// -
/// of
/// Converted to a list containing a , one for each .
///
///
///
/// Other returned types will result in an being thrown.
///
///
/// Parameters of type that are decorated with AllowedValuesAttribute
/// will automatically have their allowed values surfaced as completions in response to completion/complete requests from clients,
/// without requiring a custom to be configured.
///
///
[AttributeUsage(AttributeTargets.Method)]
public sealed class McpServerResourceAttribute : Attribute
{
///
/// Initializes a new instance of the class.
///
public McpServerResourceAttribute()
{
}
/// Gets or sets the URI template of the resource.
///
/// If , a URI will be derived from and the method's parameter names.
/// This template can, but doesn't have to, include parameters; if it does, this
/// is considered a "resource template", and if it doesn't, it is considered a "direct resource".
/// The former will be listed with requests and the latter
/// with requests.
///
public string? UriTemplate { get; set; }
/// Gets or sets the name of the resource.
/// If , the method name is used.
public string? Name { get; set; }
/// Gets or sets the title of the resource.
public string? Title { get; set; }
/// Gets or sets the MIME (media) type of the resource.
public string? MimeType { get; set; }
///
/// Gets or sets the source URI for the resource's icon.
///
///
///
/// This can be an HTTP/HTTPS URL pointing to an image file or a data URI with base64-encoded image data.
/// When specified, a single icon will be added to the resource.
///
///
/// For more advanced icon configuration (multiple icons, MIME type specification, size characteristics),
/// use when creating the resource programmatically.
///
///
public string? IconSource { get; set; }
}