A modern shopping cart application demonstrating the new WebMCP API with vanilla TypeScript.
This example uses the simplified WebMCP API introduced in 2024:
- ✅ Uses
navigator.modelContext.registerTool()- no MCP SDK required - ✅ Simple JSON schema validation
- ✅ Zero boilerplate compared to legacy examples
- ✅ Just install
@mcp-b/globaland start coding
# Install dependencies
pnpm install
# Run development server
pnpm devThen open your browser and install the MCP-B extension to interact with the tools.
This example exposes 5 AI-callable tools:
- add_to_cart - Add products to the shopping cart
- remove_from_cart - Remove items by product ID
- get_cart - View current cart contents
- clear_cart - Empty the entire cart
- get_cart_total - Get the total price
The new API is incredibly simple:
import '@mcp-b/global';
navigator.modelContext.registerTool({
name: 'add_to_cart',
description: 'Add a product to the shopping cart',
inputSchema: {
type: 'object',
properties: {
productId: { type: 'string', description: 'Unique product ID' },
name: { type: 'string', description: 'Product name' },
price: { type: 'number', description: 'Product price in USD' },
},
required: ['productId', 'name', 'price'],
},
async execute(args) {
// Your logic here
return {
content: [{ type: 'text', text: 'Success!' }],
};
},
});Old API (deprecated):
import { TabServerTransport } from '@mcp-b/transports';
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
// ... lots of boilerplateNew API (recommended):
import '@mcp-b/global';
navigator.modelContext.registerTool({ ... });MIT