AI agent interacting with a website through structured tools and prompts

WebMCP: Turning Websites into AI-Ready Interfaces

Sascha Kiefer

Traditional AI agents struggle with websites. They click around like bots, parse constantly changing HTML, or rely on slow screenshot-based automation. This creates brittle integrations that break with every UI update and perform poorly at scale.

WebMCP takes a fundamentally different approach: instead of fighting the web interface, it lets websites expose structured capabilities directly to AI agents through the Model Context Protocol (MCP).

What is WebMCP?

WebMCP is an open-source JavaScript library that allows any website to expose structured tools, prompts, and resources to Large Language Models and AI agents. It adds a small, unobtrusive widget (typically in the bottom-right corner) that users can connect to via their MCP client - whether that's a browser extension, Claude Desktop, or another agent interface.

Once connected, an AI agent can:

  • Call tools: Execute JavaScript functions you define to perform actions on your site
  • Use prompts: Access predefined prompt templates for consistent interactions
  • Read resources: Retrieve page content or specific DOM elements as context

This transforms your website into something like a client-side MCP server, where frontend code directly provides capabilities to agents - while keeping authentication, state, and user control in the same interface.

Why This Matters

The problems with traditional web automation are well-documented:

ApproachIssues
Screen scrapingBreaks with UI changes, requires constant maintenance
DOM parsingFragile selectors, different across browsers and themes
Screenshot automationSlow, expensive, prone to misinterpretation
Headless browsersResource-intensive, often blocked by sites

WebMCP solves these by inverting the relationship. Instead of agents trying to understand your UI, you tell them exactly what they can do:

  • Reliability: Agents call structured functions instead of guessing UI elements
  • Performance: Direct JavaScript execution is faster and cheaper than backend roundtrips
  • Developer control: You decide exactly what the agent can do - no unintended actions
  • Future-proof: As MCP adoption grows and browsers add native support (e.g., navigator.modelContext), sites using WebMCP will be instantly "agent-ready"

Getting Started

Integration requires just one script tag:

<script src="https://webmcp.dev/webmcp.min.js"></script>

The widget appears automatically. Now you can register capabilities.

Registering Tools

Tools are JavaScript functions that agents can call. Each tool has a name, description, parameter schema, and handler:

mcp.registerTool(
  'searchProducts',
  'Search the product catalog by query',
  {
    query: { type: "string", description: "Search term" },
    category: { type: "string", description: "Product category (optional)" }
  },
  async (args) => {
    const results = await searchAPI(args.query, args.category);
    return {
      content: [{
        type: "text",
        text: JSON.stringify(results, null, 2)
      }]
    };
  }
);

The parameter schema follows JSON Schema conventions, making it easy for agents to understand what inputs are valid.

Registering Prompts

Prompts provide guided interactions for common tasks:

mcp.registerPrompt(
  'summarize-page',
  'Generate a summary of the current page content',
  [],
  () => ({
    messages: [{
      role: "user",
      content: {
        type: "text",
        text: `Please summarize the following page content:\n\n${document.body.innerText.slice(0, 5000)}`
      }
    }]
  })
);

Exposing Resources

Resources let agents access page content or specific elements:

// Expose current page content
mcp.registerResource(
  'page://current',
  'Current page content',
  'text/plain',
  () => document.body.innerText
);

// Expose a specific element
mcp.registerResource(
  'element://shopping-cart',
  'Current shopping cart contents',
  'application/json',
  () => JSON.stringify(getCartContents())
);

Customizing the Widget

The widget appearance is configurable:

mcp.configure({
  position: 'bottom-right',  // or 'bottom-left', 'top-right', 'top-left'
  color: '#0066cc',          // match your brand
  size: 'medium'             // 'small', 'medium', 'large'
});

Use Cases

WebMCP is particularly valuable for:

SaaS Applications: Let agents help users navigate complex workflows, fill forms, or extract reports without building custom integrations for every AI tool.

E-Commerce: Enable agents to search products, compare options, add items to cart, or track orders - all through structured APIs rather than brittle scraping.

Documentation Sites: Expose search and navigation tools so agents can find relevant docs and provide accurate answers based on your actual content.

Dashboards and Analytics: Let agents query data, generate reports, or explain metrics using your existing frontend logic.

Internal Tools: Give AI assistants structured access to company tools, maintaining security through your existing auth while enabling automation.

Human-in-the-Loop Design

One of WebMCP's strengths is that users and agents share the same interface. The user sees what the agent is doing, can intervene at any point, and maintains control over sensitive actions.

This is fundamentally different from headless automation, where agents operate invisibly in the background. With WebMCP:

  • Users can approve or deny tool executions
  • Actions happen visibly in the browser
  • Authentication flows through the user's existing session
  • Sensitive operations can require explicit confirmation

Browser Native Support

WebMCP aligns with emerging browser standards. Chrome already has early preview support, and the specification is being developed within the W3C Web Machine Learning Community Group.

The proposed navigator.modelContext API would provide native browser support for MCP, meaning sites using WebMCP today will be compatible with future browser-native implementations:

// Future browser-native API (in development)
if (navigator.modelContext) {
  // Use native implementation
} else {
  // Fall back to WebMCP library
}

Security Considerations

When exposing tools to AI agents, security requires careful thought:

  • Principle of least privilege: Only expose what agents actually need
  • Input validation: Validate all tool parameters before execution
  • Rate limiting: Prevent abuse through excessive calls
  • Audit logging: Track what agents do for debugging and compliance
  • Sensitive operations: Require explicit user confirmation for destructive actions

WebMCP provides hooks for implementing these patterns, but the security design is your responsibility.

Comparison with Other Approaches

FeatureWebMCPHeadless BrowsersScreen ScrapingCustom APIs
Setup complexityLow (one script)HighMediumHigh
MaintenanceLowHighVery HighMedium
PerformanceFastSlowMediumFast
User visibilityYesNoNoNo
Works with any AIYes (MCP standard)Tool-specificTool-specificCustom integration
Auth handlingUser's sessionComplexComplexCustom

Getting Started Today

  1. Visit webmcp.dev for the official library, examples, and documentation
  2. Add the script to your HTML
  3. Register your first tool, prompt, or resource
  4. Test with an MCP client - generate a token, paste it into the widget, and watch your AI interact natively

The project is open source on GitHub, and the evolving specification can be found in the related W3C incubation repositories.

Conclusion

WebMCP represents a significant step toward an agentic web - where AI doesn't fight the UI but collaborates through it. By exposing structured capabilities instead of forcing agents to reverse-engineer interfaces, websites become first-class citizens in the AI ecosystem.

For teams building AI-integrated products or looking to make their existing sites more accessible to agents, WebMCP offers a straightforward path forward that aligns with emerging standards.


Resources

Need Support?

Want to make your web applications AI-ready with WebMCP or integrate MCP into your existing infrastructure? We are happy to help. Contact us and let's discuss how we can bring intelligent agent capabilities to your products.

Never miss an article

No spam. Only relevant news about and from us. Unsubscribe anytime.