Content

A content block as used in tool results, prompt messages, and sampling.

Modeled as a tagged union over the per-kind content structs above (TextContent, ImageContent, AudioContent, ResourceLink, EmbeddedResource, ToolUseContent, ToolResultContent). Each kind stores only the fields that are meaningful for it, so there are no meaningless-per-kind fields. Construct via the make* factories; the chainable with* setters apply only on the kinds where the field is valid.

Members

Aliases

Payload
alias Payload = SumType!(TextContent, ImageContent, AudioContent, ResourceLink, EmbeddedResource, ToolUseContent, ToolResultContent, UnknownContent)

The underlying tagged union. Public so callers that prefer std.sumtype.match can pattern-match directly over the per-kind structs.

Functions

annotations
Json annotations()

The shared annotations value (any kind may carry it).

dupSelf
Content dupSelf()

A deep copy of this content block.

embeddedResource
ResourceContents embeddedResource()

Decode an embedded resource content block's resource payload into a typed ResourceContents. For the embeddedResource kind this is ResourceContents.fromJson of the raw resource() object (giving typed uri/mimeType/text/blob access instead of the untyped Json); for any other kind it returns a default ResourceContents.

forVersion
Content forVersion(ProtocolVersion v)

Return a copy of this content block projected for the negotiated protocol version so the wire output stays in-schema for the peer. Two things are projected:

kind
ContentKind kind()

Which content kind this block holds.

meta
Json meta()

The shared _meta value (any kind may carry it).

withAnnotations
Content withAnnotations(Json a)

Attach optional annotations (audience/priority/lastModified) to this content block. Returns a copy so calls can be chained, e.g. Content.makeText("hi").withAnnotations(a). Valid on every kind.

withContentMeta
Content withContentMeta(Json m)

Attach an optional _meta object to this content block. Per the MCP schema every content kind may carry _meta. Returns a copy.

withDescription
Content withDescription(string d)

Attach an optional description to a resource_link content block, per the MCP ResourceLink shape (it extends Resource). Returns a copy so calls can be chained. Only valid for the resourceLink kind.

withIsError
Content withIsError(bool e)

Mark a tool_result content block as an error (sampling). Returns a copy. Only valid for the toolResult kind.

withSize
Content withSize(long s)

Attach an optional size (bytes) to a resource_link content block, per the MCP ResourceLink shape. Returns a copy. Only valid for the resourceLink kind.

withStructuredContent
Content withStructuredContent(Json sc)

Attach an optional structuredContent object to a tool_result content block (sampling). Returns a copy. Only valid for the toolResult kind.

withTitle
Content withTitle(string t)

Attach an optional human-readable title to a resource_link content block (ResourceLink extends Resource/BaseMetadata). Returns a copy. Only valid for the resourceLink kind.

Static functions

makeToolResult
Content makeToolResult(string toolUseId, Content[] content)

A tool_result content block (sampling): the result of a tool call, answering the tool_use whose id is toolUseId. content is the nested result content blocks. Per ToolResultContent in the 2025-11-25 / draft schema.

makeToolUse
Content makeToolUse(string id, string name, Json input)

A tool_use content block (sampling): the model's request to call a tool. id is the model-assigned call id, name the tool name, and input the arguments object. Per ToolUseContent in the 2025-11-25 / draft schema.