A modern task management application demonstrating the new WebMCP API with React hooks and Zod validation.
This example uses the simplified WebMCP React hooks introduced in 2024:
- ✅ Uses
useWebMCP()hook from@mcp-b/react-webmcp - ✅ Automatic Zod schema validation
- ✅ React state management built-in
- ✅ Type-safe with TypeScript
- ✅ Zero MCP SDK boilerplate
# 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 6 AI-callable tools:
- add_task - Create new tasks with priority and category
- complete_task - Mark tasks as completed
- delete_task - Remove tasks by ID
- list_tasks - Get filtered list of tasks
- update_task_priority - Change task priority level
- get_task_stats - Get task statistics and analytics
The React hook makes tool registration incredibly simple:
import { useWebMCP } from '@mcp-b/react-webmcp';
import { z } from 'zod';
function App() {
const [tasks, setTasks] = useState([]);
useWebMCP({
name: 'add_task',
description: 'Add a new task to the task manager',
inputSchema: {
title: z.string().min(1).describe('Task title'),
priority: z.enum(['low', 'medium', 'high']).default('medium'),
},
handler: async ({ title, priority }) => {
// Your logic here with React state
setTasks((prev) => [...prev, { title, priority }]);
return { success: true, message: 'Task added!' };
},
});
return <div>Your React UI</div>;
}- Zod Validation: Type-safe schema validation with helpful error messages
- React Integration: Seamless state updates via hooks
- Auto Cleanup: Tools automatically unregister on component unmount
- Simple Returns: Return plain objects (no MCP content wrapping needed)
Old API (deprecated):
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
// Complex setup with server, transport, tool registration...New API (recommended):
import { useWebMCP } from '@mcp-b/react-webmcp';
useWebMCP({ name, inputSchema, handler });The inputSchema uses Zod objects instead of JSON schema:
inputSchema: {
title: z.string().min(1).describe('Task title'),
priority: z.enum(['low', 'medium', 'high']).default('medium'),
tags: z.array(z.string()).optional(),
}This provides:
- Automatic type inference
- Runtime validation
- Better error messages
- Type safety throughout
MIT