Prerequisites
Before you begin, ensure you have:- Modern browser: Chrome, Edge, or Brave (latest version)
- MCP-B Extension installed from Chrome Web Store
- Node.js 18+ (for NPM installation) or basic HTML knowledge (for script tag method)
- Package manager: npm, pnpm, or yarn (optional for NPM method)
Installation
- React (Recommended)
- Vanilla JS
- Script Tag
Building Interactive Apps with MCP-UI + WebMCP
Want to build interactive apps that AI agents can control? Usecreate-webmcp-app:
- MCP Server (Cloudflare Workers) - Exposes tools to AI
- Embedded App (React or Vanilla) - Runs in iframe, registers tools
- Bidirectional Communication - AI controls your app, your app notifies AI
Real-World Example
Wrap your existing application logic as tools:- React
- Vanilla JS
Testing
- Run dev server:
pnpm dev - Open in Chrome with MCP-B extension
- Click extension icon → Tools tab
- Test tools via chat or inspector
Examples
webmcp.sh
Production-ready React app with database, navigation, and graph tools
Vanilla TypeScript
Todo app with dynamic tool registration
Script Tag
Zero-config setup with no build tools
More Examples
Vue, Nuxt, React Flow, and community examples
Best Practices
✅ Use registerTool() - it just works!
✅ Use registerTool() - it just works!
For 99% of use cases, use
navigator.modelContext.registerTool(). It’s simple, automatic, and handles cleanup for you.⚛️ React: Use the useWebMCP() hook
⚛️ React: Use the useWebMCP() hook
React users should use the
useWebMCP() hook - it handles registration, cleanup, and Zod validation automatically:🔒 Security first
🔒 Security first
- Only expose tools users can already access via your UI
- Validate all inputs with schemas
- Use
credentials: 'same-origin'for API calls - Tools inherit the user’s authentication and permissions
🎨 Tool design tips
🎨 Tool design tips
- Use descriptive names:
add_to_cart,search_products,update_profile - Wrap existing functions - don’t duplicate logic
- Provide visual feedback when tools execute
- Return clear success/error messages
⚠️ When to use provideContext()
⚠️ When to use provideContext()
Only use
provideContext() for defining base application-level tools. Most developers should stick with registerTool().See Advanced Patterns for details.