pub enum Content {
Text {
text: String,
_meta: Option<Meta>,
},
Image {
data: String,
mime_type: String,
_meta: Option<Meta>,
},
Audio {
data: String,
mime_type: String,
_meta: Option<Meta>,
},
Resource {
resource: EmbeddedResourceContents,
_meta: Option<Meta>,
},
ToolUse {
id: String,
name: String,
input: Value,
_meta: Option<Meta>,
},
ToolResult {
tool_use_id: String,
content: Vec<ToolResultContent>,
is_error: Option<bool>,
_meta: Option<Meta>,
},
}Expand description
Content types for tool responses and sampling messages
Variants§
Text
Image
Audio
Audio content with base64-encoded data
Fields
Resource
ToolUse
Tool use request from LLM during sampling (MCP 2025-11-25)
Fields
ToolResult
Tool result to be passed back to LLM during sampling (MCP 2025-11-25)
Implementations§
Source§impl Content
impl Content
pub fn text(text: impl Into<String>) -> Self
pub fn image(data: impl Into<String>, mime_type: impl Into<String>) -> Self
Sourcepub fn audio(data: impl Into<String>, mime_type: impl Into<String>) -> Self
pub fn audio(data: impl Into<String>, mime_type: impl Into<String>) -> Self
Create audio content with base64-encoded data
Sourcepub fn resource(
uri: impl Into<String>,
mime_type: Option<String>,
text: Option<String>,
) -> Self
pub fn resource( uri: impl Into<String>, mime_type: Option<String>, text: Option<String>, ) -> Self
Create embedded resource content
Sourcepub fn from_resource_contents(contents: ResourceContents) -> Self
pub fn from_resource_contents(contents: ResourceContents) -> Self
Create embedded resource content from ResourceContents
Sourcepub fn tool_use(
id: impl Into<String>,
name: impl Into<String>,
input: Value,
) -> Self
pub fn tool_use( id: impl Into<String>, name: impl Into<String>, input: Value, ) -> Self
Create a tool use content (MCP 2025-11-25)
Used during sampling when the LLM wants to invoke a tool.
Sourcepub fn tool_result(
tool_use_id: impl Into<String>,
content: Vec<ToolResultContent>,
is_error: Option<bool>,
) -> Self
pub fn tool_result( tool_use_id: impl Into<String>, content: Vec<ToolResultContent>, is_error: Option<bool>, ) -> Self
Create a tool result content (MCP 2025-11-25)
Used during sampling to return tool execution results to the LLM.
Sourcepub fn tool_result_text(
tool_use_id: impl Into<String>,
text: impl Into<String>,
) -> Self
pub fn tool_result_text( tool_use_id: impl Into<String>, text: impl Into<String>, ) -> Self
Create a successful tool result with text content (MCP 2025-11-25)
Sourcepub fn tool_result_error(
tool_use_id: impl Into<String>,
error_message: impl Into<String>,
) -> Self
pub fn tool_result_error( tool_use_id: impl Into<String>, error_message: impl Into<String>, ) -> Self
Create an error tool result (MCP 2025-11-25)
Sourcepub fn ui_html(uri: impl Into<String>, html: impl Into<String>) -> Self
pub fn ui_html(uri: impl Into<String>, html: impl Into<String>) -> Self
Create a UI HTML resource content (for MCP Apps Extension / MCP-UI)
This helper simplifies creating HTML UI resources by automatically formatting the resource JSON according to the MCP-UI specification.
§Example
use pulseengine_mcp_protocol::Content;
let html = r#"<html><body><h1>Hello!</h1></body></html>"#;
let content = Content::ui_html("ui://greetings/interactive", html);This is equivalent to but much more concise than:
let resource_json = serde_json::json!({
"uri": "ui://greetings/interactive",
"mimeType": "text/html",
"text": html
});
Content::Resource {
resource: resource_json.to_string(),
text: None,
_meta: None,
}Create a UI HTML resource content (for MCP Apps Extension / MCP-UI)
Sourcepub fn ui_resource(
uri: impl Into<String>,
mime_type: impl Into<String>,
content: impl Into<String>,
) -> Self
pub fn ui_resource( uri: impl Into<String>, mime_type: impl Into<String>, content: impl Into<String>, ) -> Self
Create a UI resource content with custom MIME type (for MCP Apps Extension / MCP-UI)
This helper allows you to create UI resources with any MIME type and content.
§Example
use pulseengine_mcp_protocol::Content;
let json_data = r#"{"message": "Hello, World!"}"#;
let content = Content::ui_resource(
"ui://data/greeting",
"application/json",
json_data
);Source§impl Content
impl Content
Sourcepub fn as_text_content(&self) -> Option<TextContent>
pub fn as_text_content(&self) -> Option<TextContent>
Get text content as TextContent struct for compatibility
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Content
impl<'de> Deserialize<'de> for Content
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>,
Auto Trait Implementations§
impl Freeze for Content
impl RefUnwindSafe for Content
impl Send for Content
impl Sync for Content
impl Unpin for Content
impl UnwindSafe for Content
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)