Skip to main content

Dynamic Tool Registration

Conditional Tools Based on User State

Register tools based on authentication, permissions, or user roles:

Page-Specific Tools

Register tools based on the current route - tools appear and disappear as users navigate:

Context Engineering

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.

State Synchronization

React State Integration

Tools can access and update React state:

Context API Integration

Share tools across the component tree using React Context:

Advanced Validation

Complex Input Validation

Zod supports sophisticated validation patterns:

Custom Validation Logic

Add business logic validation in your handler:

Error Handling

Handle errors gracefully and provide clear feedback:

Performance Optimization

Use debouncing, throttling, and caching for expensive operations:

Multi-Tab Tool Collection

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.

How Tool Collection Works

When you have multiple tabs open with WebMCP servers:

Tool Routing

When an agent calls a tool:
1

Agent requests tool

Agent calls a tool (e.g., github_com_create_issue)
2

Extension identifies source

Extension determines which tab owns that tool
3

Extension routes call

If the tab is open, the tool is executed immediately. If the tab was closed, the extension may need to reopen it.
4

Results returned

Tool execution results are returned to the agent

Design Implications

Since all tools from all tabs are visible to the agent:
Use descriptive, namespaced tool names to avoid confusion:
Since agents see all tools at once, make descriptions specific:
Tools appear and disappear as you open/close tabs:
Agents can naturally compose tools from different tabs:

Managing Tool Overload

When many tabs are open, agents see many tools. Use context engineering patterns to help:
See Context Engineering Patterns for more strategies to limit tool availability based on application state.

Multi-Step Workflows

Stateful Multi-Step Operations

Cross-Site Tool Composition

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 Cross-Site Calls Work

Example: Cross-Site Tool Composition

Site A exposes cart data:
Site B offers price comparison:
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.

Example: Content Aggregation

Agents can fetch content from one site and post to another:
Agents can fetch stories from the news site and share them on social media.

Best Practices for Cross-Site Tools

Include the site domain or purpose in tool names to avoid collisions:
Make it easy for tools on other sites to consume your data:
Each tool should do one thing well, making them easier to compose:
Use clear descriptions and schemas so other sites know what to expect:

Security Considerations

When building tools that will be composed with other sites:
  • Never expose sensitive data in tool responses
  • Validate all inputs from external sources
  • Don’t trust data from other sites without validation
  • Be aware that AI may pass data between sites
  • Review security best practices for multi-site scenarios

Read-Only Context Tools

Exposing Application State

Security Best Practices

Always sanitize inputs, implement rate limiting, and validate permissions. See the Security Guide for comprehensive patterns including:
  • Input sanitization with DOMPurify
  • Rate limiting implementations
  • Permission checks and auth validation
  • Handling sensitive data securely

Next Steps

Package Documentation

Deep dive into package APIs

Examples

See complete working examples

Troubleshooting

Common issues and solutions

Discord Community

Get help from the community