pub trait ResourceProvider: Send + Sync {
// Required methods
fn list_resources<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
cursor: Option<&'life1 str>,
ctx: &'life2 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<(Vec<Resource>, Option<String>)>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn read_resource<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
uri: &'life1 str,
ctx: &'life2 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<Vec<ResourceContents>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
// Provided methods
fn list_templates<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<Vec<ResourceTemplate>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn subscribe<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_uri: &'life1 str,
_ctx: &'life2 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn unsubscribe<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_uri: &'life1 str,
_ctx: &'life2 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
}Expand description
Trait for implementing resource providers
Implement this trait to provide resources (files, data, etc.) to MCP clients. All methods receive a RequestContext with access to headers and request metadata.
Required Methods§
Sourcefn list_resources<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
cursor: Option<&'life1 str>,
ctx: &'life2 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<(Vec<Resource>, Option<String>)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn list_resources<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
cursor: Option<&'life1 str>,
ctx: &'life2 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<(Vec<Resource>, Option<String>)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Sourcefn read_resource<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
uri: &'life1 str,
ctx: &'life2 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<Vec<ResourceContents>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn read_resource<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
uri: &'life1 str,
ctx: &'life2 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<Vec<ResourceContents>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Provided Methods§
Sourcefn list_templates<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<Vec<ResourceTemplate>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn list_templates<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<Vec<ResourceTemplate>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
List resource templates (optional)
Resource templates define URI patterns for dynamic resources. Return empty vec if not supported.
Sourcefn subscribe<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_uri: &'life1 str,
_ctx: &'life2 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn subscribe<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_uri: &'life1 str,
_ctx: &'life2 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Subscribe to resource changes (optional)
Called when a client subscribes to changes for a specific resource. Return Ok if subscription is accepted.
Sourcefn unsubscribe<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_uri: &'life1 str,
_ctx: &'life2 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn unsubscribe<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_uri: &'life1 str,
_ctx: &'life2 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Unsubscribe from resource changes (optional)