Reading A2UI out of Model Context Protocol values: the A2UI messages a tool result or a resource carries, the UI resources a tool or a result names, and the MCP Apps a resource holds.
A2UI travels in MCP as JSON text with the MIME type
application/a2ui+json, either embedded in a tool result's content or
in a resource; a tool or a result names its UI resources in
_meta.ui.resourceUri (one URI or a list). An
MCP App is HTML
with the MIME type text/html;profile=mcp-app, and its resource's
_meta.ui may carry csp and permissions for the sandbox that runs
it.
Summary
Functions
The MIME type of MCP App HTML: text/html;profile=mcp-app.
The MCP App in a resources/read result, or nil: the HTML of its
first content with the MCP App MIME type (text, or base64 blob),
with the csp and permissions of that content's _meta.ui.
The MIME type of A2UI content: application/a2ui+json.
The A2UI messages of a resources/read result: the JSON of every
content with the A2UI MIME type, in order.
The A2UI messages embedded in a tool result's content: the JSON of
every resource block with the A2UI MIME type, in order. A block whose
text is not JSON is an error.
The UI resource URIs a tool descriptor or a tool result names in
_meta.ui.resourceUri, without duplicates.
Functions
@spec app_mime_type() :: String.t()
The MIME type of MCP App HTML: text/html;profile=mcp-app.
The MCP App in a resources/read result, or nil: the HTML of its
first content with the MCP App MIME type (text, or base64 blob),
with the csp and permissions of that content's _meta.ui.
iex> A2UICore.MCP.app_resource(%{"contents" => [
...> %{"uri" => "ui://game", "mimeType" => "text/html;profile=mcp-app", "text" => "<p>Hi</p>"}
...> ]})
%{"htmlContent" => "<p>Hi</p>"}
@spec mime_type() :: String.t()
The MIME type of A2UI content: application/a2ui+json.
@spec resource_messages(map(), String.t()) :: {:ok, [map()]} | {:error, A2UICore.Error.t()}
The A2UI messages of a resources/read result: the JSON of every
content with the A2UI MIME type, in order.
@spec tool_result_messages(map()) :: {:ok, [map()]} | {:error, A2UICore.Error.t()}
The A2UI messages embedded in a tool result's content: the JSON of
every resource block with the A2UI MIME type, in order. A block whose
text is not JSON is an error.
The UI resource URIs a tool descriptor or a tool result names in
_meta.ui.resourceUri, without duplicates.
iex> A2UICore.MCP.ui_resource_uris(%{"_meta" => %{"ui" => %{"resourceUri" => "ui://card"}}})
["ui://card"]
iex> A2UICore.MCP.ui_resource_uris(%{"content" => []})
[]