DEV Community

Cover image for MCP Apps in Angular: signals in, one HTML file out
Umbo
Umbo

Posted on

MCP Apps in Angular: signals in, one HTML file out

An MCP App is a small web page that a chat host shows inside the conversation when the model calls a tool: a chart, a form, a list to tick, instead of a wall of text. The page runs in a sandboxed iframe and talks to the host with JSON-RPC over postMessage.

An assistant answers three questions with small apps inside the chat: a packing list to tick, a sales chart, a table booking.

I wanted to write those pages in Angular, the way I write any other Angular application. Two things were in the way:

  1. The protocol. The handshake, the tool input and result, theme and display mode changes, teardown: all of it arrives as messages that you have to listen for, check and turn into state.
  2. The build. A host loads the app from one HTML resource. ng build gives you an index.html plus scripts, styles, fonts and lazy chunks.

So I made ngx-mcp-apps: a library that speaks the protocol and exposes it as signals, and a builder that turns ng build into a single HTML file. It is an unofficial community project, MIT licensed.

How the pieces talk

1. model  ──► host             "call show_chart"
2. host   ──► MCP server       tools/call, resources/read (ui://…)
3. host   ──► iframe           your HTML, then the tool result (postMessage)
4. iframe ──► host ──► server  tool calls made by the app (postMessage)
Enter fullscreen mode Exit fullscreen mode

The app never talks to the server directly: everything goes through the host, in both directions.

Quick start

In an Angular application (18 to 22):

ng add ngx-mcp-apps-builder
Enter fullscreen mode Exit fullscreen mode

This installs the library and the builder, and sets the build target to write one file, dist/<project>.html.

Register the app:

// app.config.ts
import { ApplicationConfig } from '@angular/core';
import { provideMcpApp } from 'ngx-mcp-apps';

export const appConfig: ApplicationConfig = {
  providers: [provideMcpApp({ name: 'my-app', version: '1.0.0' })],
};
Enter fullscreen mode Exit fullscreen mode

Read the tool result in a component:

// app.ts
import { Component, inject } from '@angular/core';
import { McpApp, isObject } from 'ngx-mcp-apps';

interface Greeting {
  message: string;
}
const isGreeting = (v: unknown): v is Greeting =>
  isObject(v) && typeof v['message'] === 'string';

@Component({
  selector: 'app-root',
  template: `
    <p>{{ mcp.status() }} · {{ mcp.displayMode() }}</p>
    <p>{{ greeting()?.message }}</p>
    @if (mcp.canFullscreen()) {
      <button (click)="mcp.toggleFullscreen()">Fullscreen</button>
    }
  `,
})
export class App {
  protected readonly mcp = inject(McpApp);
  // structuredContent of the tool call that opened the app, checked and typed
  protected readonly greeting = this.mcp.structuredContentAs(isGreeting);
}
Enter fullscreen mode Exit fullscreen mode
ng build
Enter fullscreen mode Exit fullscreen mode

The connection starts on its own when McpApp is first injected. Outside a host (ng serve, a plain browser tab) status() becomes standalone, so you develop the app as a normal page.

What you get

Signals Connection status, tool input and result, host theme, display mode. No subscriptions to manage, and it works without zone.js.
Small About 14 KB minified, about 5 KB gzipped, no runtime dependencies. Host messages are checked with hand-written type guards instead of a schema library.
One file The builder runs Angular's own application builder, then inlines scripts, styles, and the fonts and images your CSS references. Lazy routes and @defer blocks are merged into the file.
Angular 18 to 22 Each major is checked with a new application: installed, built, opened in a browser.

The server side, in short

The page needs an MCP server to hand it to the host. Any server that follows the MCP Apps specification works. The shape is always the same: serve the HTML as a ui:// resource, and link a tool to it.

import {
  registerAppTool,
  registerAppResource,
  RESOURCE_MIME_TYPE,
} from '@modelcontextprotocol/ext-apps/server';

const uri = `ui://greeting/app-${hash}.html`; // hash of the build: see below

registerAppResource(server, 'greeting', uri, { description: 'Greeting' }, async () => ({
  contents: [{ uri, mimeType: RESOURCE_MIME_TYPE, text: html }],
}));

registerAppTool(
  server,
  'greet',
  {
    title: 'Greeting',
    description: 'Shows a greeting as an interactive app in the conversation.',
    inputSchema: { name: z.string() },
    _meta: { ui: { resourceUri: uri } },
  },
  async ({ name }) => ({
    content: [{ type: 'text', text: `Greeted ${name} in the app.` }],
    structuredContent: { message: `Hello, ${name}!` },
  }),
);
Enter fullscreen mode Exit fullscreen mode

content is what the model reads. structuredContent is what the app reads. The documentation has a complete server in Node.

Things I learned on a real phone

I tested with claude.ai on the web and the Claude app for Android. A few things only showed up there:

Inside Claude for Android: the app is connected to the host, with dark theme and 334 px width, and the Angular Material form field, datepicker and dialog work.

  • Keep the state on the server. The iframe is recreated when the conversation is reopened, and the host gives it the original tool result again. Ask the server for the current state when the app starts.
  • Put a hash of the build in the resource address. Hosts may cache the page. ui://my-app/app-<hash>.html makes a new build visible at once.
  • Send the app's data in structuredContent. It reaches the view unchanged and the model does not read it.
  • Design for a narrow frame. The frame Claude for Android gives the app is 334 px wide.
  • Use withHashLocation() if you need a router, and do not count on localStorage: the iframe is not your origin.

WebAssembly runs (at least a small one)

I also tried WebAssembly inside an app. The page carried a tiny hand-written module, a few bytes inside the HTML, with one function, add.

Host Claude for Android 1.261124.19
System Android 16, WebView Chrome 157
WebAssembly exists yes
new WebAssembly.Module (sync) yes, 1 export
WebAssembly.instantiate (async) yes
Call add(20, 22) = 42

This is worth noting because the default Content Security Policy in the MCP Apps specification (script-src 'self' 'unsafe-inline') has no 'wasm-unsafe-eval', which would block the compilation. The resource declared no special permission, so Claude for Android does not seem to apply that default as it is written.

What this does not show: it was one run, with a module of a few bytes embedded in the page. I have not tried a real module of several megabytes, a .wasm file fetched from another address, or claude.ai in the browser.

Limits

It follows the MCP Apps specification (protocol 2026-01-26), so other hosts that implement it should work, but I have only tried Claude. A web worker cannot be merged into a single file and fails the build. The API may still change between minor versions until 1.0.

Links

If you try it in a host I have not tested, I would like to hear what happens: issues are open.

Top comments (0)