pub enum ContentBlock {
TextContent(TextContent),
ImageContent(ImageContent),
AudioContent(AudioContent),
ResourceLink(ResourceLink),
EmbeddedResource(EmbeddedResource),
}Expand description
Latest MCP Protocol 2025_11_25 ContentBlock
JSON schema
{
"anyOf": [
{
"$ref": "#/$defs/TextContent"
},
{
"$ref": "#/$defs/ImageContent"
},
{
"$ref": "#/$defs/AudioContent"
},
{
"$ref": "#/$defs/ResourceLink"
},
{
"$ref": "#/$defs/EmbeddedResource"
}
]
}Variants§
TextContent(TextContent)
ImageContent(ImageContent)
AudioContent(AudioContent)
ResourceLink(ResourceLink)
EmbeddedResource(EmbeddedResource)
Implementations§
Source§impl ContentBlock
impl ContentBlock
Sourcepub fn text_content(text: String) -> Self
pub fn text_content(text: String) -> Self
Create a ContentBlock::TextContent
Sourcepub fn image_content(data: String, mime_type: String) -> Self
pub fn image_content(data: String, mime_type: String) -> Self
Create a ContentBlock::ImageContent
Sourcepub fn audio_content(data: String, mime_type: String) -> Self
pub fn audio_content(data: String, mime_type: String) -> Self
Create a ContentBlock::AudioContent
Sourcepub fn resource_link(value: ResourceLink) -> Self
pub fn resource_link(value: ResourceLink) -> Self
Create a ContentBlock::ResourceLink
Sourcepub fn embedded_resource(resource: EmbeddedResourceResource) -> Self
pub fn embedded_resource(resource: EmbeddedResourceResource) -> Self
Create a ContentBlock::EmbeddedResource
Sourcepub fn content_type(&self) -> &str
pub fn content_type(&self) -> &str
Returns the content type as a string based on the variant of ContentBlock
Sourcepub fn as_text_content(&self) -> Result<&TextContent, RpcError>
pub fn as_text_content(&self) -> Result<&TextContent, RpcError>
Converts the content to a reference to TextContent, returning an error if the conversion is invalid.
Sourcepub fn as_image_content(&self) -> Result<&ImageContent, RpcError>
pub fn as_image_content(&self) -> Result<&ImageContent, RpcError>
Converts the content to a reference to TextContent, returning an error if the conversion is invalid.
Sourcepub fn as_audio_content(&self) -> Result<&AudioContent, RpcError>
pub fn as_audio_content(&self) -> Result<&AudioContent, RpcError>
Converts the content to a reference to TextContent, returning an error if the conversion is invalid.
Sourcepub fn as_resource_link(&self) -> Result<&ResourceLink, RpcError>
pub fn as_resource_link(&self) -> Result<&ResourceLink, RpcError>
Converts the content to a reference to TextContent, returning an error if the conversion is invalid.
Sourcepub fn as_embedded_resource(&self) -> Result<&EmbeddedResource, RpcError>
pub fn as_embedded_resource(&self) -> Result<&EmbeddedResource, RpcError>
Converts the content to a reference to TextContent, returning an error if the conversion is invalid.
Sourcepub fn embedded_text_resource<U, M, T>(uri: U, mime_type: M, text: T) -> Self
pub fn embedded_text_resource<U, M, T>(uri: U, mime_type: M, text: T) -> Self
Build a ContentBlock::EmbeddedResource carrying a text payload
(e.g. JSON, plain text, source code).
Shortcut for:
EmbeddedResource::new(
EmbeddedResourceResource::TextResourceContents(
TextResourceContents::new(text, uri).with_mime_type(mime_type),
),
None, None,
).into()Sourcepub fn embedded_blob_resource<U, M, D>(
uri: U,
mime_type: M,
base64_data: D,
) -> Self
pub fn embedded_blob_resource<U, M, D>( uri: U, mime_type: M, base64_data: D, ) -> Self
Build a ContentBlock::EmbeddedResource carrying a base64-encoded
binary payload (images, audio, arbitrary file blobs).
base64_data must already be base64-encoded.
Trait Implementations§
Source§impl Clone for ContentBlock
impl Clone for ContentBlock
Source§fn clone(&self) -> ContentBlock
fn clone(&self) -> ContentBlock
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more