Welcome! This document helps you navigate the WebMCP Examples repository efficiently.
Start here: CONTRIBUTING.md - Development standards and best practices
- README.md - What these examples demonstrate, quick start guide
- CONTRIBUTING.md - How to contribute new examples or improve existing ones
- vanilla/README.md - Shopping cart example using
@mcp-b/global - Location:
/vanilla - Key file:
vanilla/src/main.ts- Entry point with WebMCP tool registration - API used:
navigator.modelContext.registerTool()
- react/README.md - Task manager using
@mcp-b/react-webmcp - Location:
/react - Key file:
react/src/App.tsx- React component withuseWebMCPhooks - API used:
useWebMCP()hook
- rails/README.md - Bookmarks manager using Stimulus controllers
- Location:
/rails - Key file:
rails/app/javascript/controllers/bookmarks_webmcp_controller.ts- Stimulus controller with WebMCP tools - API used:
navigator.modelContext.registerTool()in Stimulus
- angular/README.md - Note manager using
@mcp-b/globalwith Angular services - Location:
/angular - Key file:
angular/src/app/services/webmcp.service.ts- Angular service with tool registration - API used:
navigator.modelContext.registerTool()via service
- phoenix-liveview/README.md - Counter + items with server-side state
- Location:
/phoenix-liveview - Key files:
lib/webmcp_demo_web/live/counter_live.ex- LiveView with state managementassets/js/app.js- WebMCP hook registration
- API used:
navigator.modelContext.registerTool()via LiveView hooks
- relegated/README.md - Old examples using deprecated MCP SDK
- Warning: These use the legacy
@modelcontextprotocol/sdkAPI - Status: Kept for reference only, not recommended for new projects
- CONTRIBUTING.md - Contribution guidelines
- CODE_OF_CONDUCT.md - Community standards
- CHANGELOG.md - Version history and changes
# Navigate to the example
cd vanilla # or react, rails, angular
cd vanilla # or react, rails, phoenix-liveview
# Install dependencies
pnpm install # For JS examples
# OR
mix setup # For Phoenix example
# Start development server
pnpm dev # For JS examples
# OR
mix phx.server # For Phoenix example- Check existing examples first to avoid duplication
- Choose the right location:
/vanillafor pure TypeScript/JavaScript/reactfor React-based examples/railsfor Rails with Stimulus examples/angularfor Angular-based examples
- Create self-contained directory with:
README.md- Documentationpackage.json- Dependenciessrc/- Source codevite.config.ts- Build config
- Use modern WebMCP API:
- Vanilla:
@mcp-b/globalpackage - React:
@mcp-b/react-webmcppackage
- Vanilla:
- Follow patterns in existing examples
- Document thoroughly - explain what WebMCP concepts are demonstrated
See CONTRIBUTING.md for detailed guidelines.
# Type-check
pnpm typecheck
# Lint
pnpm lint
# Build
pnpm buildVanilla TypeScript:
import '@mcp-b/global';
navigator.modelContext.registerTool({
name: 'my_tool',
description: 'What this tool does',
inputSchema: {
type: 'object',
properties: {
param: { type: 'string', description: 'Description' }
}
},
async execute(args) {
return {
content: [{ type: 'text', text: 'Result' }]
};
}
});React with Hooks:
import { useWebMCP } from '@mcp-b/react-webmcp';
import { z } from 'zod';
useWebMCP({
name: 'my_tool',
description: 'What this tool does',
inputSchema: {
param: z.string().describe('Description')
},
handler: async ({ param }) => {
return { success: true };
}
});Each example follows this structure:
example-name/
├── README.md # What it demonstrates, how to run
├── package.json # Dependencies (@mcp-b/* packages)
├── vite.config.ts # Vite configuration
├── tsconfig.json # TypeScript config
├── index.html # HTML entry point
└── src/
├── main.ts(x) # Application entry point
└── ... # Additional source files
Vanilla Example:
- Entry:
vanilla/src/main.ts - Config:
vanilla/vite.config.ts - Types:
vanilla/src/types.ts
React Example:
- Entry:
react/src/main.tsx - Root:
react/src/App.tsx - Config:
react/vite.config.ts
Rails Example:
- Entry:
rails/app/javascript/application.ts - Controller:
rails/app/javascript/controllers/bookmarks_webmcp_controller.ts - Config:
rails/vite.config.ts
Angular Example:
- Entry:
angular/src/main.ts - Root:
angular/src/app/app.component.ts - WebMCP:
angular/src/app/services/webmcp.service.ts - Config:
angular/angular.jsonPhoenix LiveView Example: - Entry:
phoenix-liveview/lib/webmcp_demo/application.ex - LiveView:
phoenix-liveview/lib/webmcp_demo_web/live/counter_live.ex - WebMCP Hook:
phoenix-liveview/assets/js/app.js - Config:
phoenix-liveview/config/config.exs
- @mcp-b/global - Core WebMCP polyfill for vanilla JS
- @mcp-b/react-webmcp - React hooks for WebMCP
- @mcp-b/transports - Transport layer (used internally)
- @mcp-b/core - Core functionality (used internally)
- WebMCP Introduction - What is WebMCP
- Quick Start - Get started in 2 minutes
- Concepts - Core concepts explained
- Examples - Additional examples
- Model Context Protocol - MCP overview
- MCP Specification - Protocol spec
- MCP UI Resources - UI resource types
- MCP-B Chrome Extension - Required for testing
- Node.js: 18 or higher (see
.nvmrc) - pnpm: Package manager (for JS examples)
- Elixir: 1.14+ (for Phoenix example)
- MCP-B Extension: Chrome extension for testing WebMCP tools
- Browser: Chrome or Chromium-based browser
When working on this repository:
-
Understand the context:
- Read README.md for project overview
- Check CONTRIBUTING.md for standards
- Review existing examples for patterns
-
Make changes:
- Follow TypeScript strict mode
- Use modern WebMCP API (never deprecated SDK)
- Document all public APIs with JSDoc
- Keep code self-documenting
-
Quality checks:
- Run
pnpm typecheck- must pass - Run
pnpm lint- must pass - Run
pnpm build- must succeed - Test manually with MCP-B extension
- Run
-
Documentation:
- Update README if changing functionality
- Add comments explaining WebMCP concepts
- Include examples in JSDoc
- Never use deprecated APIs from
/relegated- these are for reference only - Always use the latest packages:
@mcp-b/globaland@mcp-b/react-webmcp - Follow the single source of truth principle - don't duplicate information
- Keep examples simple - focus on demonstrating one concept clearly
- Test with the extension - every example must work with MCP-B Chrome Extension
- Check docs.mcp-b.ai for WebMCP documentation
- Review existing examples for patterns
- Read CONTRIBUTING.md for detailed guidelines
- Open a GitHub issue if you need help
Remember: This file is a navigation hub. Detailed information lives in linked documentation to maintain a single source of truth.