ResourceHandler

Trait ResourceHandler 

Source
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§

Source

fn list_resources( &self, ctx: &Context<'_>, ) -> impl Future<Output = Result<Vec<Resource>, McpError>> + Send

List all available resources.

Source

fn read_resource( &self, uri: &str, ctx: &Context<'_>, ) -> impl Future<Output = Result<Vec<ResourceContents>, McpError>> + Send

Read a resource by URI.

Provided Methods§

Source

fn subscribe( &self, _uri: &str, _ctx: &Context<'_>, ) -> impl Future<Output = Result<bool, McpError>> + Send

Subscribe to resource updates.

Returns true if the subscription was successful.

Source

fn unsubscribe( &self, _uri: &str, _ctx: &Context<'_>, ) -> impl Future<Output = Result<bool, McpError>> + Send

Unsubscribe from resource updates.

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.

Implementations on Foreign Types§

Source§

impl<T: ResourceHandler> ResourceHandler for Arc<T>

Source§

fn list_resources( &self, ctx: &Context<'_>, ) -> impl Future<Output = Result<Vec<Resource>, McpError>> + Send

Source§

fn read_resource( &self, uri: &str, ctx: &Context<'_>, ) -> impl Future<Output = Result<Vec<ResourceContents>, McpError>> + Send

Source§

fn subscribe( &self, uri: &str, ctx: &Context<'_>, ) -> impl Future<Output = Result<bool, McpError>> + Send

Source§

fn unsubscribe( &self, uri: &str, ctx: &Context<'_>, ) -> impl Future<Output = Result<bool, McpError>> + Send

Implementors§