relay/content

MCP content values: text, image, audio, resource-link and embedded-resource blocks, resource contents, annotations and icons.

These records mirror the frozen 2026-07-28 schema and include every optional field it defines, _meta included, so they change only with a protocol revision. Tools (relay/tool), prompts (relay/prompts) and resources (relay/resources) return them, and relay/client decodes results into them. Build blocks with text, image, audio, resource_link and embedded; read them by label or with case.

Binary data stays bytes: image, audio and blob_resource take a BitArray, and Relay encodes base64 only on the wire.

import gleam/option.{Some}
import relay/content

pub fn reply() -> List(content.ContentBlock) {
  let note =
    content.text("Report ready")
    |> content.with_annotations(content.Annotations(
      ..content.empty_annotations(),
      priority: Some(0.8),
    ))
  [note, content.image(<<137, 80, 78, 71>>, "image/png")]
}

Types

Hints about how a client should use a piece of content. An empty audience and None fields are omitted on the wire. priority ranges from 0.0 (least important) to 1.0 (most important); last_modified is an ISO 8601 timestamp.

pub type Annotations {
  Annotations(
    audience: List(Role),
    priority: option.Option(Float),
    last_modified: option.Option(String),
  )
}

Constructors

One block of content in a tool result or a prompt message.

pub type ContentBlock {
  TextContent(
    text: String,
    annotations: option.Option(Annotations),
    meta: List(#(String, value.Value)),
  )
  ImageContent(
    data: BitArray,
    mime_type: String,
    annotations: option.Option(Annotations),
    meta: List(#(String, value.Value)),
  )
  AudioContent(
    data: BitArray,
    mime_type: String,
    annotations: option.Option(Annotations),
    meta: List(#(String, value.Value)),
  )
  ResourceLinkBlock(link: ResourceLink)
  EmbeddedResourceBlock(
    resource: ResourceContents,
    annotations: option.Option(Annotations),
    meta: List(#(String, value.Value)),
  )
}

Constructors

An icon a client may show for a tool, resource or prompt. An empty sizes list is omitted on the wire.

pub type Icon {
  Icon(
    src: String,
    mime_type: option.Option(String),
    sizes: List(String),
    theme: option.Option(IconTheme),
  )
}

Constructors

The theme an icon is designed for.

pub type IconTheme {
  LightTheme
  DarkTheme
}

Constructors

  • LightTheme
  • DarkTheme

The _meta object of a protocol value: its members. An empty list omits _meta on the wire; a decoded value may list members in another order.

pub type Meta =
  List(#(String, value.Value))

The contents of one resource: text, or binary data as bytes.

pub type ResourceContents {
  TextResourceContents(
    uri: String,
    text: String,
    mime_type: option.Option(String),
    meta: List(#(String, value.Value)),
  )
  BlobResourceContents(
    uri: String,
    blob: BitArray,
    mime_type: option.Option(String),
    meta: List(#(String, value.Value)),
  )
}

Constructors

  • TextResourceContents(
      uri: String,
      text: String,
      mime_type: option.Option(String),
      meta: List(#(String, value.Value)),
    )
  • BlobResourceContents(
      uri: String,
      blob: BitArray,
      mime_type: option.Option(String),
      meta: List(#(String, value.Value)),
    )

A link to a resource that a client may read, carried in a ResourceLinkBlock.

pub type ResourceLink {
  ResourceLink(
    uri: String,
    name: String,
    title: option.Option(String),
    description: option.Option(String),
    mime_type: option.Option(String),
    size: option.Option(Int),
    annotations: option.Option(Annotations),
    icons: List(Icon),
    meta: List(#(String, value.Value)),
  )
}

Constructors

Who a piece of content is meant for.

pub type Role {
  UserRole
  AssistantRole
}

Constructors

  • UserRole
  • AssistantRole

Values

pub fn audio(data: BitArray, mime_type: String) -> ContentBlock

An audio block from raw audio bytes.

pub fn blob_resource(
  uri: String,
  blob: BitArray,
) -> ResourceContents

Binary resource contents without a MIME type. Relay encodes the bytes as base64 on the wire.

pub fn embedded(resource: ResourceContents) -> ContentBlock

A block that embeds the contents of a resource.

pub fn empty_annotations() -> Annotations

Annotations with no hints set.

pub fn icon(src: String) -> Icon

An icon with only its source URI.

pub fn image(data: BitArray, mime_type: String) -> ContentBlock

An image block from raw image bytes, such as a PNG file’s contents.

pub fn resource_link(uri: String, name: String) -> ContentBlock

A resource-link block with only its URI and name.

pub fn text(text: String) -> ContentBlock

A text block.

pub fn text_of(blocks: List(ContentBlock)) -> String

Join only the text blocks, in wire order, with newlines. Other content remains available on the original result; this is a text projection.

pub fn text_resource(
  uri: String,
  text: String,
) -> ResourceContents

Text resource contents without a MIME type.

pub fn with_annotations(
  block: ContentBlock,
  annotations: Annotations,
) -> ContentBlock

Replaces a block’s annotations.

pub fn with_meta(
  block: ContentBlock,
  meta: List(#(String, value.Value)),
) -> ContentBlock

Replaces a block’s _meta members.

✨ Search Document