UStackUStack
WebMCP favicon

WebMCP

WebMCP is an open-source JavaScript library enabling websites to integrate with the Model Context Protocol (MCP) via an interactive LLM widget.

What is WebMCP?

WebMCP: Integrating LLM Interaction Directly into Your Website

What is WebMCP?

WebMCP is an innovative, open-source JavaScript library designed to bridge the gap between traditional web applications and advanced Large Language Models (LLMs) or AI agents via the Model Context Protocol (MCP). By simply including a script tag, developers can embed a small, non-intrusive blue widget in the bottom right corner of their webpage. This widget serves as the gateway for end-users to connect their configured MCP client (like Claude Desktop) directly to the live context of the website, allowing for sophisticated, context-aware interactions.

The core value proposition of WebMCP lies in empowering LLMs to perform actions, access specific page data, and engage in structured conversations based on the real-time state of the webpage. This transforms static content consumption into dynamic, agent-assisted experiences, all while maintaining user control over the connection via client-side token authentication. It is the essential tool for developers looking to infuse their web properties with next-generation AI capabilities.

Key Features

WebMCP provides a robust API for deep integration with MCP clients, offering several powerful capabilities:

  • LLM Tool Registration: Developers can register custom JavaScript functions as callable tools. The LLM client can then invoke these tools (e.g., weather, calculate) by passing structured arguments, allowing agents to execute actions directly on the site's behalf.
  • Predefined Prompt Templates: Standardize common user interactions by registering prompts. These templates allow clients to initiate complex queries (like generating Git commit messages or summarizing text) with predefined structures and dynamic arguments.
  • Contextual Resource Exposure: Expose dynamic or static website data as readable resources identified by URIs. This allows LLMs to access current page HTML (page://current) or content from specific DOM elements (e.g., element://my-id) as context for their responses.
  • Secure Sampling Mechanism: Implement server-initiated interactions where the LLM requests a completion based on a system prompt and context. WebMCP handles the security by presenting a modal dialog to the user, requiring explicit input before sending the response back to the originating server, ensuring privacy and oversight.
  • Customizable Widget Appearance: The embedded widget is highly configurable, allowing developers to adjust its color, position (bottom-right, top-right, etc.), size, and padding to seamlessly match their website's design aesthetic.

How to Use WebMCP

Integrating WebMCP into a website is straightforward for developers, while user interaction relies on a pre-configured MCP client.

For Website Developers (Integration):

  1. Include the Script: Add the following line to your HTML, typically before the closing </body> tag: <script src="webmcp.js"></script>
  2. Initialization & Configuration: Optionally, initialize the library with custom settings (color, position) immediately after including the script.
  3. Register Functionality: Use mcp.registerTool(), mcp.registerPrompt(), and mcp.registerResource() to expose your site's capabilities and data to connected LLMs.

For End Users (Connection):

  1. Configure Client: Ensure the user has an MCP client (e.g., Claude Desktop) configured to connect to the WebMCP server endpoint (using the provided npx command).
  2. Generate Token: The user starts their MCP client and requests a webmcp token.
  3. Connect: The user clicks the blue WebMCP widget on the website and pastes the generated token into the connection prompt.

Use Cases

WebMCP unlocks powerful AI integration across various web contexts:

  1. E-commerce Product Support: An LLM agent, connected via WebMCP, can access the page-content resource to read product descriptions and specifications. A user can then ask, "Based on this page, is this laptop suitable for video editing?" The agent uses the context to provide an accurate, immediate answer without leaving the product page.
  2. Interactive Documentation & Tutorials: For complex software documentation sites, tools can be registered to execute code snippets or run simulations. A user can ask the agent to "Explain the function of the highlighted code block" (by registering a resource for the selected element ID), and the agent provides an explanation based on the live DOM content.
  3. Data Entry & Form Assistance: In internal web applications or complex forms, prompts can be registered to standardize data entry. For example, a prompt could be registered to "Generate a standardized compliance summary" based on data fields the agent can read via registered resources.
  4. Agentic Workflow Automation: By registering tools that interact with backend APIs (if exposed securely through the client), an agent could potentially initiate complex, multi-step workflows—such as "Draft an email summarizing today's sales figures"—where the LLM uses context resources to gather the necessary data before executing the final tool call.

FAQ

Q: Is WebMCP free to use? A: Yes, WebMCP is explicitly mentioned as an open-source JavaScript library, meaning the core integration code is freely available for use and modification.

Q: What is the Model Context Protocol (MCP) and why is it necessary? A: MCP is the underlying communication standard that WebMCP implements. It defines how a website (the server) communicates context, tools, and requests to an external LLM client securely, ensuring that the interaction is standardized across different client applications.

Q: Do I need to restart my MCP client every time I register a new tool? A: It is highly recommended to restart the MCP client after registering new tools or resources, especially during initial setup or development, as some clients may not dynamically update their available toolset immediately upon a token connection.

Q: Can the LLM access sensitive user data without my permission? A: No. The interaction is governed by the MCP client. While resources can expose page content, the critical step is the user connecting via a token. Furthermore, sensitive actions requiring external execution are handled via the Sampling mechanism, which explicitly requires the user to provide input via a modal dialog, maintaining human oversight.

Q: Can I change the look of the blue widget? A: Absolutely. The library allows for customization of the widget's appearance, including its color, position (e.g., 'top-right'), size, and padding during the initialization phase of the WebMCP object.

WebMCP | UStack