WebMCP Integration in Angular DOCX Editor

5 Nov 202620 minutes to read

Integration

WebMCP integrates seamlessly into your Angular 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 { 
    DocumentEditorContainerModule, 
    DocumentEditorContainerComponent, 
    ToolbarService, 
    RibbonService 
} from '@syncfusion/ej2-angular-documenteditor';

Step 3: Enable WebMCP

Set the enableWebMcp property to true in your DocumentEditorContainer configuration:

template: `
<!-- Use the following service URL only for demo purposes -->
<ejs-documenteditorcontainer        
        #document_editor
        id="container"
        serviceUrl="https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/"
        height="590px"
        style="width:100%;display:block"
        [enableToolbar]="true"
        [toolbarMode]="'Ribbon'" 
        [enableWebMcp]="true">
    </ejs-documenteditorcontainer>
`

Step 4: Register Tools

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

template: `
<!-- Use the following service URL only for demo purposes -->
<ejs-documenteditorcontainer        
        #document_editor
        id="container"
        serviceUrl="https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/"
        height="590px"
        style="width:100%;display:block"
        [enableToolbar]="true"
        [toolbarMode]="'Ribbon'" 
        [enableWebMcp]="true"
        [webMcpSettings]="webMcpSettings">
    </ejs-documenteditorcontainer>
`
...
...
public webMcpSettings: any = { name: 'container' };

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 { Component } from '@angular/core';
import {
    DocumentEditorContainerModule,
    ToolbarService,
    RibbonService
} from '@syncfusion/ej2-angular-documenteditor';

@Component({
    selector: 'app-root',
    standalone: true,
    imports: [DocumentEditorContainerModule],
    template: `
    <!-- Use the following service URL only for demo purposes -->
    <ejs-documenteditorcontainer
        serviceUrl="https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/"
        height="590px"
        style="width:100%;display:block"
        [enableToolbar]="true"
        [toolbarMode]="'Ribbon'" 
        [enableWebMcp]="true"
        [webMcpSettings]="webMcpSettings">
    </ejs-documenteditorcontainer>
`,
    providers: [ToolbarService, RibbonService]
})
export class App {
    public webMcpSettings: any = {
        name: 'container'
    };
}

View Sample in GitHub.

Selective Tool Registration

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

import { Component, ViewChild } from '@angular/core';
import {
    DocumentEditorContainerModule,
    ToolbarService,
    RibbonService,
} from '@syncfusion/ej2-angular-documenteditor';

@Component({
    selector: 'app-root',
    standalone: true,
    imports: [DocumentEditorContainerModule],
    template: `
    <!-- Use the following service URL only for demo purposes -->
    <ejs-documenteditorcontainer        
        #document_editor
        id="container"
        serviceUrl="https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/"
        height="590px"
        style="width:100%;display:block"
        [enableToolbar]="true"
        [toolbarMode]="'Ribbon'" 
        [enableWebMcp]="true"
        [webMcpSettings]="webMcpSettings">
    </ejs-documenteditorcontainer>
`,
    providers: [ToolbarService, RibbonService]
})
export class App { @ViewChild('document_editor')
    public webMcpSettings: any = {
        name: 'container',
        tools: [ 'getDocumentBookmarks', 'getSelectionText', 'find', 'findAll', 'goToPage' ] //Register only with needed tools
    };
}

View Sample in GitHub.

Multi-Instance Setup

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

import { Component } from '@angular/core';
import {
    DocumentEditorContainerModule,
    ToolbarService,
    RibbonService
} from '@syncfusion/ej2-angular-documenteditor';

@Component({
    selector: 'app-root',
    standalone: true,
    imports: [DocumentEditorContainerModule],
    template: `
    <!-- Use the following service URLs only for demo purposes -->
    <div style="display:flex; width:100%; gap:10px;">

        <ejs-documenteditorcontainer
            serviceUrl="https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/"
            height="590px"
            width="50%"
            [enableToolbar]="true"
            [toolbarMode]="'Ribbon'"
            [enableWebMcp]="true"
            [webMcpSettings]="webMcpSettings1">
        </ejs-documenteditorcontainer>

        <ejs-documenteditorcontainer
            serviceUrl="https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/"
            height="590px"
            width="50%"
            [enableToolbar]="true"
            [toolbarMode]="'Ribbon'"
            [enableWebMcp]="true"
            [webMcpSettings]="webMcpSettings2">
        </ejs-documenteditorcontainer>

    </div>
    `,
    providers: [ToolbarService, RibbonService]
})
export class App {

    public webMcpSettings1 = {
        name: 'documentEditor1'
    };

    public webMcpSettings2 = {
        name: 'documentEditor2'
    };
}

View Sample in GitHub.

Auditing and Restrictions

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

import { Component } from '@angular/core';
import {
    DocumentEditorContainerModule,
    ToolbarService,
    RibbonService,
    WebMcpToolExecuteEventArgs
} from '@syncfusion/ej2-angular-documenteditor';

@Component({
    selector: 'app-root',
    standalone: true,
    imports: [DocumentEditorContainerModule],
    template: `
    <!-- Use the following service URL only for demo purposes -->
    <ejs-documenteditorcontainer
        serviceUrl="https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/"
        height="590px"
        style="width:100%;display:block"
        [enableToolbar]="true"
        [toolbarMode]="'Ribbon'"
        [enableWebMcp]="true"
        [webMcpSettings]="webMcpSettings"
        (beforeWebMcpToolExecute)="beforeWebMcpToolExecute($event)">
    </ejs-documenteditorcontainer>
`,
    providers: [ToolbarService, RibbonService]
})
export class App {
    public webMcpSettings: any = {
        name: 'container'
    };

    public beforeWebMcpToolExecute(args: WebMcpToolExecuteEventArgs): void {
        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.';
        }
    }
}

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: any = { name: 'container' }; 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:4200 or similar

See Also