WebMCP Integration in React DOCX Editor

11 Nov 202622 minutes to read

Integration

WebMCP integrates seamlessly into your React DOCX Editor (Document Editor) application with minimal configuration.

Prerequisites

Ensure the following before integrating WebMCP:

  • Syncfusion DOCX Editor component is installed and configured Getting Started
  • A Chromium-based browser with the WebMCP origin trial or chrome://flags/#enable-webmcp enabled. The API is experimental, so confirm it in the browser versions you support.

Getting Started

Step 1: Configure Your Browser

Before you can use WebMCP locally, enable the feature flag and install the browser extension:

  1. Enable WebMCP Flag
    • Enable WebMCP for testing via chrome://flags/
    • Click “Relaunch” to restart Chrome
  2. Install WebMCP Extension
    • Search for “WebMCP - Model Context Tool Inspector” in Chrome Web Store
    • Click “Add to Chrome”
    • Pin the extension icon to your toolbar
  3. Configure Gemini API Key
    • Visit Google AI Studio to create or copy an API key
    • Open the WebMCP extension → paste your API key
    • Extension is now ready to use

Step 2: Import and Inject the Modules

Import and inject the needed modules into your DOCX Editor:

import { DocumentEditorContainer, Toolbar, Ribbon } from '@syncfusion/ej2-react-documenteditor';

// Inject required modules
DocumentEditorContainer.Inject(Toolbar, Ribbon);

Step 3: Enable WebMCP

Set the enableWebMcp property to true in your DocumentEditorContainer configuration:

<DocumentEditorContainerComponent
          id="container"
          ref={(scope) => { container = scope; }}
          // Use the following service URL only for demo purposes
          serviceUrl="https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/"
          height="100%"
          enableToolbar={true}
          toolbarMode="Ribbon"
          enableWebMcp={true}
        >
        </DocumentEditorContainerComponent>

Step 4: Register Tools

Set the webMcpSettings property to register the available tools in the control level:

<DocumentEditorContainerComponent
          id="container"
          ref={(scope) => { container = scope; }}
          // Use the following service URL only for demo purposes
          serviceUrl="https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/"
          height="100%"
          enableToolbar={true}
          toolbarMode="Ribbon"
          enableWebMcp={true}
          webMcpSettings=
        >
</DocumentEditorContainerComponent>

Step 5: Test Your Setup

Test with Your Local Setup

  • Run the application locally and open it in a Chromium-based browser.
  • Launch the WebMCP extension and confirm that it connects to your application successfully.
  • Verify that the registered tools are displayed with your chosen prefix.
  • Try a sample prompt that matches your data scenario to validate tool execution and response behavior.

View Sample in GitHub.

Sample Prompts
Here are realistic natural language prompts you can test with the WebMCP extension:

Document Information

Summarize the current document and report the total page count and word count

Search and Replace

Find every occurrence of “Syncfusion” and replace it with “Syncfusion Inc.”

Tool Reference

WebMCP tools are organized by category. The tables below provide an overview of all available tools. For complete input/output schemas, call getWebMcpTools() programmatically.

Document Information Tools

Tool Name Type Condition Description
getDocumentBookmarks Read Always Returns all bookmark names available in the current document.
pageCount Read Always Returns the total number of pages in the document.
getSelectionText Read Always Retrieves the plain text content of the current selection.
getSelectionSfdt Read Always Retrieves the selected content as formatted SFDT.

Search & Navigation Tools

Tool Name Type Condition Description
find Read Always Finds the next occurrence of specified text in the document.
findAll Read Always Finds all occurrences of specified text throughout the document.
selectBookmark Write Always Navigates to and selects an existing bookmark.
goToPage Write Always Navigates to a specified page in the document.
select Write Always Selects content between specified document positions or coordinates.
selectAll Write Always Selects all content in the document.
selectCurrentWord Write Always Selects the word at the current cursor position.
selectParagraph Write Always Selects the current paragraph.

Content Editing Tools

