Skip to main content
Follow these performance guidelines to ensure your WebMCP tools are fast and efficient.

Tool Registration

Register Once Per Lifecycle

Don’t repeatedly register and unregister tools:

Limit Total Tools

Avoid registering too many tools per page:
  • Good: 5-20 tools per page
  • ⚠️ Acceptable: 20-50 tools per page
  • Too many: >50 tools per page
Why? Too many tools overwhelm AI agents and slow down tool discovery. Solutions:
  • Register tools dynamically based on page context
  • Group related operations into single tools with parameters
  • Use conditional registration based on user state

Lazy Registration

Register tools only when features become available:

Tool Execution

Use Async/Await Properly

Always use async/await for asynchronous operations:

Avoid Blocking Operations

Don’t block the main thread with heavy computations:

Implement Timeouts

Prevent tools from hanging indefinitely:

Show Progress for Long Operations

Provide feedback for operations that take time:

Transport Performance

Minimize Payload Size

Keep tool registration payloads small:

Batch Updates

If registering multiple tools, do it in a batch:

Memory Management

Clean Up Properly

Always unregister tools when they’re no longer needed:

Avoid Memory Leaks in Handlers

Be careful with closures in tool handlers:

Monitoring Performance

Measure Tool Execution Time

Track how long tools take to execute:

Performance Budget

Set performance targets for your tools:
  • Instant: <100ms - Data reads, simple computations
  • Fast: 100-500ms - API calls, database queries
  • ⚠️ Acceptable: 500ms-2s - Complex operations, file processing
  • Too slow: >2s - Consider breaking into smaller steps or showing progress

Caching

Cache Expensive Operations

Tool Registration

Best practices for registering tools

Tool Design

Designing efficient tools

Best Practices

General WebMCP best practices

Architecture

Understanding system architecture