Class ImageContentBlock | MCP C# SDK

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()

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

ReadOnlyMemory<byte>

Remarks

DecodedData

Gets the decoded image data represented by Data.

[JsonIgnore]
public ReadOnlyMemory<byte> DecodedData { get; }

Property Value

ReadOnlyMemory<byte>

Remarks

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

string

Remarks

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

Methods

FromBytes(ReadOnlyMemory<byte>, string)

public static ImageContentBlock FromBytes(ReadOnlyMemory<byte> bytes, string mimeType)

Parameters

bytes ReadOnlyMemory<byte>

The unencoded image bytes.

mimeType string

The MIME type of the image.

Returns

ImageContentBlock

A new ImageContentBlock instance.

Remarks

Exceptions

ArgumentNullException

mimeType is null.

ArgumentException

mimeType is empty or composed entirely of whitespace.