Skip to main content

ResourceReader

Trait ResourceReader 

Source
pub trait ResourceReader: Send + Sync {
    // Required method
    fn read_resource(
        &self,
        cx: &Cx,
        uri: &str,
        depth: u32,
    ) -> Pin<Box<dyn Future<Output = McpResult<ResourceReadResult>> + Send + '_>>;
}
Expand description

Trait for reading resources from within handlers.

This trait is implemented by the server’s Router to allow tools, resources, and prompts to read other resources. It enables cross-component composition and code reuse.

The trait uses boxed futures to avoid complex lifetime issues with async traits.

Required Methods§

Source

fn read_resource( &self, cx: &Cx, uri: &str, depth: u32, ) -> Pin<Box<dyn Future<Output = McpResult<ResourceReadResult>> + Send + '_>>

Reads a resource by URI.

§Arguments
  • cx - The asupersync context
  • uri - The resource URI to read
  • depth - Current recursion depth (to prevent infinite loops)
§Returns

The resource contents, or an error if the resource doesn’t exist or reading fails.

Implementors§