pub trait ResourceProvider: Send + Sync {
// Required methods
fn list_resources<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<ResourceDescriptor>, CapabilityError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn read_resource<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
id: &'life1 ResourceId,
ctx: &'life2 mut CapabilityContext<'life3>,
) -> Pin<Box<dyn Future<Output = Result<ResourceContents, CapabilityError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait;
}Expand description
A provider of named data resources that can be listed and read.
Implement this trait to expose data sources – files on disk, database rows, API responses – to the model. The agentkit MCP bridge uses this trait to surface MCP-server resources into the agentic loop.
§Example
use agentkit_capabilities::{
CapabilityContext, CapabilityError, ResourceContents,
ResourceDescriptor, ResourceId, ResourceProvider,
};
use agentkit_core::{DataRef, MetadataMap};
use async_trait::async_trait;
struct StaticFile;
#[async_trait]
impl ResourceProvider for StaticFile {
async fn list_resources(&self) -> Result<Vec<ResourceDescriptor>, CapabilityError> {
Ok(vec![ResourceDescriptor {
id: ResourceId::new("readme"),
name: "README.md".into(),
description: Some("Project readme".into()),
mime_type: Some("text/markdown".into()),
metadata: MetadataMap::new(),
}])
}
async fn read_resource(
&self,
id: &ResourceId,
_ctx: &mut CapabilityContext<'_>,
) -> Result<ResourceContents, CapabilityError> {
if id.as_str() == "readme" {
Ok(ResourceContents {
data: DataRef::InlineText("# Hello".into()),
metadata: MetadataMap::new(),
})
} else {
Err(CapabilityError::Unavailable(format!(
"unknown resource: {id}"
)))
}
}
}Required Methods§
Sourcefn list_resources<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<ResourceDescriptor>, CapabilityError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn list_resources<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<ResourceDescriptor>, CapabilityError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Lists all resources currently available from this provider.
§Errors
Returns CapabilityError if the provider cannot enumerate its
resources (e.g. a network timeout).
Sourcefn read_resource<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
id: &'life1 ResourceId,
ctx: &'life2 mut CapabilityContext<'life3>,
) -> Pin<Box<dyn Future<Output = Result<ResourceContents, CapabilityError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn read_resource<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
id: &'life1 ResourceId,
ctx: &'life2 mut CapabilityContext<'life3>,
) -> Pin<Box<dyn Future<Output = Result<ResourceContents, CapabilityError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Reads the contents of the resource identified by id.
§Arguments
id- The unique resource identifier, as returned in aResourceDescriptor.ctx- The shared capability context for this turn.
§Errors
Returns CapabilityError::Unavailable if the resource does not exist
or CapabilityError::ExecutionFailed if reading fails.