npx skills add ...
npx skills add modelcontextprotocol/ext-apps --skill convert-web-app
This skill should be used when the user asks to "add MCP App support to my web app", "turn my web app into a hybrid MCP App", "make my web page work as an MCP App too", "wrap my existing UI as an MCP App", "convert iframe embed to MCP App", "turn my SPA into an MCP App", or needs to add MCP App support to an existing web application while keeping it working standalone. Provides guidance for analyzing existing web apps and creating a hybrid web + MCP App with server-side tool and resource registration.
npx skills add modelcontextprotocol/ext-apps --skill convert-web-app
Add MCP App support to an existing web application so it works both as a standalone web app and as an MCP App that renders inline in MCP-enabled hosts like Claude Desktop — from a single codebase.
The existing web app stays intact. A thin initialization layer detects whether the app is running inside an MCP host or as a regular web page, and fetches parameters from the appropriate source. A new MCP server wraps the app's bundled HTML as a resource and registers a tool to display it.
The app's rendering logic is shared — only the data source changes.
Clone the SDK repository for working examples and API documentation:
Read JSDoc documentation directly from /tmp/mcp-ext-apps/src/:
| File | Contents |
|---|---|
src/app.ts | App class, handlers (ontoolinput, ontoolresult, onhostcontextchanged, onteardown), lifecycle |
src/server/index.ts | registerAppTool, registerAppResource, tool visibility options |
src/spec.types.ts | All type definitions: McpUiHostContext, CSS variable keys, display modes |
src/styles.ts | applyDocumentTheme, applyHostStyleVariables, applyHostFonts |
src/react/useApp.tsx | useApp hook for React apps |
src/react/useHostStyles.ts | useHostStyles, useHostStyleVariables, useHostFonts hooks |
Learn and adapt from /tmp/mcp-ext-apps/examples/basic-server-{framework}/:
| Template | Key Files |
|---|---|
basic-server-vanillajs/ | server.ts, src/mcp-app.ts, mcp-app.html |
basic-server-react/ | server.ts, src/mcp-app.tsx (uses useApp hook) |
basic-server-vue/ | server.ts, src/App.vue |
basic-server-svelte/ | server.ts, src/App.svelte |
basic-server-preact/ | server.ts, src/mcp-app.tsx |
basic-server-solid/ | server.ts, src/mcp-app.tsx |
| Example | Relevant Pattern |
|---|---|
examples/map-server/ | External API integration + CSP (connectDomains, resourceDomains) |
examples/sheet-music-server/ | Library that loads external assets (soundfonts) |
examples/pdf-server/ | Binary content handling + app-only helper tools |
Before writing any code, examine the existing web app to plan what needs to change.
window.parent !== window)Present findings to the user and confirm the approach.
In hybrid mode, the app keeps its existing data sources for standalone use and adds MCP equivalents:
| Standalone data source | MCP App equivalent |
|---|---|
| URL query parameters | ontoolinput / ontoolresult arguments or structuredContent |
| REST API calls | app.callServerTool() to server-side tools, or keep direct API calls with CSP connectDomains |
| Props / component inputs | ontoolinput arguments |
| localStorage / sessionStorage | Not available in sandboxed iframe — pass via structuredContent or server-side state |
| WebSocket connections | Keep with CSP connectDomains, or convert to polling via app-only tools |
| Hardcoded data | Move to tool structuredContent to make it dynamic |
MCP Apps HTML runs in a sandboxed iframe with no same-origin server. Every external origin must be declared in CSP — missing origins fail silently.
Before writing any code, build the app and investigate all origins it references:
Document your findings as three lists, and note for each origin whether it's universal, dev-only, or prod-only:
If no origins are found, the app may not need custom CSP domains.
Create a new MCP server with tool and resource registration. This wraps the existing web app for MCP hosts.
Use npm install so the package manager resolves versions; ext-apps 2.x needs
the split base MCP SDK packages at ^2.0.0 (@modelcontextprotocol/core comes
in transitively). Do not add the legacy @modelcontextprotocol/sdk v1 package
or substitute unpublished local packages.
Create server.ts:
Add to package.json:
The MCP App build must produce a single HTML file using vite-plugin-singlefile. The standalone web app build stays unchanged.
Create or update vite.config.ts. If the app already uses Vite, add vite-plugin-singlefile and a separate entry point for the MCP App build. If it uses another bundler, add a Vite config alongside for the MCP App build only.
Add framework-specific Vite plugins as needed (e.g., @vitejs/plugin-react for React, @vitejs/plugin-vue for Vue).
Create mcp-app.html as a separate entry point for the MCP App build. This can point to the same app code — the runtime detection handles the rest:
dist/mcp-app.html (single file with all assets inlined)The standalone web app continues to build and deploy as before.
This is the core step. Instead of replacing the app's data sources, add an alternative initialization path for MCP mode. The app detects its environment at startup and reads parameters from the right source.
Or keep direct API calls in both modes with CSP connectDomains:
When running as an MCP App, integrate with host styling for theme consistency. Use CSS variable fallbacks so the app looks correct in both modes.
Vanilla JS — use helper functions:
React — use hooks:
Using variables in CSS — use var() with fallbacks so standalone mode still looks right:
Key variable groups: --color-background-*, --color-text-*, --color-border-*, --font-sans, --font-mono, --font-text-*-size, --font-heading-*-size, --border-radius-*. See src/spec.types.ts for the full list.
For data the UI needs to poll or fetch that the model doesn't need to call directly:
The UI calls these via
app.callServerTool({ name: "refresh-data", arguments: {} }).
For large tool inputs, use ontoolinputpartial to show progress during LLM generation:
Always provide a content array for non-UI hosts:
localStorage / sessionStorage in MCP mode — not available in sandboxed iframe; use fallbacks or pass via structuredContentvite-plugin-singlefile — external assets won't load in the iframeconnect() — register ALL handlers BEFORE calling app.connect()var(..., fallback) so both modes look correctctx.safeAreaInsets in onhostcontextchangedcontent fallback — always provide content array for non-UI hostsresourceUri that must have a matching resourceTest the MCP App mode with the basic-host example:
Configure SERVERS with a JSON array of your server URLs (default: http://localhost:3001/mcp).
ontoolinput handler fires with tool argumentsontoolresult handler fires with tool result