pub struct ReadResourceResult {
pub contents: Vec<ResourceContent>,
}Fields§
§contents: Vec<ResourceContent>Implementations§
Source§impl ReadResourceResult
impl ReadResourceResult
Sourcepub fn text(uri: impl Into<String>, content: impl Into<String>) -> Self
pub fn text(uri: impl Into<String>, content: impl Into<String>) -> Self
Create a result with text content.
§Example
use tower_mcp::ReadResourceResult;
let result = ReadResourceResult::text("file://readme.md", "# Hello World");Sourcepub fn text_with_mime(
uri: impl Into<String>,
content: impl Into<String>,
mime_type: impl Into<String>,
) -> Self
pub fn text_with_mime( uri: impl Into<String>, content: impl Into<String>, mime_type: impl Into<String>, ) -> Self
Create a result with text content and a specific MIME type.
§Example
use tower_mcp::ReadResourceResult;
let result = ReadResourceResult::text_with_mime(
"file://readme.md",
"# Hello World",
"text/markdown"
);Sourcepub fn json<T: Serialize>(uri: impl Into<String>, value: &T) -> Self
pub fn json<T: Serialize>(uri: impl Into<String>, value: &T) -> Self
Create a result with JSON content.
The value is serialized to a JSON string automatically.
§Example
use tower_mcp::ReadResourceResult;
use serde_json::json;
let data = json!({"name": "example", "count": 42});
let result = ReadResourceResult::json("data://config", &data);Sourcepub fn blob(uri: impl Into<String>, bytes: &[u8]) -> Self
pub fn blob(uri: impl Into<String>, bytes: &[u8]) -> Self
Create a result with binary content (base64 encoded).
§Example
use tower_mcp::ReadResourceResult;
let bytes = vec![0x89, 0x50, 0x4E, 0x47]; // PNG magic bytes
let result = ReadResourceResult::blob("file://image.png", &bytes);Sourcepub fn blob_with_mime(
uri: impl Into<String>,
bytes: &[u8],
mime_type: impl Into<String>,
) -> Self
pub fn blob_with_mime( uri: impl Into<String>, bytes: &[u8], mime_type: impl Into<String>, ) -> Self
Create a result with binary content and a specific MIME type.
§Example
use tower_mcp::ReadResourceResult;
let bytes = vec![0x89, 0x50, 0x4E, 0x47];
let result = ReadResourceResult::blob_with_mime("file://image.png", &bytes, "image/png");Sourcepub fn first_text(&self) -> Option<&str>
pub fn first_text(&self) -> Option<&str>
Get the text from the first content item.
Returns None if there are no contents or the first item has no text.
§Example
use tower_mcp::ReadResourceResult;
let result = ReadResourceResult::text("file://readme.md", "# Hello");
assert_eq!(result.first_text(), Some("# Hello"));Trait Implementations§
Source§impl Clone for ReadResourceResult
impl Clone for ReadResourceResult
Source§fn clone(&self) -> ReadResourceResult
fn clone(&self) -> ReadResourceResult
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ReadResourceResult
impl Debug for ReadResourceResult
Source§impl<'de> Deserialize<'de> for ReadResourceResult
impl<'de> Deserialize<'de> for ReadResourceResult
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for ReadResourceResult
impl RefUnwindSafe for ReadResourceResult
impl Send for ReadResourceResult
impl Sync for ReadResourceResult
impl Unpin for ReadResourceResult
impl UnwindSafe for ReadResourceResult
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