What You’re Building
Building a bidirectional MCP-UI app means the AI agent can invoke your code, which then provides UI to the user, which can then invoke the AI again. This creates interactive workflows where the interface evolves based on what the agent decides to do.npx create-webmcp-app scaffolds a bidirectional system with three components:
- MCP Server (Cloudflare Worker) - Exposes tools to AI agents
- Embedded Web App (React or Vanilla JS) - Runs in an iframe, registers its own tools
- Communication Layer - IframeParentTransport ↔ IframeChildTransport
Quick Navigation
Quick Start
Get started in minutes with npx
Architecture
Understand how it works
MCP Server
Build the backend tools
Vanilla App
HTML/CSS/JS implementation
React App
TypeScript + React implementation
Deployment
Deploy to production
Quick Start
- Vanilla Template
- React Template
HTML/CSS/JavaScript with no build step. Uses CDN for dependencies.Runs at:
http://localhost:8889How it works: See MCP-UI Architecture for detailed diagrams and communication flow between the AI agent, MCP server, host application, and your embedded app.
Part 1: The MCP Server
The MCP server (worker/mcpServer.ts) exposes tools that return UI resources.
Example: Template MCP Server
Part 2: The Embedded App (Vanilla)
The Vanilla template uses@mcp-b/global via CDN—no build step required.
Full template with styling and additional tools available via
npx create-webmcp-app (select “vanilla”). Tool handlers and UI buttons should share the same state management logic.Part 3: The Embedded App (React)
src/main.tsx - Initialize WebMCP before rendering:useWebMCP:
Full template with Zod validation, TypeScript types, and additional tools available via
npx create-webmcp-app (select “react”).Development Workflow
1
Start Development Server
Launch your local development environment:This starts:
- MCP server:
http://localhost:8888/mcp(or 8889 for vanilla) - Embedded app:
http://localhost:8888/(served by the worker) - Hot reload: Changes to your app update instantly
2
Connect a Test Client
- Chat UI
- Claude Desktop
Use the included chat-ui (in mcp-ui-webmcp repo):
3
Test the Interaction
- AI calls
showTemplateApp→ iframe appears - AI calls
template_get_message→ reads current state - AI calls
template_update_message→ updates the UI - UI buttons use the same logic as tool handlers
Best Practices
Share logic between UI and tools
Share logic between UI and tools
Use tool annotations
Use tool annotations
Use
destructiveHint, idempotentHint, and readOnlyHint to help AI understand tool behavior.Validate inputs
Validate inputs
Use JSON Schema (Vanilla) or Zod (React) for type-safe, validated tool inputs.
Handle parent-ready protocol
Handle parent-ready protocol
Wait for the
parent_ready message before sending notifications to avoid race conditions.Deployment
https://your-app.workers.dev/mcp). See the mcp-ui-webmcp repository for detailed deployment instructions.
Next Steps
MCP-UI Architecture
Deep dive into architecture and communication flow
Examples
Production examples including TicTacToe game
@mcp-b/react-webmcp
React hooks API reference
@mcp-b/transports
Transport layer documentation
Troubleshooting
Common issues and solutions
Resources
- Source Code: mcp-ui-webmcp repository
- Live Demos:
- Documentation:
- Community: WebMCP Discord
