The Simple Way: registerTool()
For most use cases, use registerTool() to add tools one at a time:
registerTool() is the default:
- ✅ Works everywhere (React, Vue, vanilla JS)
- ✅ Automatic cleanup when unregistered
- ✅ Perfect for component-scoped tools
- ✅ Simple and intuitive
Advanced: provideContext() for base tools
Advanced: provideContext() for base tools
Only use When to use:
provideContext() when you need to set application-level base tools all at once:- Defining core application tools at startup
- Setting up a foundation tool set
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
Register once per lifecycle
Register once per lifecycle
Don’t repeatedly register and unregister tools. Register when the component/feature becomes available, unregister when it’s removed.
Limit total tools per page
Limit total tools per page
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
Clean up properly
Clean up properly
Always unregister tools when they’re no longer available:
Use descriptive names and descriptions
Use descriptive names and descriptions
Help AI agents understand when and how to use your tools:
Related Topics
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