Tool Name Type Condition Description
insertText Write Always Inserts plain text at the current cursor or selection position.
paste Write Always Pastes formatted SFDT content while preserving document structure and formatting.
replaceAll Write Always Replaces all occurrences of specified text with new content.
insertBookmark Write Always Creates a bookmark at the current cursor position for navigation.
insertField Write Always Inserts dynamic fields such as merge fields, or page numbers.
insertImage Write Always Inserts an image with optional sizing and alternate text.
insertHyperlink Write Always Inserts a hyperlink with optional display text and screen tip.

Formatting Tools

Tool Name Type Condition Description
formatCharacter Write Always Applies character formatting such as font, size, color, bold, italic, and highlighting.
formatParagraph Write Always Applies paragraph formatting such as alignment, indentation, and spacing.

Protection & Permissions Tools

Tool Name Type Condition Description
enforceProtection Write Always Protects the document and restricts editing with a password.
stopProtection Write Always Removes document protection and restores editing access.
insertEditingRegion Write Always Creates an editable region for specific users in a protected document.

Document Management Tools

Tool Name Type Condition Description
saveDocument Write Always Saves or exports the current document in DOCX, DOTX, TXT, or SFDT format.
configureDocumentEditorSettings Write Always Configures editor appearance and behavior settings such as ruler, bookmarks, navigation pane, and fonts.
print Write Always Opens the print dialog for the current document.

Code Examples

Basic Setup

Set up a DocumentEditorContainer with WebMCP enabled and register tools on creation.

import { createRoot } from 'react-dom/client';
import * as React from 'react';
import { DocumentEditorContainerComponent, Ribbon } from '@syncfusion/ej2-react-documenteditor';
import './index.css';
DocumentEditorContainerComponent.Inject(Ribbon);

// tslint:disable:max-line-length
const WebMCPApp = () => {
  let webMcpSettings = {
    name: 'container'
  };
  let container;

  React.useEffect(() => {
    if(container){
        container.documentEditor.documentName = 'WebMCP Tool Demo';
    }
    document.title = 'WebMCP Tool Demo - DocumentEditorContainer'; 
  }, []);

  return (
     <div style=>
        <DocumentEditorContainerComponent
          id="container"
          ref={(scope) => { container = scope; }}
          // Use the following service URL only for demo purposes
          serviceUrl="https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/"
          height="100%"
          enableToolbar={true}
          toolbarMode="Ribbon"
          enableWebMcp={true}
          webMcpSettings={webMcpSettings}
        >
        </DocumentEditorContainerComponent>      
    </div>
  );
};
export default WebMCPApp;
createRoot(document.getElementById('sample')).render(<WebMCPApp />);

View Sample in GitHub.

Selective Tool Registration

Register only the essential tools required for the application to minimize system exposure and enhance security.

import { createRoot } from 'react-dom/client';
import * as React from 'react';
import { DocumentEditorContainerComponent, Ribbon } from '@syncfusion/ej2-react-documenteditor';
import './index.css';
DocumentEditorContainerComponent.Inject(Ribbon);

const WebMCPApp = () => {
  let webMcpSettings = {
    name: 'container',
    tools: ['getDocumentBookmarks', 'getSelectionText', 'find', 'findAll', 'goToPage'] // Register only the needed tools
  };
  let container;

  return (
     <div style=>
        <DocumentEditorContainerComponent
          id="container"
          ref={(scope) => { container = scope; }}
          // Use the following service URL only for demo purposes
          serviceUrl="https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/"
          height="100%"
          enableToolbar={true}
          toolbarMode="Ribbon"
          enableWebMcp={true}
          webMcpSettings={webMcpSettings}
        >
        </DocumentEditorContainerComponent>
    </div>
  );
};
export default WebMCPApp;
createRoot(document.getElementById('sample')).render(<WebMCPApp />);

View Sample in GitHub.

Multi-Instance Setup

Shows how to use different prefixes for multiple DOCX Editor instances on the same page.

import { createRoot } from 'react-dom/client';
import * as React from 'react';
import { DocumentEditorContainerComponent, Ribbon } from '@syncfusion/ej2-react-documenteditor';
import './index.css';
DocumentEditorContainerComponent.Inject(Ribbon);

