Table of Contents

Class SamplingMessage

Namespace
ModelContextProtocol.Protocol
Assembly
ModelContextProtocol.Core.dll

Represents a message issued to or received from an LLM API within the Model Context Protocol.

public sealed class SamplingMessage
Inheritance
SamplingMessage
Inherited Members

Remarks

A SamplingMessage encapsulates content sent to or received from AI models in the Model Context Protocol. The message has a role (User or Assistant) and content which can be text, images, audio, tool uses, or tool results.

SamplingMessage objects are typically used in collections within CreateMessageRequestParams to represent prompts or queries for LLM sampling. They form the core data structure for text generation requests within the Model Context Protocol.

If content contains any ToolResultContentBlock, then all content items must be ToolResultContentBlock. Tool results cannot be mixed with text, image, or audio content in the same message.

See the schema for details.

Properties

Content

Gets or sets the content of the message.

[JsonPropertyName("content")]
[JsonConverter(typeof(SingleItemOrListConverter<ContentBlock>))]
public required IList<ContentBlock> Content { get; set; }

Property Value

IList<ContentBlock>

Meta

Gets or sets metadata reserved by MCP for protocol-level metadata.

[JsonPropertyName("_meta")]
public JsonObject? Meta { get; set; }

Property Value

JsonObject

Remarks

Implementations must not make assumptions about its contents.

Role

Gets or sets the role of the message sender.

[JsonPropertyName("role")]
public Role Role { get; set; }

Property Value

Role