Skip to main content

The Simple Way: registerTool()

For most use cases, use registerTool() to add tools one at a time:
Why registerTool() is the default:
  • ✅ Works everywhere (React, Vue, vanilla JS)
  • ✅ Automatic cleanup when unregistered
  • ✅ Perfect for component-scoped tools
  • ✅ Simple and intuitive
Only use provideContext() when you need to set application-level base tools all at once:
When to use:
  • Defining core application tools at startup
  • Setting up a foundation tool set
Important: This replaces all base tools each time it’s called. For most use cases, stick with registerTool() instead.See Advanced Patterns for detailed guidance.

Tool Lifecycle

React Component Example

Vanilla JavaScript Example

Tool Definition Structure

A complete tool definition includes:

Registration Best Practices

Don’t repeatedly register and unregister tools. Register when the component/feature becomes available, unregister when it’s removed.
Avoid registering too many tools (>50) on a single page. This can overwhelm AI agents and slow down tool discovery.Consider:
  • Registering context-specific tools dynamically
  • Grouping related operations into single tools with parameters
  • Using tool annotations to guide AI selection
Always unregister tools when they’re no longer available:
Help AI agents understand when and how to use your tools:

Tool Schemas

Learn about input validation and schema definition

Tool Design Patterns

Best practices for designing effective tools

React WebMCP

React hooks for WebMCP tool registration

Performance

Performance considerations for tool registration