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,
}],
})
});
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) -> Resource
pub fn handler<F, Fut>(self, handler: F) -> Resource
Set the handler function for reading the resource
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