diff --git a/README.md b/README.md index 1b04e28..2e004d2 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ The fastest way to build an MCP App is to let your AI coding agent do it. This r | [`create-mcp-app`](./plugins/mcp-apps/skills/create-mcp-app/SKILL.md) | Scaffolds a new MCP App with an interactive UI from scratch | _"Create an MCP App"_ | | [`migrate-oai-app`](./plugins/mcp-apps/skills/migrate-oai-app/SKILL.md) | Converts an existing OpenAI App to use MCP Apps | _"Migrate from OpenAI Apps SDK"_ | | [`add-app-to-server`](./plugins/mcp-apps/skills/add-app-to-server/SKILL.md) | Adds interactive UI to an existing MCP server's tools | _"Add UI to my MCP server"_ | -| [`convert-web-app`](./plugins/mcp-apps/skills/convert-web-app/SKILL.md) | Converts an existing web app into an MCP App | _"Convert my web app to an MCP App"_ | +| [`convert-web-app`](./plugins/mcp-apps/skills/convert-web-app/SKILL.md) | Turns an existing web app into a hybrid web + MCP App | _"Add MCP App support to my web app"_ | ### Install the Skills @@ -72,8 +72,8 @@ Once installed, verify by asking your agent _"What skills do you have?"_ — you ## Supported Clients
-
-
+
+
diff --git a/plugins/mcp-apps/skills/convert-web-app/SKILL.md b/plugins/mcp-apps/skills/convert-web-app/SKILL.md
index 0b34216..5db2d94 100644
--- a/plugins/mcp-apps/skills/convert-web-app/SKILL.md
+++ b/plugins/mcp-apps/skills/convert-web-app/SKILL.md
@@ -1,24 +1,23 @@
---
name: convert-web-app
-description: This skill should be used when the user asks to "convert my web app to an MCP App", "turn my website into an MCP App", "make my web page an MCP tool", "wrap my existing UI as an MCP App", "convert iframe embed to MCP App", "turn my SPA into an MCP App", or needs to convert an existing web application into an MCP App with server-side tool and resource registration. Provides guidance for analyzing existing web apps and creating MCP server + App wrappers.
+description: 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.
---
-# Convert Web App to MCP App
+# Add MCP App Support to a Web App
-Turn an existing web application into an MCP App that renders inline in MCP-enabled hosts like Claude Desktop.
+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.
## How It Works
-The existing web app becomes the View (HTML resource) in an MCP App. A new MCP server is created to:
-
-1. Register a tool that the LLM calls to display the app
-2. Register the bundled HTML as a resource
-3. Pass data to the app via `structuredContent` instead of URL params / API calls
+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.
```
-Host calls tool → Server returns result → Host renders your web app → App receives data via MCP lifecycle
+Standalone: Browser loads page → App reads URL params / APIs → renders
+MCP App: Host calls tool → Server returns result → Host renders app in iframe → App reads MCP lifecycle → renders
```
+The app's rendering logic is shared — only the data source changes.
+
## Getting Reference Code
Clone the SDK repository for working examples and API documentation:
@@ -53,7 +52,7 @@ Learn and adapt from `/tmp/mcp-ext-apps/examples/basic-server-{framework}/`:
| `basic-server-preact/` | `server.ts`, `src/mcp-app.tsx` |
| `basic-server-solid/` | `server.ts`, `src/mcp-app.tsx` |
-### Conversion Reference Examples
+### Reference Examples
| Example | Relevant Pattern |
|---------|-----------------|
@@ -63,7 +62,7 @@ Learn and adapt from `/tmp/mcp-ext-apps/examples/basic-server-{framework}/`:
## Step 1: Analyze the Existing Web App
-Before writing any code, examine the existing web app to plan the conversion.
+Before writing any code, examine the existing web app to plan what needs to change.
### What to Investigate
@@ -71,17 +70,20 @@ Before writing any code, examine the existing web app to plan the conversion.
2. **External dependencies** — CDN scripts, fonts, API endpoints, iframe embeds, WebSocket connections
3. **Build system** — Current bundler (Webpack, Vite, Rollup, none), framework (React, Vue, vanilla), entry points
4. **User interactions** — Does the app have inputs/forms that should map to tool parameters?
+5. **Runtime detection** — How to tell if the app is running inside an MCP host (e.g., check the current origin, a query param, or whether `window.parent !== window`)
-Present findings to the user and confirm the conversion approach.
+Present findings to the user and confirm the approach.
### Data Source Mapping
-| Data source in web app | MCP App equivalent |
+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 — move to `structuredContent` or server-side state |
+| 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 |
@@ -89,7 +91,7 @@ Present findings to the user and confirm the conversion approach.
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 conversion code**, build the app and investigate all origins it references:
+**Before writing any code**, build the app and investigate all origins it references:
1. Build the app using the existing build command
2. Search the resulting HTML, CSS, and JS for **every** origin (not just "external" origins — every network request will need CSP approval)
@@ -108,7 +110,7 @@ If no origins are found, the app may not need custom CSP domains.
## Step 3: Set Up the MCP Server
-Create a new MCP server with tool and resource registration. The web app has no existing server, so this is built from scratch.
+Create a new MCP server with tool and resource registration. This wraps the existing web app for MCP hosts.
### Dependencies
@@ -185,11 +187,11 @@ Add to `package.json`:
## Step 4: Adapt the Build Pipeline
-The UI must be bundled into a single HTML file using `vite-plugin-singlefile`. Without it, external assets won't load in the sandboxed iframe.
+The MCP App build must produce a single HTML file using `vite-plugin-singlefile`. The standalone web app build stays unchanged.
### Vite Configuration
-Create or update `vite.config.ts`:
+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.
```typescript
import { defineConfig } from "vite";
@@ -210,7 +212,7 @@ Add framework-specific Vite plugins as needed (e.g., `@vitejs/plugin-react` for
### HTML Entry Point
-Create `mcp-app.html` as the entry point for the MCP App build:
+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:
```html
@@ -222,118 +224,170 @@ Create `mcp-app.html` as the entry point for the MCP App build: