pub struct ResourceBuilder { /* private fields */ }Expand description
Builder for creating resources with a fluent API
§Example
use tower_mcp::resource::ResourceBuilder;
use tower_mcp::protocol::{ReadResourceResult, ResourceContent};
let resource = ResourceBuilder::new("file:///config.json")
.name("Configuration")
.description("Application configuration file")
.mime_type("application/json")
.handler(|| async {
Ok(ReadResourceResult {
contents: vec![ResourceContent {
uri: "file:///config.json".to_string(),
mime_type: Some("application/json".to_string()),
text: Some(r#"{"setting": "value"}"#.to_string()),
blob: None,
}],
})
})
.build();
assert_eq!(resource.uri, "file:///config.json");Implementations§
Source§impl ResourceBuilder
impl ResourceBuilder
pub fn new(uri: impl Into<String>) -> Self
Sourcepub fn title(self, title: impl Into<String>) -> Self
pub fn title(self, title: impl Into<String>) -> Self
Set a human-readable title for the resource
Sourcepub fn description(self, description: impl Into<String>) -> Self
pub fn description(self, description: impl Into<String>) -> Self
Set the resource description
Sourcepub fn icon_with_meta(
self,
src: impl Into<String>,
mime_type: Option<String>,
sizes: Option<Vec<String>>,
) -> Self
pub fn icon_with_meta( self, src: impl Into<String>, mime_type: Option<String>, sizes: Option<Vec<String>>, ) -> Self
Add an icon with metadata
Sourcepub fn handler<F, Fut>(self, handler: F) -> ResourceBuilderWithHandler<F>
pub fn handler<F, Fut>(self, handler: F) -> ResourceBuilderWithHandler<F>
Set the handler function for reading the resource.
Returns a ResourceBuilderWithHandler that can be used to apply
middleware layers via .layer() or build the resource directly via .build().
Sourcepub fn handler_with_context<F, Fut>(
self,
handler: F,
) -> ResourceBuilderWithContextHandler<F>where
F: Fn(RequestContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<ReadResourceResult>> + Send + 'static,
pub fn handler_with_context<F, Fut>(
self,
handler: F,
) -> ResourceBuilderWithContextHandler<F>where
F: Fn(RequestContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<ReadResourceResult>> + Send + 'static,
Set a context-aware handler for reading the resource.
The handler receives a RequestContext for progress reporting and
cancellation checking.
Returns a ResourceBuilderWithContextHandler that can be used to apply
middleware layers via .layer() or build the resource directly via .build().
Auto Trait Implementations§
impl Freeze for ResourceBuilder
impl RefUnwindSafe for ResourceBuilder
impl Send for ResourceBuilder
impl Sync for ResourceBuilder
impl Unpin for ResourceBuilder
impl UnwindSafe for ResourceBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more