Skip to contents

An MCP App is a web page that the client shows to the user in the conversation, with the result of a tool: for runlog, a chart of the totals of a year next to the table that summarise_runs returns. The server serves the page; the client shows it, gives it the result of the tool, and lets it call the tools of the server. The model never sees the page: it reads the result of the tool, as for any tool, and a client that does not show pages gets only that result. mordew follows the io.modelcontextprotocol/ui extension, in its stable revision 2026-01-26: its specification says what a page sends and receives.

The page

The page is a resource with a ui:// URI that returns HTML, with @mcpReturns html:

#' Year chart
#'
#' A chart of the totals of a year.
#'
#' @mcpResource ui://runlog/year-chart
#' @mcpReturns html
year_chart <- function() {
  readLines(
    system.file(
      "app",
      "year-chart.html",
      package = "runlog"
    )
  )
}

The page is a file to write, inst/app/year-chart.html here: the runlog example that mordew ships has none. The function returns a character vector, sent as one text/html;profile=mcp-app text, one element per line. The roclet stops on a ui:// URI without @mcpReturns html, or the reverse. The page is the same at every call of the tool: the data comes from the result of the tool, which the client passes to the page. The page receives it, and talks to the client, with the protocol of the extension, in JavaScript: mordew serves the HTML as it is.

What the page may do

The client shows the page in a sandbox that, by default, loads nothing from outside: no script, image, font or call to another server. Tags of the page loosen it, and set how the client shows it:

Tag _meta.ui field What it gives the page
@mcpCsp connect <domain>... csp.connectDomains Servers the page may call, such as an API
@mcpCsp resource <domain>... csp.resourceDomains Where the page may load scripts, images, styles and fonts from
@mcpCsp frame <domain>... csp.frameDomains Pages the page may embed in a frame
@mcpCsp baseUri <domain>... csp.baseUriDomains Base URIs the page may set
@mcpPermission <permission>... permissions camera, microphone, geolocation and clipboardWrite, which the client may grant
@mcpDomain <domain> domain A dedicated origin for the page, in the format each client documents
@mcpBorder <true\|false> prefersBorder Whether the client draws a border around the page; without the tag, the client decides

@mcpCsp takes one kind then one domain or more, and repeats for more kinds or more domains:

#' @mcpResource ui://runlog/year-chart
#' @mcpReturns html
#' @mcpCsp resource https://cdn.jsdelivr.net
#' @mcpPermission geolocation
#' @mcpDomain runlog-year-chart.example.com
#' @mcpBorder false

The server sends _meta.ui with the page, in resources/list and in the content of resources/read. The roclet stops on a domain that is not an origin, such as * alone, on an unknown kind, permission or border, and on these tags for a resource that is not a page. A page that embeds its scripts and styles needs no @mcpCsp.

The tool

A tool names its page with @mcpApp:

#' @mcpTool
#' @mcpApp ui://runlog/year-chart

tools/list sends the URI in _meta.ui.resourceUri of the definition of the tool, and the client reads the page from it. The roclet, or mcp_server() for a server written in a script, stops on a URI that does not start with ui://, and on a page that is not a resource of the server.

Who may call a tool

@mcpVisibility says who may call a tool: model, app, the page of an MCP App, or model app, both, the default without the tag. A tool for the page only, such as one that the page calls when the user picks another year, is not one the model needs:

#' @mcpTool
#' @mcpVisibility app

tools/list sends it in _meta.ui.visibility, and the client applies it: it does not show the model a tool without model, and refuses a call of the page to a tool without app.

A client that does not know MCP Apps cannot apply it, so the server checks what the client declared: the io.modelcontextprotocol/ui extension, whose mimeTypes hold text/html;profile=mcp-app, in the capabilities of initialize or, for 2026-07-28, in the clientCapabilities of each request. A client without it gets no tool without model in tools/list; one that calls such a tool by its name still gets its result. Since the list then depends on the client, a 2026-07-28 tools/list of a server with such a tool carries cacheScope: "private".

Widgets

@mcpWidget plot_totals names a function of the package that takes the value of the tool and returns an htmlwidget, such as a plotly chart or a leaflet map, drawn from that value; the tool needs @mcpApp. The model still gets the value of the tool, converted as @mcpReturns says, and the result carries the widget in _meta["mordew/widget"], which the client passes to the page and the specification keeps out of the context of the model. A client that did not declare the extension gets the value alone:

#' @mcpTool
#' @mcpReturns table
#' @mcpApp ui://runlog/year-chart
#' @mcpWidget plot_totals

_meta["mordew/widget"] holds the HTML of the widget in html, and its dependencies in dependencies, each with its name, its version, its scripts and its styles as text: the files that the styles use, such as images and fonts, become data: URIs, so that the page loads nothing from outside. A plotly chart carries about 3.7 MB of scripts, a leaflet map about 450 KB. A dependency that names a URL in place of local files is refused, since nothing of it could be sent. A widget function that fails gives an isError result.

widget_page() gives the page that draws it, the same for every widget:

#' Year chart
#'
#' A chart of the totals of a year.
#'
#' @mcpResource ui://runlog/year-chart
#' @mcpReturns html
year_chart <- function() {
  mordew::widget_page()
}

The page sends ui/initialize to the client, then ui/notifications/initialized once the client answers. When ui/notifications/tool-result brings the result of the tool, it adds the styles and scripts of each dependency, once per name, puts the HTML of the widget in the page and draws it with htmlwidgets. It sends its size with ui/notifications/size-changed whenever it changes, answers ping and ui/resource-teardown, and answers any other request with the error -32601. Its scripts are inline, which the default sandbox of the specification allows. What a widget loads from outside, such as the tiles of a leaflet map, needs its domains in @mcpCsp resource.

A widget that finds its files from the address of a file in its styles breaks, since that address becomes a data: URI: leaflet does this for the icon of its default markers, which show as a broken image.