Documentation Index
Fetch the complete documentation index at: https://moengage.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This guide outlines how to integrate the MoEngage Web SDK into MCP UI applications.Key Capabilities
- Track user behavior in real-time.
- Trigger On-Site Messaging (OSM).
- Trigger Cards.
MCP UI applications executes custom widgets within a secure iframe sandbox. As a result, the execution URL differs from your primary domain, and standard URL-based campaigns are not supported.However, you can seamlessly deliver targeted experiences by configuring your campaigns to fire on Custom Events instead. All event-trigger based On-Site Messages (OSMs) and Cards remain fully supported for this integration.
MCP UI Applications Setup and Configuration
Implementation Steps
1. Install dependencies
Run the following command in your project directory:NPM
2. Configure CSP Domain Whitelisting
The MCP UI applications widget runs inside a strict internal iframe sandbox, standard CSP headers block the application by default. You must explicitly whitelist the CSP URL in your MCP server configuration. Ensure you whitelist both the MoEngage URLs (Base URLs, tracking endpoints, and OSM delivery URLs) and the sandbox URLs in yourconnect-src and script-src directives to prevent the browser from blocking requests.
Ensure that you whitelist the following endpoints for smooth integration.
script-src:
image-src:
- https://moe-email-campaigns.s3.amazonaws.com/
- https://image.moengage.com/
- https://image-eu.moengage.com/
- https://image-ap1.moengage.com/
- https://image-04.moengage.com/
- https://image-06.moengage.com/
- https://image.moengage.com/all-campaign-images-moe-dc-100/
- https://sdk-01.moengage.com/
- https://sdk-02.moengage.com/
- https://sdk-03.moengage.com/
- https://sdk-04.moengage.com/
- https://sdk-06.moengage.com/
Refused to connect to https://\*\*\*.moengage.com/\*\*\*\* because it violates the following Content Security Policy directive. If you do not whitelist the URLs.
3. Initialize the SDK and Inject Credentials
Initialize the SDK before your React component mounts. You will inject your MoEngage App ID and Data Center credentials into the widget HTML or environment variables. Create a custom wrapper hookuseMoEngage.js to cleanly manage initialization and expose SDK methods throughout your widget.
useMoEngage Hook
4. Handle Tool Results (handleToolResult)
ThehandleToolResult callback acts as the central event dispatcher. MoEngage SDK methods can be triggered in two ways:
- Direct UI Interaction: user clicks or interacts directly via UI elements.
- Chat Commands: user issues a prompt via the Model Context Protocol (MCP).
handleToolResult callback to catch incoming postMessage commands from the MCP server and route them to the appropriate MoEngage SDK wrapper functions.
handleToolResult
With your
useMoEngage hook and handleToolResult dispatcher in place, event tracking becomes a seamless part of your widget’s interactive flow.- Custom Events: When UI interactions occur (either via direct user clicks in the iframe or via MCP UI applications prompts processed by the MCP), call your trackEvent function.
- The integration is designed so that both manual UI interactions (such as clicking an “Add to Cart” button) and Chat commands (via MCP) ultimately execute the same underlying JavaScript functions. The chat interface does not track events directly; it uses MCP to call the widget, which then fires the standard tracking events.