Skip to main content
This guide covers the complete tool development lifecycle: from naming and schema design, through implementation and error handling, to testing and monitoring. Unlike userscripts where you work around existing structures, controlling your entire website lets you design tools from the ground up for optimal AI integration.
These practices apply when you own the website and can integrate WebMCP tools directly into your codebase. For userscript development, see Managing Userscripts.

Tool Design Principles

Use Descriptive, Consistent Names

Follow a clear naming convention for all your tools:

Good Names

  • products_search
  • cart_add_item
  • user_get_profile
  • orders_list_recent

Avoid

  • doStuff
  • action1
  • helper
  • processData
Naming pattern: Use domain_verb_noun or verb_noun format:

Provide Detailed Descriptions

Tool names, descriptions, and input schemas are sent directly to the AI model’s context. This is the ONLY information the model has about your tools. Make these as detailed and informative as possible.
Help AI agents understand when and how to use your tools by including everything they need to know in the description:
Include in descriptions:
  • What the tool does and when to use it
  • What data it returns and in what format
  • When to use it vs similar tools
  • Any important limitations or constraints
  • Prerequisites or dependencies on other tools
  • If this tool will modify the available tool list

Design Powerful, Consolidated Tools

Create consolidated tools that handle related operations rather than many single-purpose tools:
Benefits of consolidated tools:
  • Reduces context consumption (fewer tool definitions)
  • Modern AI models handle complex tools effectively
  • Fewer tools to maintain and document
  • Simpler tool discovery for AI agents
  • More efficient use of available context window

Input Validation

Use Zod for Type-Safe Validation

Parameter descriptions (via .describe()) are sent to the AI model’s context. Be detailed and specific!
Zod provides excellent TypeScript integration and runtime validation. Use .describe() on every parameter to tell the model exactly what it needs to know:

Validate Business Logic Constraints

Go beyond type checking to enforce business rules:

Provide Helpful Error Messages

Response Format

Use Markdown Instead of JSON

AI models work better with markdown-formatted responses than JSON. Markdown is more readable and easier for models to incorporate into natural language responses.
Return data as markdown strings rather than JSON objects:
Benefits of markdown responses:
  • More natural for AI to read and present to users
  • Better formatting in chat interfaces
  • Easier for models to extract specific information
  • More human-readable in logs and debugging

Include Helpful Context in Responses

Provide information that helps the AI understand and present the results:

Use Specific Error Messages

Help AI agents understand what went wrong with clear, formatted error messages:

Security Best Practices

For comprehensive security guidance including authentication, authorization, input validation, prompt injection protection, and multi-website threat models, see the dedicated Security Guide.

Performance Optimization

For comprehensive performance guidelines including tool registration patterns, tool limits, lazy registration, timeouts, and memory management, see the Performance Guidelines.

Optimistic Updates for Voice Models

Voice models and real-time interactions work best with instant tool responses. Implement optimistic updates by operating on in-app state rather than waiting for async API calls:
Benefits of optimistic updates:
  • Instant tool responses for voice and real-time interactions
  • Better user experience with immediate feedback
  • Voice models can chain multiple operations smoothly
  • Reduced latency in multi-step workflows
Implementation tips:
  • Maintain local application state (Redux, Zustand, React Context)
  • Update state synchronously before returning from tool
  • Queue background sync operations
  • Handle sync failures gracefully with retry logic

Testing & Quality Assurance

Test Tool Registration

Verify tools are properly registered:

Test Tool Execution

Verify tool handlers work correctly:

Test with Real AI Agents

Use the MCP-B Extension to test with actual AI:
1

Install MCP-B Extension

Get it from the Chrome Web Store
2

Load your website

Navigate to your development site where tools are registered
3

Verify tool discovery

Open the extension and confirm your tools appear in the available tools list
4

Test with natural language

Ask the AI agent to use your tools: “Search for laptops under $1000”
5

Verify results

Check that the AI correctly interprets tool responses and presents them to the user

Tool Organization

Organize tools logically in your codebase:

Use Consistent Prefixes

Group tools by domain using name prefixes:
Remember: Tool descriptions go into the model’s context. Reference other tools by name to help the model understand workflows and dependencies.
Make it clear when tools should be called in sequence or when one tool depends on another:
When to reference other tools:
  • A tool should be called before this one
  • This tool’s execution will register/unregister other tools
  • Data from another tool is needed as input
  • Multiple tools work together in a common workflow

Framework Integration

React with Hooks

Use useWebMCP for component-scoped tools:

Vue with Composition API

Vanilla JavaScript

Documentation

Write for the Model, Not Developers

JSDoc comments and code documentation do NOT go into the model’s context. Only the tool name, description, and input schema are sent to the AI.
Put all important information in the tool description and parameter descriptions:

Create Tool Catalog for Developers

Maintain a reference document for your development team:

Use OpenAPI/JSON Schema

Export tool schemas for documentation:

Monitoring & Analytics

Log Tool Usage

Track which tools are being called:

Monitor Performance

Track tool execution time:

Version Management

Version Your Tools

Include version info in tool names or metadata:

Deprecate Gracefully

Warn when tools will be removed:

Quick Reference

  • Tool name, description, and input schema ONLY
  • JSDoc and code comments are NOT sent to the model
  • Use detailed descriptions and parameter .describe() methods
  • Reference other tools by name in descriptions
  • Mention if tool execution changes the tool list
  • Prefer consolidated tools over many single-purpose tools
  • Reduces context consumption
  • Use domain_verb_noun naming pattern
  • Be specific and descriptive in all metadata
  • Include what the tool does and when to use it
  • Describe return data format
  • List prerequisites and dependencies on other tools
  • Mention if this tool registers/unregisters other tools
  • Use parameter .describe() for detailed parameter info
  • Use optimistic updates - update local state first
  • Return instantly, sync to backend in background
  • Don’t block on async API calls
  • Maintain in-app state for fast operations
  • Return markdown strings instead of JSON objects
  • Markdown is more readable for AI models
  • Better for natural language presentation
  • Include helpful context and formatting
  • Prefer Zod schemas for TypeScript projects
  • Use .describe() on every parameter (goes to model)
  • Validate both types and business logic
  • Provide helpful error messages
  • Validate user authentication
  • Check authorization for protected resources
  • Sanitize all inputs
  • Rate limit tool calls
  • Never expose sensitive data
  • Unit test registration and execution
  • Test error handling
  • Test with real AI agents using MCP-B Extension

Additional Resources

Core Concepts

Learn about WebMCP architecture and design

Quick Start

Get started with your first tool

Security Guide

Security best practices and guidelines

API Reference

Complete API documentation

React Integration

Using WebMCP with React

Examples Repository

See real-world implementations