SamplingMessage

data class SamplingMessage(val role: Role, val content: List<SamplingMessageContent>, val meta: JsonObject? = null)(source)

Describes a message issued to or received from an LLM API.

Used in sampling requests to provide conversation context and history to the LLM.

Under SEP-1577, content is a list of SamplingMessageContent blocks rather than a single block. On the wire, a list of size 1 is serialised as a single object (wire-compatible with pre-SEP single-block content); a list of size 2+ is serialised as a JSON array.

Constructors

Link copied to clipboard
constructor(role: Role, content: List<SamplingMessageContent>, meta: JsonObject? = null)
constructor(role: Role, content: SamplingMessageContent, meta: JsonObject? = null)

Convenience constructor for a single-block message. Wraps content in a singleton list so call sites can write SamplingMessage(Role.User, TextContent("hi")) without the explicit listOf(...).

Properties

Link copied to clipboard

The content blocks of the message; MUST contain at least one block.

Link copied to clipboard
@SerialName(value = "_meta")
val meta: JsonObject?

Optional metadata reserved by MCP for clients and servers.

Link copied to clipboard
val role: Role

The role of the message sender (user, assistant, or system).