Webmcp polyfill

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

Webmcp polyfill is an AI agent skill from the GitHub repository OrcaQubits/agentic-commerce-skills-plugins. Set up and use the MCP-B polyfill — vanilla JS and React packages that implement navigator.modelContext for browsers without native WebMCP. Use when developing for browsers that don't yet support WebMCP natively.

How to use this skill

Skill file

MCP-B Polyfill for WebMCP

Before writing code

Fetch live docs:

  1. Web-search site:github.com mcp-b README for the polyfill repository, packages, and API documentation
  2. Web-search site:npmjs.com mcp-b for the latest package names and versions
  3. Fetch the MCP-B GitHub README for installation, usage, and React hooks API
  4. Web-search mcp-b polyfill react hooks useMcpServer for React integration patterns
  5. Web-search mcp-b vanilla javascript navigator.modelContext for vanilla JS usage

Conceptual Architecture

What MCP-B Is

MCP-B (Model Context Protocol for Browser) is an open-source polyfill that implements the navigator.modelContext API for browsers without native WebMCP support. It allows developers to build and test WebMCP tools today, regardless of native browser support.

Why Use the Polyfill

Package Structure

MCP-B provides multiple packages (fetch the README for exact names, as they may change):

Feature Detection

Check for native WebMCP support and fall back to the polyfill:

if (!navigator.modelContext) {
  // Load MCP-B polyfill
  await import("mcp-b"); // or whatever the current package name is
}

// Now navigator.modelContext is available (native or polyfill)
navigator.modelContext.registerTool({ /* ... */ });

Vanilla JS Usage Pattern

// 1. Import polyfill (if needed)
import "mcp-b";

// 2. Register tools using the standard API
navigator.modelContext.registerTool({
  name: "searchProducts",
  description: "Search the catalog",
  inputSchema: { /* ... */ },
  async execute(input) { /* ... */ }
});

React Hooks Usage Pattern

import { useMcpServer } from "mcp-b/react"; // verify package name

function ProductPage() {
  useMcpServer({
    tools: [
      {
        name: "viewProduct",
        description: "View product details",
        inputSchema: { /* ... */ },
        execute: async (input) => { /* ... */ }
      }
    ]
  });

  return <div>Product Page</div>;
}

MCP-B Backend Translation

MCP-B can also translate between client-side WebMCP tools and backend MCP servers:

Polyfill vs Native

| Aspect | Native WebMCP | MCP-B Polyfill |

|--------|--------------|----------------|

| Browser support | Chrome 146+ Canary (flagged) | Any modern browser |

| Performance | Native speed | Slight JS overhead |

| Permission prompts | Browser-native UI | Custom/simulated |

| API surface | Full spec | May lag behind spec updates |

| Production readiness | Not yet (still in preview) | Usable today |

Progressive Enhancement Strategy

  1. Ship the polyfill for broad browser support
  2. Detect native WebMCP support at runtime
  3. Use native when available, polyfill as fallback
  4. Remove polyfill dependency once native support is widespread

Best Practices

Fetch the MCP-B README for exact installation commands, import paths, hook names, and API patterns before implementing.

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.