WebMCP Integration in TypeScript DOCX Editor

5 Nov 202617 minutes to read

Integration

WebMCP integrates seamlessly into your TypeScript 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: Inject the WebMCP Module

Import and inject the WebMcpToolExecuteEventArgs module into your DOCX Editor:

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

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

Step 3: Enable WebMCP

Set the enableWebMcp property to true in your DocumentEditorContainer configuration:

let container: DocumentEditorContainer = new DocumentEditorContainer({
    height: '590px',
    enableWebMcp: true,
    toolbarMode: 'Ribbon'
});

Step 4: Register Tools

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

// Initialize DocumentEditorContainer with WebMCP enabled
let webMcpSettings: any = {
        name: 'container'
    };
let container: DocumentEditorContainer = new DocumentEditorContainer({
    height: '590px',
    enableWebMcp: true,
    webMcpSettings: webMcpSettings,
    toolbarMode: 'Ribbon'
});

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 DOCX Editor with WebMCP enabled and register tools on creation.

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

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

// Initialize DocumentEditorContainer with WebMCP enabled
let webMcpSettings: any = {
        name: 'container'
    };

let container: DocumentEditorContainer = new DocumentEditorContainer({
    height: '590px',
    enableWebMcp: true,
    webMcpSettings: webMcpSettings, // Enable WebMCP tools
    toolbarMode: 'Ribbon'
});

// Use the following service URL only for demo purposes
container.serviceUrl = 'https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/';

// Append to container element
container.appendTo('#container');

// Update document title
document.title = 'WebMCP Tool Demo - DocumentEditorContainer';

View Sample in GitHub.

Selective Tool Registration

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

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

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

// Initialize DocumentEditorContainer with WebMCP enabled
let webMcpSettings: any = {
    name: 'container',
    tools: ['getDocumentBookmarks', 'getSelectionText', 'find', 'findAll', 'goToPage'] // Register only the needed tools
};

let container: DocumentEditorContainer = new DocumentEditorContainer({
    height: '590px',
    enableWebMcp: true,
    webMcpSettings: webMcpSettings, // Enable WebMCP tools
    toolbarMode: 'Ribbon'
});

// Use the following service URL only for demo purposes
container.serviceUrl = 'https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/';

// Append to container element
container.appendTo('#container');

View Sample in GitHub.

Multi-Instance Setup

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

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

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

// Use the following service URL only for demo purposes
const serviceUrl = 'https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/';

const container1: DocumentEditorContainer = new DocumentEditorContainer({
    height: '590px',
    width: '50%',
    enableWebMcp: true,
    toolbarMode: 'Ribbon',
    webMcpSettings: { name: 'documentEditor1' }
});
container1.serviceUrl = serviceUrl;
container1.appendTo('#container1');

const container2: DocumentEditorContainer = new DocumentEditorContainer({
    height: '590px',
    width: '50%',
    enableWebMcp: true,
    toolbarMode: 'Ribbon',
    webMcpSettings: { name: 'documentEditor2' }
});
container2.serviceUrl = serviceUrl;
container2.appendTo('#container2');

View Sample in GitHub.

Auditing and Restrictions

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

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

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

let container: DocumentEditorContainer = new DocumentEditorContainer({
    height: '590px',
    enableWebMcp: true,
    toolbarMode: 'Ribbon',
    webMcpSettings: { name: 'container' },
    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.';
        }
    }
});

// Use the following service URL only for demo purposes
container.serviceUrl = 'https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/';

// Append to container element
container.appendTo('#container');

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 webMcpSettings: {name:'container'} is added 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