OzMcp.Structs.SamplingMessage (OzMcp v0.9.0)

Copy Markdown View Source

Helper module used to build SamplingMessage structure: a message of the conversation the server asks the client to complete.

(MCP protocol: 2025-11-25)

content is one block or a list of blocks. A block is a TextContent, ImageContent, AudioContent, ToolUseContent or ToolResultContent struct, or a map that is already a block.

Short example:

%SamplingMessage{}
  |> SamplingMessage.role(:user)
  |> SamplingMessage.content(%TextContent{} |> TextContent.text("Hello"))
  |> SamplingMessage.build()

Result:

%{role: "user", content: %{type: "text", text: "Hello"}}

user/1 and assistant/1 build a message from a text:

SamplingMessage.user("Hello") |> SamplingMessage.build()

Specification: SamplingMessage

Fields

FieldSetterTypeRequired
rolerole/2role() | String.t()no
contentcontent/2block() | list(block()) | nilno
_meta_meta/2mapno

Summary

Functions

An assistant message with a text content.

A user message with a text content.

Types

block()

@type block() ::
  %OzMcp.Structs.TextContent{_meta: term(), annotations: term(), text: term()}
  | %OzMcp.Structs.ImageContent{
      _meta: term(),
      annotations: term(),
      data: term(),
      mimeType: term()
    }
  | %OzMcp.Structs.AudioContent{
      _meta: term(),
      annotations: term(),
      data: term(),
      mimeType: term()
    }
  | %OzMcp.Structs.ToolUseContent{
      _meta: term(),
      id: term(),
      input: term(),
      name: term()
    }
  | %OzMcp.Structs.ToolResultContent{
      _meta: term(),
      content: term(),
      isError: term(),
      structuredContent: term(),
      toolUseId: term()
    }
  | map()

role()

@type role() :: :user | :assistant

t()

@type t() :: %OzMcp.Structs.SamplingMessage{
  _meta: map() | nil,
  content: block() | [block()] | nil,
  role: role() | String.t()
}

Functions

assistant(text)

@spec assistant(String.t()) :: %OzMcp.Structs.SamplingMessage{
  _meta: term(),
  content: term(),
  role: term()
}

An assistant message with a text content.

build(struct)

@spec build(t()) :: map()

content(struct, value)

@spec content(t(), block() | [block()] | nil) :: t()

role(struct, value)

@spec role(t(), role() | String.t()) :: t()

user(text)

@spec user(String.t()) :: %OzMcp.Structs.SamplingMessage{
  _meta: term(),
  content: term(),
  role: term()
}

A user message with a text content.