Webmcp dev patterns

From OrcaQubits/agentic-commerce-skills-plugins · View interactive version

Webmcp dev patterns is an AI agent skill from the GitHub repository OrcaQubits/agentic-commerce-skills-plugins. Apply WebMCP cross-cutting development patterns — SPA routing, error handling, performance optimization, multi-site agents, accessibility, SEO, and production deployment. Use when architecting WebMCP-enabled sites or solving cross-cutting concerns.

How to use this skill

Skill file

WebMCP Development Patterns

Before writing code

Fetch live docs:

  1. Fetch https://developer.chrome.com/docs/ai/webmcp for the latest developer guidance and patterns
  2. Web-search webmcp development best practices patterns for community patterns
  3. Web-search webmcp SPA single page application routing for SPA-specific patterns
  4. Web-search webmcp SEO agent discovery for discoverability patterns

Conceptual Architecture

SPA Tool Lifecycle

In single-page applications, tools must be managed across route changes:

// React example: register/unregister tools on route change
useEffect(() => {
  const tools = getToolsForRoute(currentRoute);
  tools.forEach(tool => navigator.modelContext.registerTool(tool));

  return () => {
    // Cleanup on route change
    tools.forEach(tool => navigator.modelContext.unregisterTool(tool.name));
  };
}, [currentRoute]);

Key principles:

Error Handling

Tools should handle errors at multiple levels:

Network errors:

async execute(input) {
  try {
    const res = await fetch(`/api/products?q=${input.query}`);
    if (!res.ok) {
      return { status: "error", code: res.status, message: "Server error" };
    }
    return await res.json();
  } catch (err) {
    return { status: "error", code: "network_error", message: "Unable to reach server" };
  }
}

Business logic errors:

async execute(input) {
  const product = await fetchProduct(input.productId);
  if (!product) {
    return { status: "error", code: "not_found", message: "Product not found" };
  }
  if (!product.inStock) {
    return { status: "error", code: "out_of_stock", message: "Product is out of stock" };
  }
  // proceed...
}

Consistent error format:

{ status: "error", code: "error_code", message: "Human-readable message" }

Performance Optimization

WebMCP tools are inherently faster than UI scraping, but optimize further:

Multi-Site Agent Patterns

Agents may navigate across multiple sites, each with WebMCP:

Agent Journey:
1. Open site-a.com → discovers tools [searchA, addToCartA, checkoutA]
2. Call searchA("wireless headphones") → get results
3. Open site-b.com → discovers tools [searchB, addToCartB, checkoutB]
4. Call searchB("wireless headphones") → get results
5. Agent compares results and recommends best option to user
6. User picks site-a → agent calls addToCartA and checkoutA

Design implications:

Accessibility

WebMCP tools should support accessible interactions:

SEO and AI Discovery

WebMCP enhances AI discoverability:

Versioning

As tools evolve:

Production Deployment Checklist

Monitoring and Observability

Track agent interactions in production:

Commerce Platform Integration

Commerce platforms will likely add built-in WebMCP support:

Monitor your platform's announcements for native WebMCP support.

Best Practices Summary

Fetch the latest community patterns, Chrome DevTools features, and platform integration announcements before architecting.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.