Register tools based on authentication, permissions, or user roles:
Copy
import { useWebMCP } from '@mcp-b/react-webmcp';import { useAuth } from './auth';import { z } from 'zod';function AdminPanel() { const { user } = useAuth(); // Only register admin tools if user is admin useWebMCP({ name: 'delete_user', description: 'Delete a user account (admin only)', inputSchema: { userId: z.string().uuid() }, handler: async ({ userId }) => { if (!user?.isAdmin) { throw new Error('Unauthorized'); } await api.users.delete(userId); return { success: true }; }, // Only register if user is admin enabled: user?.isAdmin }); return <div>Admin Panel</div>;}
For comprehensive context engineering patterns including URL-based scoping, progressive disclosure, role-based tools, component lifecycle scoping, and feature flags, see the dedicated Context Engineering guide.
The key principle: limit tool availability based on application state to reduce AI model confusion and improve decision quality. Use the enabled prop on useWebMCP to conditionally register tools.
The MCP-B Extension collects and maintains tools from all open tabs simultaneously, making them available to agents regardless of which tab is currently active.
Key behavior: Unlike traditional tab-scoped approaches, the extension aggregates tools from every open tab, giving agents access to your entire browsing context at once.
Since all tools from all tabs are visible to the agent:
Tool Naming Matters
Use descriptive, namespaced tool names to avoid confusion:
Copy
// Good - clear which site/featureuseWebMCP({ name: 'github_create_issue', description: 'Create a new GitHub issue', // ...});// Avoid - ambiguoususeWebMCP({ name: 'create', description: 'Create something', // ...});
Context in Descriptions
Since agents see all tools at once, make descriptions specific:
Copy
// Good - describes what and whereuseWebMCP({ name: 'add_to_cart', description: 'Add the currently viewed product from shop.example.com to your shopping cart', // ...});// Avoid - lacks contextuseWebMCP({ name: 'add_to_cart', description: 'Add item to cart', // ...});
Tool Availability
Tools appear and disappear as you open/close tabs:
Copy
// This tool is available whenever the product page tab is openfunction ProductPage() { useWebMCP({ name: 'get_current_product', description: 'Get details about the currently viewed product', handler: async () => { return await fetchProductDetails(productId); } }); return <div>Product Details</div>;}// When user closes this tab, get_current_product disappears from the toolkit
Cross-Tab Workflows
Agents can naturally compose tools from different tabs:
Copy
// Tab 1: Calendar appuseWebMCP({ name: 'calendar_add_event', description: 'Add event to calendar', inputSchema: { title: z.string(), date: z.string().datetime() }, handler: async ({ title, date }) => { return await calendar.addEvent({ title, date }); }});// Tab 2: Email appuseWebMCP({ name: 'email_get_unread', description: 'Get unread emails', handler: async () => { return await email.getUnread(); }});// Agent can: "Get my unread emails and add any meeting invites to my calendar"// It sees and can use tools from both tabs
When many tabs are open, agents see many tools. Use context engineering patterns to help:
Copy
// Add metadata to help agents understand when to use toolsuseWebMCP({ name: 'shop_checkout', description: 'Complete checkout on shop.example.com. Only use this after items have been added to cart and user has confirmed.', handler: async () => { return await processCheckout(); }});// Or conditionally register tools based on statefunction CartPage() { const { items } = useCart(); // Only show checkout tool when cart has items useWebMCP({ name: 'shop_checkout', description: 'Complete the checkout process', handler: async () => { return await processCheckout(); }, enabled: items.length > 0 }); return <div>Cart</div>;}
One of the most powerful features of the MCP-B Extension is the ability to compose tools from different websites. Tools from one site can use data from another site, enabling complex multi-site workflows.
Key advantage: Each site exposes its existing functionality as MCP tools, and the extension handles routing calls between them. The user maintains separate authentication contexts for each site.
How it works: Agent can call tools from both sites. The extension routes each tool call to the correct tab, preserving separate authentication contexts for each site. Tools are thin wrappers around existing APIs - no special auth needed.