Generate Interactive MCP App
This skill provides the structure and instructions required to build an interactive, frontend-enabled MCP application using React, Vite, and the Model Context Protocol ext-apps SDK.
Requirements
When building an interactive MCP app, you must abide by the following architectural constraints:
1. Build System & Bundling
- Utilize Vite along with
vite-plugin-singlefile. Interactive MCP apps serve their frontend via custom URI protocols (ui://...), making it highly advantageous to bundle the entire React application (HTML, CSS, JS) into a single file to simplify resource serving. - The
mcp-app.htmlfile must act as the Vite input.
2. Required File Structure
Your generated workspace should include at least the following:
package.json: Include@modelcontextprotocol/sdk,@modelcontextprotocol/ext-apps,react, andvite.main.ts: The entry point that opens the transport (e.g.,StdioServerTransportfor Claude Desktop).server.ts: InitializesMcpServer, sets up tools, and exposes the UI resource.vite.config.ts: Configures the single-file plugin.mcp-app.html: Boilerplate HTML container.src/mcp-app.tsx: The React entrypoint demonstrating theuseApphook.src/global.css&src/mcp-app.module.css: Global baseline and scoped CSS Modules.
3. Connection and Logic (src/mcp-app.tsx)
- Use the
useApphook from@modelcontextprotocol/ext-apps/reactto wire the UI to the MCP host. - Handle
app.onhostcontextchangedto calculatesafeAreaInsetsand prevent the UI from being clipped by the Claude Desktop interface. - Handle
app.ontoolresultto parse incoming data generated by standard MCP tool calls. - Use
app.callServerTool({ name, arguments })to execute logic directly from user interactions in the UI.
4. Styling and Theming Rules
- Color Scheme: Include
<meta name="color-scheme" content="light dark">in the HTML head. - CSS Modules: Prefer CSS Modules (
*.module.css) to prevent style collisions between different parts of the interactive card. - Safe Area Insets: Always apply padding to the main container mapping to the host's safe area (
hostContext.safeAreaInsets.top|bottom|left|right).
AI Implementation Steps
When asked to create an MCP UI application, follow these sequential steps:
- Define the backend dependencies and initialize the
package.jsonwith correct build scripts (e.g.,tsc && vite build). - Write the backend logic (
server.tsandmain.ts) defining the necessary tools andMcpServersetup. - Write the frontend React logic (
mcp-app.tsx), tightly binding theuseApphook with UI state. - Implement standard CSS and safe area padding calculations.
- Provide the user with a setup guide on how to register the app in their
claude_desktop_config.json.