# `A2UICore.MCP`
[🔗](https://github.com/a2ui-elixir/a2ui/blob/v0.1.1/umbrella/apps/a2ui_core/lib/a2ui_core/mcp.ex#L1)

Reading A2UI out of [Model Context Protocol](https://modelcontextprotocol.io)
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](https://github.com/modelcontextprotocol/ext-apps) 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.

# `app_mime_type`
*since 0.1.0* 

```elixir
@spec app_mime_type() :: String.t()
```

The MIME type of MCP App HTML: `text/html;profile=mcp-app`.

# `app_resource`
*since 0.1.0* 

```elixir
@spec app_resource(map()) :: map() | nil
```

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>"}

# `mime_type`
*since 0.1.0* 

```elixir
@spec mime_type() :: String.t()
```

The MIME type of A2UI content: `application/a2ui+json`.

# `resource_messages`
*since 0.1.0* 

```elixir
@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.

# `tool_result_messages`
*since 0.1.0* 

```elixir
@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.

# `ui_resource_uris`
*since 0.1.0* 

```elixir
@spec ui_resource_uris(map() | nil) :: [String.t()]
```

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" => []})
    []

---

*Consult [api-reference.md](api-reference.md) for complete listing*