const WebMCPApp = () => {
  const webMcpSettings1 = {
    name: 'documentEditor1'
  };
  const webMcpSettings2 = {
    name: 'documentEditor2'
  };

  return (
    <div style=>
      <DocumentEditorContainerComponent
        id="container1"
        // Use the following service URL only for demo purposes
        serviceUrl="https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/"
        width="50%"
        height="590px"
        enableToolbar={true}
        toolbarMode="Ribbon"
        enableWebMcp={true}
        webMcpSettings={webMcpSettings1}
      >
      </DocumentEditorContainerComponent>

      <DocumentEditorContainerComponent
        id="container2"
        // Use the following service URL only for demo purposes
        serviceUrl="https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/"
        width="50%"
        height="590px"
        enableToolbar={true}
        toolbarMode="Ribbon"
        enableWebMcp={true}
        webMcpSettings={webMcpSettings2}
      >
      </DocumentEditorContainerComponent>
    </div>
  );
};
export default WebMCPApp;
createRoot(document.getElementById('sample')).render(<WebMCPApp />);

View Sample in GitHub.

Auditing and Restrictions

Demonstrates the use of the beforeWebMcpToolExecute event to log tool activity and block restricted operations.

import { createRoot } from 'react-dom/client';
import * as React from 'react';
import { DocumentEditorContainerComponent, Ribbon } from '@syncfusion/ej2-react-documenteditor';
import './index.css';
DocumentEditorContainerComponent.Inject(Ribbon);

const WebMCPApp = () => {
  let webMcpSettings = {
    name: 'container'
  };

  const beforeWebMcpToolExecute = (args: any) => {
    const { toolName, toolArgs } = args;

    // Audit all WebMCP tool invocations
    console.log(`[WebMCP] Executing: ${toolName}`, toolArgs);

    const commandName = toolName?.includes('_')
      ? toolName.substring(toolName.indexOf('_') + 1)
      : toolName;

    // Restrict a specific tool
    if (commandName === 'saveDocument') {
      args.cancel = true;
      args.cancellationResponse = 'The saveDocument operation has been restricted.';
    }
  };

  return (
     <div style=>
        <DocumentEditorContainerComponent
          id="container"
          // Use the following service URL only for demo purposes
          serviceUrl="https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/"
          height="100%"
          enableToolbar={true}
          toolbarMode="Ribbon"
          enableWebMcp={true}
          webMcpSettings={webMcpSettings}
          beforeWebMcpToolExecute={beforeWebMcpToolExecute}
        >
        </DocumentEditorContainerComponent>
    </div>
  );
};
export default WebMCPApp;
createRoot(document.getElementById('sample')).render(<WebMCPApp />);

View Sample in GitHub.

Troubleshooting FAQs

What are the common causes of “WebMCP Not Available” or an “modelContext is Undefined” errors?

  1. Verify WebMCP flag is enabled:
    • Open chrome://flags/#enable-webmcp-testing
    • Confirm it shows “Enabled”
    • Fully restart Chrome (not just reload the page)
  2. Check your Chrome version is up-to-date (WebMCP requires recent Chromium)
  3. Ensure you’re testing on a secure context (HTTPS or localhost)

Why aren’t my registered tools displayed in the extension?

  1. Verify enableWebMcp: true in your DocumentEditorContainer config
  2. Confirm public webMcpSettings: ; is bind to register the available tools
  3. Open DevTools (F12) → Console, check for errors
  4. Try refreshing the page and opening the extension again
  5. Verify the tool prefix is correct (check console logs)

Why don’t registered tools execute?

  1. Check your Gemini API key is valid:
    • Visit Google AI Studio
    • Create a new key if needed
    • Re-enter it in the WebMCP extension
  2. Verify the extension has permission to access the site:
    • Right-click WebMCP extension → Manage extension
    • Ensure “Allow on this site” is enabled

Why do I get a “Permission denied” or “Secure context required” error?

  1. WebMCP requires HTTPS in production or localhost for development
  2. If using cross-origin tools, both sites must be HTTPS
  3. Test locally using localhost:3000 or similar

See Also