MCP Apps SDK
Project Overview
MCP Apps SDK (@modelcontextprotocol/ext-apps) enables MCP servers to display interactive UIs in conversational clients.
Key abstractions:
- Guest - UI running in an iframe, uses
Appclass withPostMessageTransportto communicate with host - Host - Chat client embedding the iframe, uses
AppBridgeclass to proxy MCP requests - Server - MCP server that registers tools/resources with UI metadata
Specification (draft): specification/draft/apps.mdx
Commands
# Install dependencies
npm install
# Build the SDK only (generates schemas + bundles, does not build examples)
npm run build
# Build everything (SDK + all examples)
npm run build:all
# Type check + build a single example
npm run --workspace examples/<example-name> build
# Run all examples (starts server at http://localhost:8080)
npm start
# Run E2E tests (primary testing mechanism - starts examples server automatically)
npm run test:e2e
# Run unit tests (E2E tests have broader coverage; unit tests cover specific modules)
npm test
# Check JSDoc comment syntax and `{@link}` references
npm exec typedoc -- --treatValidationWarningsAsErrors --emit none
# Regenerate package-lock.json (especially on setups w/ custom npm registry)
rm -fR package-lock.json node_modules && \
docker run --rm -it --platform linux/amd64 -v $PWD:/src:rw -w /src node:latest npm i && \
rm -fR node_modules && \
npm i --cache=~/.npm-mcp-apps --registry=https://registry.npmjs.org/
Architecture
SDK Entry Points
@modelcontextprotocol/ext-apps- Main SDK for Apps (Appclass,PostMessageTransport)@modelcontextprotocol/ext-apps/react- React hooks (useApp,useHostStyleVariables, etc.)@modelcontextprotocol/ext-apps/app-bridge- SDK for hosts (AppBridgeclass)@modelcontextprotocol/ext-apps/server- Server helpers (registerAppTool,registerAppResource)
Key Source Files
src/app.ts-Appclass extends MCP Protocol, handles guest initialization, tool calls, messagingsrc/app-bridge.ts-AppBridgeclass for hosts, proxies MCP requests, sends tool input/results to guestssrc/server/index.ts- Helpers for MCP servers to register tools/resources with UI metadatasrc/types.ts- Protocol types re-exported fromspec.types.tsand Zod schemas fromgenerated/schema.ts(auto-generated during build)src/message-transport.ts-PostMessageTransportfor iframe communicationsrc/react/- React hooks:useApp,useHostStyles,useAutoResize,useDocumentTheme
Protocol Flow
Guest UI (App) <--PostMessageTransport--> Host (AppBridge) <--MCP Client--> MCP Server
- Host creates iframe with Guest UI HTML
- Guest UI creates
Appinstance and callsconnect()withPostMessageTransport - App sends
ui/initializerequest, receives host capabilities and context - Host sends
sendToolInput()with tool arguments after initialization - Guest UI can call server tools via
app.callServerTool()or send messages viaapp.sendMessage() - Host sends
sendToolResult()when tool execution completes - Host calls
teardownResource()before unmounting iframe
Examples
Uses npm workspaces. Examples in examples/ are separate packages:
basic-server-*- Starter templates (vanillajs, react, vue, svelte, preact, solid). Use these as the basis for new examples.basic-host- Reference host implementation- Other examples showcase specific features (charts, 3D, video, etc.)
Claude Code Plugin
The plugins/mcp-apps/ directory contains a Claude Code plugin distributed via the plugin marketplace. It provides the "Create MCP App" skill (plugins/mcp-apps/skills/create-mcp-app/SKILL.md) that guides users through building MCP Apps with interactive UIs.