---
title: "MCP UI"
description: "Declare interactive views that an agent shows in its chat, such as an approve-or-deny decision for a workflow run."
---

> Documentation Index
> Fetch the complete documentation index at: https://buildrforge.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# MCP UI

An MCP UI is an interactive view that an extension declares and an agent shows in its chat. When the moment fits its description, the agent shows the UI instead of describing a choice in text: an invoice to approve or deny, a form to fill in, or a list to review. The person working with the agent acts in the UI, and the UI tells the agent what they did.

MCP UIs use [MCP Apps](https://modelcontextprotocol.io/extensions/apps/overview), the MCP extension that lets a chat render a tool's result as a web page. Claude, ChatGPT, Visual Studio Code, and Goose render MCP Apps. A client that doesn't render them never sees an extension's MCP UIs, and its agent works through `execute` as before.

An MCP UI differs from an [extension UI](https://buildrforge.com/docs/extensions/extension-ui/):

| | MCP UI | Extension UI |
| --- | --- | --- |
| Where it runs | In the agent's chat, in a frame that the chat sandboxes | At its own address, in a browser tab |
| Who opens it | The agent, with `show_mcp_ui` | A person who follows its address |
| How it reaches Forge | Through the chat and the MCP server, as the user the agent signed in as | Through its own address, as the user signed in to it |
| Its files | One module per UI under `ui/mcp/` | `ui/web/index.html` and the files it names |

## Declare an MCP UI

An MCP UI is a declaration in `index.ts` and a module of the same name under `ui/mcp/`. Declare it with `mcpUi` from `@buildr/sdk`, under `mcpUis` in `defineExtension`:

```ts
import { boolean, defineExtension, mcpUi, number, object, string, tool, workflow } from "@buildr/sdk";

const approval = workflow(
  {
    description: "Waits for a member to approve or deny an invoice",
    input: object({ invoice: string(), vendor: string(), amount: number() }),
    signals: { decision: object({ approved: boolean(), note: string() }) },
  },
  async ({ step }, input) => {
    const { payload, sentBy } = await step.waitForSignal<{ approved: boolean; note: string }>(
      "decision",
      { timeout: "3 days" },
    );
    return { invoice: input.invoice, approved: payload.approved, decidedBy: sentBy };
  },
);

const requestApproval = tool(
  {
    description: "Starts an approval workflow run for an invoice",
    input: object({ invoice: string(), vendor: string(), amount: number() }),
  },
  async (ctx, input) => ctx.workflows.start("approval", input),
);

export default defineExtension({}, {
  tools: { requestApproval },
  workflows: { approval },
  mcpUis: {
    approveInvoice: mcpUi({
      description:
        "Shows an invoice that an approval workflow run waits on, so the user approves or denies it. Show it after requestApproval starts a run.",
      props: object({ runId: string() }),
    }),
  },
});
```

`mcpUi` takes these options:

| Option | Holds |
| --- | --- |
| `description` | When an agent shows the UI, and what the user does in it. The agent chooses a UI by its description, as it chooses a tool. |
| `props` | The value type of what the agent passes the UI: the IDs of what it shows, such as a workflow run's. Without it, the UI takes no props. |

### Pass IDs, not data

Declare props as the IDs of what the UI shows, and have the UI read the data itself through `forge`. An agent writes the props, so a UI that renders an amount or a name from them renders whatever the agent wrote. A UI that reads them by ID renders Forge's records, as the person who acts on them expects. The example above takes the run's ID and reads the invoice from the run's input.

A UI's name is an identifier, such as `approveInvoice`, and its module is `ui/mcp/<name>.tsx`, `.ts`, `.jsx`, or `.js`. A declaration without its module, or a module directly under `ui/mcp/` that `defineExtension` doesn't declare, fails the build with `DeclarationFailed`. Modules in folders under `ui/mcp/`, such as `ui/mcp/components/Card.tsx`, belong to the UIs that import them.

## Write the UI's module

An MCP UI's module is browser code. It imports `@buildr/sdk/mcp-ui` and renders into the element whose ID is `root`:

```ts
import { agent, forge, context, props } from "@buildr/sdk/mcp-ui";
import "./approveInvoice.css";

const { runId } = props as { runId: string };
const run = { repo_id: context.repo.id, name: context.extension.name, run_id: runId };
const onBranch = { ...run, branch: context.branch };
const decision = { signal: "decision", body: { payload: { approved: true, note: "" } } };

const show = async () => {
  const { input } = (await (context.installation
    ? forge.extensions.getRepoExtensionInstallationWorkflowRun(run)
    : forge.extensions.getRepoBranchExtensionWorkflowRun(onBranch))) as {
    input: { invoice: string; vendor: string; amount: number };
  };
  const { invoice, vendor, amount } = input;
  const approve = document.createElement("button");
  approve.textContent = `Approve ${invoice} from ${vendor} for $${amount}`;
  document.getElementById("root")?.append(approve);
  approve.addEventListener("click", async () => {
    await (context.installation
      ? forge.extensions.createRepoExtensionInstallationWorkflowRunSignal({ ...run, ...decision })
      : forge.extensions.createRepoBranchExtensionWorkflowRunSignal({ ...onBranch, ...decision }));
    await agent.message(`I approved invoice ${invoice}.`);
  });
};

void show();
```

A run belongs to where its tool ran, and each place has operations of its own: the repo's installation when `context.installation` is `true`, and otherwise a branch of the repo that defines the extension, which is where an agent [tries a UI](#how-an-agent-shows-an-mcp-ui) before a release. The example reads and answers the run in either place, as `callTool` does for a tool.

`@buildr/sdk/mcp-ui` exports these values:

| Export | Holds |
| --- | --- |
| `props` | What the agent passed, which the MCP server checked against the declared `props` before the user saw anything. |
| `context` | Where the UI runs: `repo.id`, `extension.name`, `branch`, and `installation`. `installation` is `true` when the repo installed the extension, and `branch` is then `"main"`. |
| `forge` | The Forge API as the user the agent signed in as, with the operations, names, and input of `forge` in the MCP server's `execute`. It rejects with a `ForgeError`. |
| `callTool(tool, body)` | Calls one of the extension's own tools where the UI runs: on the branch of the repo that defines it, or on the repo that installed it. |
| `agent.message(text)` | Sends text into the chat as the user, which the agent answers, as when the user picks an option. |
| `agent.updateContext(text)` | Tells the agent what the user did without asking it to answer. The agent reads it on its next turn, and each update replaces the last. |
| `app` | The chat, as ext-apps' [`App`](https://apps.extensions.modelcontextprotocol.io/api/classes/app.App.html), connected: the same object that every MCP App's own code uses. Read the chat's theme and size with `getHostContext()` and `addEventListener("hostcontextchanged", …)`, open links with `openLink`, and ask for fullscreen with `requestDisplayMode`. `agent.message` and `agent.updateContext` call its `sendMessage` and `updateModelContext`. |

The build bundles each UI into one script, with the npm packages that it imports, React's JSX in `.tsx` and `.jsx` files, and the CSS that its modules import. The rules of a UI's build apply, as [How `ui/web/index.html` is compiled](https://buildrforge.com/docs/extensions/extension-ui/#how-uiwebindexhtml-is-compiled) describes, with these differences:

- A UI's script runs as a classic script, so a module can't use `await` at its top level. Start async work from a function, as the example above does.
- A UI can't import a binary file, such as an image or a WebAssembly module, or an Elm module.
- A UI's script holds at most 2 MiB.

The chat's frame opens no network connection of its own: every call that the UI makes reaches Forge through the chat and the MCP server. The chat may ask the user before it sends a UI's call.

Forge's shell, an MCP App built on ext-apps' `App`, renders every MCP UI. It follows the chat's theme with ext-apps' `applyDocumentTheme`, `applyHostStyleVariables`, and `applyHostFonts`, so a UI that styles itself with the [standard CSS variables](https://apps.extensions.modelcontextprotocol.io/api/documents/patterns.html), such as `var(--color-text-primary)`, matches the chat.

The shell holds ext-apps and connects `app` to the chat, so a UI needs no ext-apps of its own to run, and `@buildr/sdk/mcp-ui` bundles none. Declare `"@modelcontextprotocol/ext-apps": "^2.0.4"` in `package.json` for your editor to type `app`, or when the UI imports ext-apps' own functions, which its build then bundles like any package.

### Style for light and dark

A chat shows a UI in its own theme, light or dark, and sets the text color of the UI's page from it. A UI that hard-codes one of its colors, such as a white card, and takes the other from the chat, such as the text, can be unreadable in the other theme. Color every surface and text with the standard CSS variables and a fallback, such as `background: var(--color-background-secondary, #f5f4ed)`, and never with a fixed color alone. Then show the UI in both themes.

## How an agent shows an MCP UI

A client that renders MCP Apps sees the MCP server's `show_mcp_ui` tool. The agent finds MCP UIs with `search`, which lists the MCP UIs of the extensions installed in the agent's repos, each with its description, the type of its props, and the `show_mcp_ui` call that shows it.

The agent calls `show_mcp_ui` with the repo the UI acts on, the extension, the UI's name, and its props:

```json
{
  "repo_id": "repo_01m64qpetrfap9y1j572cntmqn",
  "extension": "integrations.invoices",
  "mcp_ui": "approveInvoice",
  "props": { "runId": "extension_workflow_run_01m6…" }
}
```

The MCP server checks the props against the type of the UI that the repo runs, so a wrong name or a mismatch is the agent's to fix before the user sees anything. The chat then renders the UI. As with tools, a UI runs at the version that the repo's installation pins on `main`, with `extension` as the qualified name (`<repo slug>.<name>`). To try a UI of an extension that the repo defines, the agent passes `branch` and the extension's own name, and the UI runs at the version that the branch's head commit publishes. A chat that shows an earlier answer again runs the version that the repo runs then.

## Read an MCP UI through the API

| Request | Answers | CLI |
| --- | --- | --- |
| `GET /orgs/:org_id/installation-mcp-uis` | The MCP UIs of the extensions installed in your repos, once for each repo | `forge registry list-installation-mcp-uis` |
| `GET /repos/:repo_id/branches/:branch/extensions/:name/mcp-uis/:mcp_ui` | One MCP UI of the version that the branch's head commit publishes, with its description and compiled script | `forge extensions get-extension-mcp-ui` |
| `GET /repos/:repo_id/extension-installations/:name/mcp-uis/:mcp_ui` | One MCP UI of main's installation, with its description and compiled script | `forge extensions get-extension-installation-mcp-ui` |

Source: https://buildrforge.com/docs/extensions/mcp-ui/index.mdx
