English

Developer guide Internals New

Rich chat UI

How the chat renders Markdown, A2UI surfaces and MCP Apps, and how cards talk back to the Architect.

On this page

Most chat messages are text. Some answers are easier to use as a small interface: a choice to make, a form to confirm, a dashboard to read. Archipelego supports two open standards for this, so rich UI can come from the Architect or from MCP servers without custom code per card.

Markdown

Every chat message, from a person or from the Architect, goes through app/src/chat/markdown.tsx. It renders Markdown to React elements, never to an HTML string, so a message cannot inject markup.

Kind Supported
Blocks Paragraphs, headings # to #### (drawn as h3 to h6), bullet and numbered lists with indented continuation lines, block quotes, fenced code, tables with a separator row, horizontal rules.
Inline **bold** and __bold__, *italic* and _italic_, `code`, ~~strike~~, [links](https://...).

Links must be http or https. They open in a new tab with rel="noopener noreferrer". Plain text runs go through an inline callback, which the chat uses to turn [[block-id]] tokens into RefChips and @names into mentions.

Two standards

Standard What arrives in the chat Who renders it
A2UI v1.0 A declarative description of a surface: which components, with which data. The app, with its own components from the design system.
MCP Apps A ui:// resource offered by an MCP server: an HTML app. The app runs it in a sandboxed iframe and talks to it over postMessage.

Rich UI in a message

A chat message (ChatMsg in app/src/chat/model.ts) can carry rich UI in these fields:

Field Meaning
a2ui A2UI messages, such as the feature draft card.
a2uiModel The live data model of the surface. Every edit writes it to the shared document, so the room sees the same values.
a2uiDone A status line under the card, such as "Saved by Ana: 9 blocks, 2 scenarios". When it is set, the card's controls lock.
richTitle The card title. The default is "Card".
feature The cleaned feature draft behind a draft card.
app An MCP App: server, tool, ui:// resource, tool input, tool result and saved widget state.

The Architect writes rich UI as fenced blocks in its Markdown answer:

  • A block marked a2ui holds a JSON array of A2UI messages, or one message per line.
  • A block marked mcp-app holds {"server": "archipelego", "tool": "canvas_overview"}, with optional arguments.

splitRich removes both kinds of block from the prose. The chat renders the first A2UI surface under the answer. For an mcp-app block, the client waits for the answer to finish, looks the tool up in GET /api/mcp/apps, calls it, and stores the result as app on the message. Only tools that the apps list offers can open this way.

A2UI surfaces

app/src/rich/a2ui.tsx is an A2UI v1.0 renderer drawn with the design system, so a card looks like the rest of the app in both themes.

  • parseA2UI accepts an array of messages, a JSON array string, or NDJSON.
  • buildSurfaces applies createSurface, updateComponents, updateDataModel and deleteSurface in order. It keeps a flat component list per surface. Messages with version 1.x or the v0.9 forms are read; others are skipped.
  • Values bind to the surface's data model with {"@path": "/pointer"}, a JSON Pointer. Inside a template list, relative paths resolve against the current item.
  • A cycle in the component tree is drawn once. An unknown component shows "name is not in this catalog". Nothing in a surface runs as code.

A2UI_CAPABILITIES declares the one supported catalog, the basic catalog at https://a2ui.org/specification/v1_0/catalogs/basic/catalog.json.

Group Components
Display Text (with caption, and bold, italic and code inline), Image, Icon, Video, AudioPlayer, Divider
Layout Row, Column, List, Card, Tabs, Modal
Input Button, TextField, CheckBox, ChoicePicker, Slider, DateTimeInput

The renderer evaluates these basic-catalog functions: formatString, formatNumber, formatCurrency, pluralize, not, and, or, @index and required. A button with the openUrl function call opens an http or https address in a new tab. Media URLs must be http, https, data: or relative.

Card actions

A button with an action.event sends an A2UIAction:

ts
interface A2UIAction {
  version: '1.0';
  action: { name: string; surfaceId: string; sourceComponentId: string; timestamp: string; context: Record<string, unknown>; userMessage?: string };
}

The context is resolved against the data model at the moment of the press.

  1. onRichAction in app/src/App.tsx handles the actions the app understands: save_feature and preview_feature on a feature draft card. See Feature drafts.
  2. Any other action goes back to the Architect. The chat posts the button's userMessage, or the action name, as a message from the person. It sets a2uiDone to "name chose: label".
  3. The client asks the Architect again with the question "The person pressed a control in your last card. The A2UI action message is: {...}. Continue from there."

MCP Apps

An MCP App is an HTML application that an MCP server publishes as a ui:// resource, linked from a tool's _meta.ui.resourceUri. Archipelego also reads the ChatGPT Apps SDK key openai/outputTemplate.

The server side

server/src/mcp.ts is the MCP client and host backend.

  • The built-in server archipelego answers in process. Its one tool is canvas_overview.
  • Remote servers come only from ARCHIPELEGO_MCP_SERVERS, as name=url pairs. See Configuration.
  • The server speaks Streamable HTTP with protocol version 2025-06-18. It sends initialize with the io.modelcontextprotocol/ui extension and the text/html;profile=mcp-app MIME type, then notifications/initialized. It keeps the mcp-session-id header.
  • It reads both JSON answers and server-sent event answers. Each request times out after 20 seconds.
Route What it does
GET /api/mcp/apps The tools with a ui:// resource, across servers: server, serverName, tool, title, description, uri, inputSchema. A server that fails offers no apps.
POST /api/mcp/call { server, tool, arguments, canvasId }. For the built-in server, canvasId fills the tool's canvasId argument. Answers the CallToolResult.
GET /api/mcp/resource?server=&uri= Reads a ui:// resource with resources/read. Answers { html, mimeType, meta }. Any other scheme answers 400.

The host in the browser

app/src/rich/mcpApp.tsx renders McpAppFrame.

  • The resource HTML becomes the srcdoc of an iframe with sandbox="allow-scripts allow-forms" and referrerPolicy="no-referrer". Without allow-same-origin, the frame has an opaque origin: no cookies, no storage, no access to the Archipelego page.
  • The host puts a Content Security Policy <meta> first in the document head, built from the resource's _meta.ui.csp:
Directive Value
default-src 'none'
script-src, style-src 'unsafe-inline' and the declared resourceDomains
img-src, media-src data:, blob: and resourceDomains
font-src data: and resourceDomains
connect-src connectDomains, or 'none'
frame-src frameDomains, or 'none'
base-uri baseUriDomains, or 'none'
form-action 'none'

Only https:// origins count as domains, with an optional *. subdomain wildcard and port, at most 20 per list.

The bridge

The app and the host exchange JSON-RPC 2.0 messages over postMessage. The host answers only messages whose source is its own frame.

From the app The host
ui/initialize Answers protocol 2026-01-26, hostInfo, the capabilities openLinks, serverTools, message and logging, and a hostContext with theme, display mode, available modes (inline, fullscreen), locale, platform: 'web' and the tool name.
ui/notifications/initialized Sends ui/notifications/tool-input with the arguments, then ui/notifications/tool-result with the result.
ui/notifications/size-changed Sets the frame height, between 80 and 900 pixels.
tools/call Calls a tool through /api/mcp/call, only on the server the app came from.
ui/message Posts the text content in the chat as the person who uses the app, at most 4000 characters. A message with @architect asks the Architect.
ui/open-link Opens an http or https URL in a new tab.
ui/request-display-mode Switches between inline and fullscreen.
openai/setWidgetState Stores the state on the message, shared with the room.
ping Answers an empty result.
notifications/* Ignored.
Anything else Answers error -32000, "method is not supported by Archipelego."

The host also sends ui/notifications/host-context-changed when the theme or the display mode changes, and ui/resource-teardown before the frame goes away.

ChatGPT Apps SDK apps

The host injects a small window.openai shim before the app's own scripts. It maps the Apps SDK onto the same bridge:

window.openai Bridge
toolInput, toolOutput, toolResponseMetadata Filled from tool-input and tool-result, with an openai:set_globals event.
widgetState, setWidgetState() openai/setWidgetState, starting from the state saved on the message.
theme, displayMode, locale Follow host-context-changed.
callTool(name, args) tools/call
sendFollowUpMessage({ prompt }) ui/message
requestDisplayMode({ mode }) ui/request-display-mode
openExternal({ href }) ui/open-link

The shim uses request ids from one million upwards, so they never collide with the app's own. An app that never sends ui/initialize still gets the tool input and result 800 ms after the frame loads.

The canvas overview app

The built-in app lives in server/src/mcp-apps/canvas-overview.ts. It is self-contained: it loads nothing from the network.

  • The tool canvas_overview takes canvasId. It reads the canvas from the open room, or from its saved file, and answers a one-line text plus structuredContent: title, block, connection and post-it counts, blocks per layer, the ten most used kinds, and the features with their block and step counts.
  • An unknown or unsaved canvas answers isError with "This canvas has not been saved yet."
  • The page shows the counts and bars. Refresh calls the tool again with tools/call. Ask the Architect on a feature sends a ui/message that asks the Architect to tell its story.

The Architect's system prompt tells it to open this app with an mcp-app block when someone asks for an overview, statistics or a dashboard.

The RichCard component

The design system bundle exposes RichCard, the frame around rich UI in the chat:

Prop Meaning
kind 'a2ui' for an A2UI surface, or 'mcp-app' for an MCP App.
title The card title.
origin Where the card came from, shown in the header: "Architect · A2UI 1.0", or the server name and "MCP App".
expanded Shows the card in its larger state.
onExpand Adds an expand or close button to the header. MCP Apps use it for full screen.
children The rendered surface, or the sandboxed iframe.

The header carries a kind tag: A2UI, or App for an MCP App. The App tag uses signal. On an MCP App, the tooltip of the origin label says that it runs in an isolated sandbox. See bundle.js.

Security principles

  • An A2UI surface renders only known components. It never runs code from the agent.
  • An MCP App runs in a sandbox with an opaque origin and a strict CSP. It has no access to the parent page, to AI keys or to the canvas, except what the host passes to it.
  • An app can call only tools of its own server. Remote servers are chosen by the administrator, never by a participant or a model.
  • Every card shows its origin, so the room knows who built it.
  • An action inside a card goes back to the Architect as data, like a message from the person who took it.
  • Changes that the AI proposes stay drafts to review. Nothing changes the canvas until a person confirms it, as with feature drafts.

These rules extend the prompt-injection boundary of the Architect: content from participants and tools is data, never instructions. See Architect protocol.