Class ImageContentBlock
- Namespace
- ModelContextProtocol.Protocol
- Assembly
- ModelContextProtocol.Core.dll
Represents an image provided to or from an LLM.
public sealed class ImageContentBlock : ContentBlock
- Inheritance
-
ImageContentBlock
- Inherited Members
- Extension Methods
Constructors
ImageContentBlock()
Initializes a new instance of the ImageContentBlock class.
public ImageContentBlock()
Properties
Data
Gets or sets the base64-encoded UTF-8 bytes representing the image data.
[JsonPropertyName("data")]
public required ReadOnlyMemory<byte> Data { get; set; }
Property Value
Remarks
Setting this value will invalidate any cached value of DecodedData.
DecodedData
Gets the decoded image data represented by Data.
[JsonIgnore]
public ReadOnlyMemory<byte> DecodedData { get; }
Property Value
Remarks
When getting, this member will decode the value in Data and cache the result. Subsequent accesses return the cached value unless Data is modified.
MimeType
Gets or sets the MIME type (or "media type") of the content, specifying the format of the data.
[JsonPropertyName("mimeType")]
public required string MimeType { get; set; }
Property Value
Remarks
Common values include "image/png" and "image/jpeg".
Type
When overridden in a derived class, gets the type of content.
public override string Type { get; }
Property Value
- string
The type of content. Valid values include "image", "audio", "text", "resource", "resource_link", "tool_use", and "tool_result".
Remarks
This value determines the structure of the content object.
Methods
FromBytes(ReadOnlyMemory<byte>, string)
Creates an ImageContentBlock from decoded image bytes.
public static ImageContentBlock FromBytes(ReadOnlyMemory<byte> bytes, string mimeType)
Parameters
bytesReadOnlyMemory<byte>The unencoded image bytes.
mimeTypestringThe MIME type of the image.
Returns
- ImageContentBlock
A new ImageContentBlock instance.
Remarks
This method stores the provided bytes as DecodedData and lazily encodes them to base64 UTF-8 bytes for Data.
Exceptions
- ArgumentNullException
mimeTypeis null.- ArgumentException
mimeTypeis empty or composed entirely of whitespace.