npm package
@modelcontextprotocol/ext-apps review
Choose @modelcontextprotocol/ext-apps when you can maintain the HTML resource, browser connection and host verification together.
An MCP tool result and its interactive view need separate connections. @modelcontextprotocol/ext-apps provides server helpers that associate a tool with an HTML resource, plus a browser-side App that communicates through the host. Use it when a tool result needs an interactive view, such as a report with a refresh control. You still need an MCP server, a browser build and a host that supports MCP Apps.
Choose @modelcontextprotocol/ext-apps when you can maintain the HTML resource, browser connection and host verification together. Start with a text result and one small view, then verify that view in the intended host before expanding it.
Answers from our run
@modelcontextprotocol/ext-apps or @modelcontextprotocol/server: which should you use?
@modelcontextprotocol/server: @modelcontextprotocol/server is the TypeScript MCP server package. Use it for server work when you do not need the embedded view described here. The ext-apps server helpers wrap its tool and resource registration methods. Choose @modelcontextprotocol/ext-apps when you can maintain the HTML resource, browser connection and host verification together.
When should you not use @modelcontextprotocol/ext-apps?
Your tool only needs to return text or structured data. Use the server package without adding an HTML view.
Use it if
Skip it if
Setup reality
Version 2.0.4 requires Node.js 20 or newer. Its manifest separates the browser App entry point from /server, /react and /app-bridge. It declares @modelcontextprotocol/core and @modelcontextprotocol/client ^2.0.0 and zod ^4.2.0 as peers. The server peer is optional in npm metadata, but the server illustrations below use it. React and React DOM are optional peers; the App class is framework independent.
Connect two pieces. On the server, register a tool with _meta.ui.resourceUri and serve HTML at that URI with registerAppResource. The resource helper supplies a default MIME type for the listing. Include RESOURCE_MIME_TYPE on the returned content item too, as the source example does. Your build must produce the HTML file the callback reads. These illustrations do not configure a bundler, connect an MCP transport or deploy a host.
In the browser bundle, create App and attach notification listeners before connecting. Await app.connect() before making host-bound calls. With strict enabled, premature calls throw. Registering the first listener for a one-shot event after connection can also throw under strict mode because the host may already have sent that notification. If you supply an options object, set autoResize explicitly when you want it: the constructor's default options object applies only when that argument is omitted.
registerAppTool normalizes the modern UI resource URI into the legacy flat metadata key as well. This metadata conversion does not verify a particular host. Check advertised support with getUiCapability and retain a useful text fallback. For external assets and network requests, the server source demonstrates separate resourceDomains and connectDomains CSP lists. Verify their behavior in the intended host.
Evidence scope: this guide uses the published 2.0.4 manifest and the implementation at its gitHead. No installation, example execution, iframe rendering or host test is recorded in the supplied evidence. Every snippet is an unexecuted illustration. The core SDK guide covers the separate v1-versus-v2 package decision.
The site computes reader scores in code. The dimension notes below are editorial assessments of the supplied documentation, implementation and release evidence; they do not describe that calculation. Their assessment criteria are explicit API boundaries and migration details for API stability, concrete integration examples for documentation, release-specific upkeep for maintenance, and documented integration surfaces for ecosystem. No published numeric rubric was supplied, so this guide does not assign meanings to points on the scale. Host compatibility, production adoption and long-term reliability remain unmeasured.
Patterns
Install the UI package and explicit server peers install-app-packages
npm install @modelcontextprotocol/ext-apps@2.0.4 @modelcontextprotocol/core@2.0.0 @modelcontextprotocol/client@2.0.0 @modelcontextprotocol/server@2.0.0 'zod@^4.2.0'Unexecuted installation command. The MCP package versions match the manifest's declared peer ranges. React is unnecessary for these plain App illustrations. This command does not verify runtime or host behavior.
Associate a tool with an HTML view associate-tool-view
import { McpServer } from '@modelcontextprotocol/server';
import { z } from 'zod';
import { registerAppTool } from '@modelcontextprotocol/ext-apps/server';
const server = new McpServer({ name: 'report-server', version: '1.0.0' });
const viewUri = 'ui://reports/view.html';
registerAppTool(server, 'show-report', {
description: 'Show the current report',
inputSchema: z.object({}),
_meta: { ui: { resourceUri: viewUri } },
}, async () => ({
content: [{ type: 'text', text: 'Report ready' }],
}));Unexecuted server illustration. The following resource snippet reuses server and viewUri. Metadata references the HTML resource; it does not generate that file. Use z.object(), since the raw-shape overload is deprecated.
Serve the matching HTML resource serve-view-html
import { readFile } from 'node:fs/promises';
import { registerAppResource, RESOURCE_MIME_TYPE } from '@modelcontextprotocol/ext-apps/server';
registerAppResource(server, 'Report view', viewUri, {}, async () => ({
contents: [{
uri: viewUri,
mimeType: RESOURCE_MIME_TYPE,
text: await readFile('dist/report.html', 'utf8'),
}],
}));Unexecuted server continuation. Build dist/report.html with the browser code before serving it. This relative path uses the process working directory. The source example includes a MIME type on the returned content item as well as the helper's listing default.
Make a tool callable by the app UI restrict-tool-visibility
registerAppTool(server, 'refresh-report', {
description: 'Refresh the report view',
inputSchema: z.object({}),
_meta: { ui: { resourceUri: viewUri, visibility: ['app'] } },
}, async () => ({
content: [{ type: 'text', text: 'Report refreshed' }],
}));Unexecuted server continuation using server, z and viewUri. The source describes app-only visibility as hidden from the model and callable by the UI. This callback returns a fixed message; replace it with the report operation you need.
Declare the external origins a view needs declare-view-origins
registerAppResource(server, 'Remote report view', 'ui://reports/remote.html', {}, async () => ({
contents: [{
uri: 'ui://reports/remote.html',
mimeType: RESOURCE_MIME_TYPE,
text: await readFile('dist/remote-report.html', 'utf8'),
_meta: { ui: { csp: {
resourceDomains: ['https://cdn.example.com'],
connectDomains: ['https://api.example.com'],
} } },
}],
}));Unexecuted server continuation using the earlier imports. The origins are placeholders, and this resource needs its own HTML file and an associated tool URI. The source example uses resourceDomains for scripts, styles and images, and connectDomains for fetch and WebSocket. Verify the intended host's behavior.
Create the browser-side App create-browser-app
import { App } from '@modelcontextprotocol/ext-apps';
const app = new App(
{ name: 'Report view', version: '1.0.0' },
{},
{ autoResize: true, strict: true },
);Unexecuted browser-module illustration. Bundle this separately from the server code into the HTML resource. strict makes premature host-bound calls throw. autoResize is explicit because passing an options object replaces the constructor's default options object.
Attach view listeners before connecting listen-before-connect
const output = document.createElement('pre');
document.body.append(output);
const onResult = result => {
output.textContent = JSON.stringify(result, null, 2);
};
app.addEventListener('toolresult', onResult);
app.addEventListener('toolcancelled', () => {
output.textContent = 'The tool was cancelled.';
});
try {
await app.connect();
} catch (error) {
output.textContent = `Host connection failed: ${String(error)}`;
}Unexecuted browser continuation, run after document.body exists. Attach listeners before connecting to avoid missing early notifications. Only enable host calls after connection succeeds. Remove onResult with removeEventListener('toolresult', onResult) when its UI owner is disposed.
Handle both forms of tool failure call-originating-tool
async function refreshReport() {
try {
const result = await app.callServerTool({
name: 'refresh-report',
arguments: {},
});
output.textContent = result.isError
? `Tool error: ${JSON.stringify(result.content)}`
: JSON.stringify(result.content, null, 2);
} catch (error) {
output.textContent = `Request failed: ${String(error)}`;
}
}Unexecuted browser continuation using app and output. Call it from a refresh control only after connection succeeds and the server registers refresh-report. callServerTool takes one object containing name and arguments. Handle a returned isError separately from a rejected request, as the source example does.
Check advertised MCP Apps support check-app-capability
import { getUiCapability, RESOURCE_MIME_TYPE } from '@modelcontextprotocol/ext-apps/server';
function canRenderApp(clientCapabilities) {
const ui = getUiCapability(clientCapabilities);
return ui?.mimeTypes?.includes(RESOURCE_MIME_TYPE) ?? false;
}Unexecuted server-side helper; merge these imports with the earlier server imports if combining snippets. Supply client capabilities obtained through the server lifecycle. getUiCapability reads the io.modelcontextprotocol/ui extension. Retain a text fallback when support is absent, and verify advertised support in the intended host.
Alternatives
| Package | Registry | Pick it when |
|---|---|---|
| @modelcontextprotocol/server | npm | @modelcontextprotocol/server is the TypeScript MCP server package. Use it for server work when you do not need the embedded view described here. The ext-apps server helpers wrap its tool and resource registration methods. |
| @modelcontextprotocol/client | npm | @modelcontextprotocol/client is the TypeScript MCP client package. Use it for MCP client work. The App implementation imports its Protocol class and adds the Apps handshake and lifecycle, so the client package alone is not a substitute for that view layer. |
More cli & tooling guides
How this guide is made: grounded in the library's documentation, release notes, changelog, and issue history, on a fixed rubric — not a hands-on install of every release. The 50 most-downloaded entries are additionally install-verified in clean containers. Corrections: contact the desk.