pub enum ContentBlock {
Text {
text: String,
annotations: Option<Annotations>,
meta: Option<HashMap<String, Value>>,
},
Image {
data: String,
mime_type: String,
annotations: Option<Annotations>,
meta: Option<HashMap<String, Value>>,
},
Audio {
data: String,
mime_type: String,
annotations: Option<Annotations>,
meta: Option<HashMap<String, Value>>,
},
ResourceLink {
resource: ResourceReference,
annotations: Option<Annotations>,
meta: Option<HashMap<String, Value>>,
},
Resource {
resource: ResourceContents,
annotations: Option<Annotations>,
meta: Option<HashMap<String, Value>>,
},
ToolUse {
id: String,
name: String,
input: HashMap<String, Value>,
meta: Option<HashMap<String, Value>>,
},
ToolResult {
tool_use_id: String,
content: Vec<ContentBlock>,
structured_content: Option<Value>,
is_error: Option<bool>,
meta: Option<HashMap<String, Value>>,
},
}Expand description
Core MCP protocol types and error handling Content block union type matching MCP 2025-11-25 specification exactly
Variants§
Text
Text content
Image
Image content
Fields
annotations: Option<Annotations>Audio
Audio content
Fields
annotations: Option<Annotations>ResourceLink
Resource link (ResourceLink from MCP spec)
Resource
Embedded resource (EmbeddedResource from MCP spec)
ToolUse
Tool use content block (per MCP 2025-11-25 spec)
Fields
ToolResult
Tool result content block (per MCP 2025-11-25 spec)
Fields
content: Vec<ContentBlock>Content returned by the tool
Implementations§
Source§impl ContentBlock
impl ContentBlock
Sourcepub fn text(text: impl Into<String>) -> ContentBlock
pub fn text(text: impl Into<String>) -> ContentBlock
Create text content
Sourcepub fn text_with_annotations(
text: impl Into<String>,
annotations: Annotations,
) -> ContentBlock
pub fn text_with_annotations( text: impl Into<String>, annotations: Annotations, ) -> ContentBlock
Create text content with annotations
Sourcepub fn image(
data: impl Into<String>,
mime_type: impl Into<String>,
) -> ContentBlock
pub fn image( data: impl Into<String>, mime_type: impl Into<String>, ) -> ContentBlock
Create image content
Sourcepub fn audio(
data: impl Into<String>,
mime_type: impl Into<String>,
) -> ContentBlock
pub fn audio( data: impl Into<String>, mime_type: impl Into<String>, ) -> ContentBlock
Create audio content
Sourcepub fn resource_link(resource: ResourceReference) -> ContentBlock
pub fn resource_link(resource: ResourceReference) -> ContentBlock
Create resource link
Sourcepub fn resource(resource: ResourceContents) -> ContentBlock
pub fn resource(resource: ResourceContents) -> ContentBlock
Create embedded resource
Sourcepub fn tool_use(
id: impl Into<String>,
name: impl Into<String>,
input: HashMap<String, Value>,
) -> ContentBlock
pub fn tool_use( id: impl Into<String>, name: impl Into<String>, input: HashMap<String, Value>, ) -> ContentBlock
Create tool use content block
Sourcepub fn tool_result(
tool_use_id: impl Into<String>,
content: Vec<ContentBlock>,
) -> ContentBlock
pub fn tool_result( tool_use_id: impl Into<String>, content: Vec<ContentBlock>, ) -> ContentBlock
Create tool result content block
Sourcepub fn tool_result_error(
tool_use_id: impl Into<String>,
content: Vec<ContentBlock>,
) -> ContentBlock
pub fn tool_result_error( tool_use_id: impl Into<String>, content: Vec<ContentBlock>, ) -> ContentBlock
Create tool result error content block
Sourcepub fn with_annotations(self, annotations: Annotations) -> ContentBlock
pub fn with_annotations(self, annotations: Annotations) -> ContentBlock
Add annotations to any content block that supports them. ToolUse and ToolResult do not have annotations per spec — this is a no-op for those variants.
Trait Implementations§
Source§impl Clone for ContentBlock
impl Clone for ContentBlock
Source§fn clone(&self) -> ContentBlock
fn clone(&self) -> ContentBlock
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more