pub struct ReadResourceResult {
pub contents: Vec<ResourceContent>,
pub meta: Option<Value>,
}Fields§
§contents: Vec<ResourceContent>§meta: Option<Value>Optional protocol-level metadata
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_types::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_types::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_types::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_types::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_types::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_types::ReadResourceResult;
let result = ReadResourceResult::text("file://readme.md", "# Hello");
assert_eq!(result.first_text(), Some("# Hello"));Sourcepub fn first_uri(&self) -> Option<&str>
pub fn first_uri(&self) -> Option<&str>
Get the URI from the first content item.
Returns None if there are no contents.
§Example
use tower_mcp_types::ReadResourceResult;
let result = ReadResourceResult::text("file://readme.md", "# Hello");
assert_eq!(result.first_uri(), Some("file://readme.md"));Sourcepub fn as_json(&self) -> Option<Result<Value, Error>>
pub fn as_json(&self) -> Option<Result<Value, Error>>
Parse the first text content as a JSON Value.
Returns None if there are no contents or the first item has no text.
§Example
use tower_mcp_types::ReadResourceResult;
use serde_json::json;
let result = ReadResourceResult::json("data://config", &json!({"key": "value"}));
let value = result.as_json().unwrap().unwrap();
assert_eq!(value["key"], "value");Sourcepub fn deserialize<T: DeserializeOwned>(&self) -> Option<Result<T, Error>>
pub fn deserialize<T: DeserializeOwned>(&self) -> Option<Result<T, Error>>
Deserialize the first text content into a typed value.
Returns None if there are no contents or the first item has no text.
§Example
use tower_mcp_types::ReadResourceResult;
use serde::Deserialize;
use serde_json::json;
#[derive(Debug, Deserialize, PartialEq)]
struct Config { key: String }
let result = ReadResourceResult::json("data://config", &json!({"key": "value"}));
let config: Config = result.deserialize().unwrap().unwrap();
assert_eq!(config.key, "value");Trait Implementations§
Source§impl Clone for ReadResourceResult
impl Clone for ReadResourceResult
Source§fn clone(&self) -> ReadResourceResult
fn clone(&self) -> ReadResourceResult
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more