pub trait ResourceHandler: Send + Sync {
// Required methods
fn list_resources(
&self,
ctx: &Context<'_>,
) -> impl Future<Output = Result<Vec<Resource>, McpError>> + Send;
fn read_resource(
&self,
uri: &str,
ctx: &Context<'_>,
) -> impl Future<Output = Result<Vec<ResourceContents>, McpError>> + Send;
// Provided methods
fn subscribe(
&self,
_uri: &str,
_ctx: &Context<'_>,
) -> impl Future<Output = Result<bool, McpError>> + Send { ... }
fn unsubscribe(
&self,
_uri: &str,
_ctx: &Context<'_>,
) -> impl Future<Output = Result<bool, McpError>> + Send { ... }
}Expand description
Handler for resource-related operations.
Implement this trait to expose resources that AI assistants can read.
Required Methods§
Sourcefn list_resources(
&self,
ctx: &Context<'_>,
) -> impl Future<Output = Result<Vec<Resource>, McpError>> + Send
fn list_resources( &self, ctx: &Context<'_>, ) -> impl Future<Output = Result<Vec<Resource>, McpError>> + Send
List all available resources.
Sourcefn read_resource(
&self,
uri: &str,
ctx: &Context<'_>,
) -> impl Future<Output = Result<Vec<ResourceContents>, McpError>> + Send
fn read_resource( &self, uri: &str, ctx: &Context<'_>, ) -> impl Future<Output = Result<Vec<ResourceContents>, McpError>> + Send
Read a resource by URI.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.