pub struct Resource {
pub uri: String,
pub name: String,
pub title: Option<String>,
pub description: Option<String>,
pub mime_type: Option<String>,
pub icons: Option<Vec<ToolIcon>>,
pub size: Option<u64>,
pub annotations: Option<ContentAnnotations>,
/* private fields */
}Expand description
A complete resource definition with service-based execution.
Resources are implemented as Tower services internally, enabling middleware
composition via the builder’s .layer() method. The service is wrapped
in [ResourceCatchError] to convert any errors (from handlers or middleware)
into error result responses.
Fields§
§uri: StringResource URI
name: StringHuman-readable name
title: Option<String>Human-readable title for display purposes
description: Option<String>Optional description
mime_type: Option<String>Optional MIME type
icons: Option<Vec<ToolIcon>>Optional icons for display in user interfaces
size: Option<u64>Optional size in bytes
annotations: Option<ContentAnnotations>Optional annotations (audience, priority hints)
Implementations§
Source§impl Resource
impl Resource
Sourcepub fn builder(uri: impl Into<String>) -> ResourceBuilder
pub fn builder(uri: impl Into<String>) -> ResourceBuilder
Create a new resource builder
Sourcepub fn definition(&self) -> ResourceDefinition
pub fn definition(&self) -> ResourceDefinition
Get the resource definition for resources/list
Sourcepub fn read(&self) -> BoxFuture<'static, ReadResourceResult>
pub fn read(&self) -> BoxFuture<'static, ReadResourceResult>
Read the resource without context
Creates a dummy request context. For full context support, use
read_with_context.
Sourcepub fn read_with_context(
&self,
ctx: RequestContext,
) -> BoxFuture<'static, ReadResourceResult>
pub fn read_with_context( &self, ctx: RequestContext, ) -> BoxFuture<'static, ReadResourceResult>
Read the resource with request context
The context provides progress reporting, cancellation support, and access to client requests (for sampling, etc.).
§Note
This method returns ReadResourceResult directly (not Result<ReadResourceResult>).
Any errors from the handler or middleware are converted to error responses
in the result contents.