Table of Contents

Class AudioContentBlock

Namespace
ModelContextProtocol.Protocol
Assembly
ModelContextProtocol.Core.dll

Represents audio provided to or from an LLM.

public sealed class AudioContentBlock : ContentBlock
Inheritance
AudioContentBlock
Inherited Members
Extension Methods

Constructors

AudioContentBlock()

Initializes a new instance of the AudioContentBlock class.

public AudioContentBlock()

Properties

Data

Gets or sets the base64-encoded UTF-8 bytes representing the audio data.

[JsonPropertyName("data")]
public required ReadOnlyMemory<byte> Data { get; set; }

Property Value

ReadOnlyMemory<byte>

Remarks

Setting this value will invalidate any cached value of DecodedData.

DecodedData

Gets the decoded audio data represented by Data.

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

Property Value

ReadOnlyMemory<byte>

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

string

Remarks

Common values include "audio/wav" and "audio/mp3".

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 AudioContentBlock from decoded audio bytes.

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

Parameters

bytes ReadOnlyMemory<byte>

The unencoded audio bytes.

mimeType string

The MIME type of the audio.

Returns

AudioContentBlock

A new AudioContentBlock instance.

Remarks

This method stores the provided bytes as DecodedData and lazily encodes them to base64 UTF-8 bytes for Data.

Exceptions

ArgumentNullException

mimeType is null.

ArgumentException

mimeType is empty or composed entirely of whitespace.