Skip to main content
Glama
docx_mcp_server_ts

docx_mcp_server_ts

by Mavline

DOCX MCP Server

Ein umfassender, auf TypeScript basierender MCP-Server (Model Context Protocol) für die universelle DOCX-Verarbeitung mit vollständiger OOXML-Unterstützung. Verarbeiten Sie Word-Dokumente programmgesteuert mit Unterstützung für Text, Tabellen, Bilder, Kopf- und Fußzeilen, SDTs, Kommentare und mehr.

Funktionen

  • Vollständiger OOXML-Zugriff: DOCX-Teile auf ZIP-Ebene lesen/schreiben mit vollständiger Namespace-Unterstützung

  • Textoperationen: Text extrahieren, finden und ersetzen mit minimaler Diff-Erhaltung

  • Tabellenverwaltung: Zeilen einfügen/löschen, Zellen ändern, Zusammenführungs-/Teilungsoperationen

  • Bildverarbeitung: Inline-/positionierte Bilder mit EMU-basierter Größenanpassung hinzufügen

  • Strukturierte Datentags (SDT): Zugriff auf Inhaltssteuerelemente nach Tag oder Alias

  • Kopf-/Fußzeilen: Abschnittskopf- und -fußzeilen auflisten und ändern

  • Änderungsnachverfolgung: Revisionen annehmen/ablehnen, Einfügungen/Löschungen behandeln

  • Kommentare: Dokumentkommentare verwalten

  • Metadaten: Kern- und Anwendungseigenschaften lesen/schreiben

  • LRU-Caching: Effiziente Speicherverwaltung mit Teil-Caching

  • Verlustfreies XML: Erhält die Dokumentstruktur mit fast-xml-parser

Related MCP server: InkPaw

Installation

npm install
npm run build

Schnellstart

Server starten

npm start

Der Server lauscht über stdin/stdout auf MCP-Protokollnachrichten.

Installation & Konfiguration

Claude Code CLI

claude mcp install docx \
  --command node \
  --args /full/path/to/docx_mcp_server_ts/dist/index.js \
  --env LOG_LEVEL=INFO

~/.claude.json (für Claude Code)

Bearbeiten Sie ~/.claude.json und fügen Sie Folgendes im Abschnitt "projects" hinzu:

{
  "projects": {
    "/full/path/to/docx_mcp_server_ts": {
      "mcpServers": {
        "docx": {
          "command": "node",
          "args": ["/full/path/to/docx_mcp_server_ts/dist/index.js"],
          "env": {
            "LOG_LEVEL": "INFO"
          }
        }
      }
    }
  }
}

Beispiel für Linux/WSL:

{
  "projects": {
    "/mnt/c/Users/pavelk/Desktop/Projects/MCP-servers/docx_mcp_server_ts": {
      "mcpServers": {
        "docx": {
          "command": "node",
          "args": ["/mnt/c/Users/pavelk/Desktop/Projects/MCP-servers/docx_mcp_server_ts/dist/index.js"],
          "env": {
            "LOG_LEVEL": "INFO"
          }
        }
      }
    }
  }
}

MCP-Tools

Dokumentverwaltung

docx.open

Öffnet ein DOCX-Dokument aus einer Datei oder einem Base64-Puffer.

Eingabe:

{
  "path": "/path/to/document.docx",
  "bufferBase64": "..."  // OR provide base64 data
}

Ausgabe:

{
  "docId": "uuid-string",
  "parts": ["word/document.xml", ...],
  "props": { "core": {}, "app": {} }
}

docx.close

Schließt ein Dokument und gibt Ressourcen frei.

Eingabe: { "docId": "uuid" }

docx.save

Speichert ein Dokument in einer Datei oder gibt es als Base64 zurück.

Eingabe:

{
  "docId": "uuid",
  "path": "/output/path.docx",  // optional
  "returnBase64": true  // optional
}

docx.list_parts

Listet alle Teile des Dokuments auf.

docx.part_read / docx.part_write

Liest/schreibt einzelne XML-Teile für den Low-Level-Zugriff.

Textoperationen

docx.get_text

Extrahiert den gesamten Text aus dem Dokument.

Eingabe: { "docId": "uuid", "scope": "document|headers|footers|all" }

docx.replace_text

Ersetzt Text, wobei die Run-Struktur erhalten bleibt.

Eingabe:

{
  "docId": "uuid",
  "match": "search text",
  "replace": "replacement",
  "mode": "literal|regex",
  "where": "document|headers|footers|all"
}

Ausgabe: { "replaced": 5 }

docx.find

Findet Text mit Kontext.

Ausgabe:

{
  "hits": [
    {
      "text": "found text",
      "context": "...found text...",
      "offset": 150
    }
  ]
}

Tabellenoperationen

docx.tables_list

Listet alle Tabellen mit ihren Dimensionen auf.

Ausgabe:

{
  "tables": [
    {
      "tableXPath": "//w:tbl[1]",
      "rows": 5,
      "colsApprox": 3
    }
  ]
}

docx.table_edit

Führt Tabellenoperationen aus.

Eingabe:

{
  "docId": "uuid",
  "tableXPath": "//w:tbl[1]",
  "op": {
    "kind": "setCellText",
    "row": 0,
    "col": 0,
    "text": "new value"
  }
}

Unterstützte Operationen:

  • { "kind": "setCellText", "row": number, "col": number, "text": string }

  • { "kind": "insertRow", "at": number }

  • { "kind": "deleteRow", "at": number }

  • { "kind": "insertCol", "at": number }

  • { "kind": "deleteCol", "at": number }

Strukturierte Datentags (SDT)

docx.sdt_get

Ruft den Inhalt eines Inhaltssteuerelements ab.

Eingabe: { "docId": "uuid", "tagOrAlias": "control_tag" }

Ausgabe:

{
  "xml": "<w:p>...</w:p>",
  "textPreview": "Control content..."
}

docx.sdt_put

Aktualisiert ein Inhaltssteuerelement.

Eingabe:

{
  "docId": "uuid",
  "tagOrAlias": "control_tag",
  "xmlFragment": "<w:p>...</w:p>"
}

Bildoperationen

docx.images_list

Listet alle Bilder mit Metadaten auf.

Ausgabe:

{
  "images": [
    {
      "rId": "rId4",
      "path": "word/media/image1.png",
      "sizeEMU": { "cx": 914400, "cy": 914400 }
    }
  ]
}

docx.image_add

Fügt ein Bild inline oder verankert ein.

Eingabe:

{
  "docId": "uuid",
  "target": {
    "afterParagraphXPath": "//w:p[1]",
    "sdtTagOrAlias": "imageControl"  // OR use SDT
  },
  "image": {
    "path": "/local/image.png",
    "base64": "...",  // OR base64 data
    "filename": "image.png",
    "contentType": "image/png"
  },
  "placement": {
    "kind": "inline"  // OR { "kind": "anchor", "xEMU": 0, "yEMU": 0 }
  },
  "size": {
    "widthMM": 50,
    "heightMM": 50
  },
  "altText": "Description"
}

docx.image_update_position

Aktualisiert Position/Größe eines verankerten Bildes.

Erweiterte Operationen

docx.styles_get / docx.styles_set

Liest/schreibt styles.xml

docx.numbering_get / docx.numbering_set

Liest/schreibt numbering.xml

docx.headers_footers_list

Listet Kopf- und Fußzeilen mit Abschnittsinformationen auf.

docx.headers_footers_get / docx.headers_footers_set

Liest/schreibt eine bestimmte Kopf- oder Fußzeile.

docx.comments_list / docx.comments_add / docx.comments_delete

Verwaltet Dokumentkommentare.

docx.changes_accept_all

Akzeptiert alle nachverfolgten Änderungen (entfernt w:del, entpackt w:ins).

Ausgabe: { "removedDel": 3, "flattenedIns": 5 }

docx.metadata_get / docx.metadata_set

Liest/schreibt Dokumenteigenschaften (core.xml, app.xml).

Größenumrechnungen

Der Server führt EMU-Umrechnungen (English Metric Unit) intern durch:

  • 1 Zoll = 914.400 EMU

  • 1 mm ≈ 36.000 EMU

  • 1 Punkt ≈ 12.700 EMU

Beispiele

Text extrahieren und ersetzen

// Open document
const openResult = await client.call('docx.open', {
  path: '/tmp/document.docx'
});
const docId = openResult.docId;

// Get text
const textResult = await client.call('docx.get_text', { docId });
console.log(textResult.text);

// Replace text
await client.call('docx.replace_text', {
  docId,
  match: 'old text',
  replace: 'new text',
  mode: 'literal'
});

// Save
await client.call('docx.save', {
  docId,
  path: '/tmp/document-modified.docx'
});

// Close
await client.call('docx.close', { docId });

Tabelle ändern

// List tables
const tablesResult = await client.call('docx.tables_list', { docId });
const tableXPath = tablesResult.tables[0].tableXPath;

// Update cell
await client.call('docx.table_edit', {
  docId,
  tableXPath,
  op: {
    kind: 'setCellText',
    row: 0,
    col: 0,
    text: 'Updated Value'
  }
});

// Insert row
await client.call('docx.table_edit', {
  docId,
  tableXPath,
  op: {
    kind: 'insertRow',
    at: 1
  }
});

Bild hinzufügen

const fs = require('fs').promises;

const imageBuffer = await fs.readFile('/path/to/image.png');
const base64 = imageBuffer.toString('base64');

await client.call('docx.image_add', {
  docId,
  target: {
    afterParagraphXPath: '//w:p[1]'
  },
  image: {
    base64,
    filename: 'image.png',
    contentType: 'image/png'
  },
  placement: {
    kind: 'inline'
  },
  size: {
    widthMM: 100,
    heightMM: 75
  },
  altText: 'My image'
});

Architektur

src/
├── index.ts              # MCP server entry point
├── logger.ts             # Logging utility
├── errors.ts             # Error types and codes
├── ooxml/
│   ├── namespaces.ts     # OOXML constants and namespaces
│   ├── emu.ts            # Unit conversion utilities
│   ├── dom.ts            # XML DOM utilities (xmldom + fontoxpath)
│   ├── xmlParser.ts      # FXP parser with order preservation
│   ├── parts.ts          # ZIP part reading/writing
│   ├── rels.ts           # Relationship management
│   ├── text.ts           # Text operations with diff-match-patch
│   ├── tables.ts         # Table manipulation
│   ├── sdt.ts            # Structured Data Tags
│   ├── drawings.ts       # Image handling
│   ├── headersFooters.ts # Header/footer operations
│   ├── comments.ts       # Comment management
│   ├── changes.ts        # Track changes handling
│   ├── styles.ts         # Styles XML access
│   └── numbering.ts      # Numbering XML access
├── store/
│   ├── types.ts          # Store type definitions
│   └── docStore.ts       # Document store with LRU cache
└── mcp/
    └── tools.ts          # MCP tool implementations

Leistung

  • Speicher: Der LRU-Cache begrenzt die Anzahl der Teile pro Dokument auf 50 zwischengespeicherte Elemente

  • Gesamtgröße: Unterstützt Dokumente bis zu 100 MB im Arbeitsspeicher

  • Partieller Zugriff: Nur angeforderte Teile werden aus der ZIP-Datei geparst

  • Minimale Diffs: Textersetzungen erhalten nach Möglichkeit die Run-Struktur

Einschränkungen

  • Seitenlayoutberechnungen werden nicht durchgeführt (Word-Rendering-Engine erforderlich)

  • Erweiterte DrawingML-Transformationen sind schreibgeschützt

  • VBA-Makros und eingebettete OLE-Objekte werden nicht unterstützt

  • Extrem große Dokumente (>500MB) erfordern möglicherweise Streaming

Entwicklung

# Install dependencies
npm install

# Type check
npm run type-check

# Build
npm run build

# Run dev server
npm run dev

# Debug with inspector
npm run dev:debug

Protokollierung

Steuern Sie die Protokollebene über eine Umgebungsvariable:

LOG_LEVEL=DEBUG npm start     # Verbose
LOG_LEVEL=INFO npm start      # Default
LOG_LEVEL=WARN npm start      # Warnings only
LOG_LEVEL=ERROR npm start     # Errors only

Protokollunterstützung

  • Transport: stdio

  • Protokoll: MCP (Model Context Protocol)

  • Handler: @modelcontextprotocol/sdk

Lizenz

MIT

Ressourcen

Available Tools

29 tools
docx.changes_accept_allB

Accept all changes

Inputs: no named parameters.

docx.closeB

Close a DOCX document and free resources

Inputs: docId.

docx.comments_addD

Add comment

Inputs: no named parameters.

docx.comments_deleteD

Delete comment

Inputs: no named parameters.

docx.comments_listC

List comments

Inputs: no named parameters.

docx.findB

Find text in document

Inputs: no named parameters.

docx.get_textC

Get all text from document

Inputs: docId.

docx.headers_footers_getC

Get header/footer

Inputs: no named parameters.

docx.headers_footers_listC

List headers/footers

Inputs: no named parameters.

docx.headers_footers_setC

Set header/footer

Inputs: no named parameters.

docx.image_addC

Add image

Inputs: no named parameters.

docx.images_listA

List all images

Inputs: no named parameters.

docx.image_update_positionD

Update image position

Inputs: no named parameters.

docx.list_partsB

List all parts (XML files) in a DOCX document

Inputs: docId.

docx.metadata_getC

Get metadata

Inputs: no named parameters.

docx.metadata_setC

Set metadata

Inputs: no named parameters.

docx.numbering_getC

Get numbering

Inputs: no named parameters.

docx.numbering_setC

Set numbering

Inputs: no named parameters.

docx.openB

Open a DOCX document from file or buffer

Inputs: path, bufferBase64.

docx.part_readB

Read a specific XML part from the document

Inputs: docId, partPath.

docx.part_writeC

Write/update a specific XML part in the document

Inputs: xml, docId, partPath.

docx.replace_textB

Replace text in document

Inputs: no named parameters.

docx.saveC

Save a DOCX document to file or get as base64

Inputs: path, docId, returnBase64.

docx.sdt_getC

Get SDT content

Inputs: no named parameters.

docx.sdt_putC

Set SDT content

Inputs: no named parameters.

docx.styles_getC

Get styles

Inputs: no named parameters.

docx.styles_setC

Set styles

Inputs: no named parameters.

docx.table_editD

Edit table

Inputs: no named parameters.

docx.tables_listB

List all tables

Inputs: no named parameters.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    C2.9/5.0

    Scored across 29 tools

    Disambiguation5/5

    Each tool has a clear, distinct purpose (e.g., get_text vs. find vs. replace_text), with no overlapping functionality. The split between list/get/set operations across different document parts (tables, headers, styles) avoids ambiguity.

    Naming Consistency5/5

    All tools follow a consistent verb_noun pattern (e.g., list_parts, part_read, table_edit) and share the 'docx.' prefix. The naming is uniform, lowercase with underscores, making it predictable and easy to navigate.

    Tool Count4/5

    With 29 tools, the count is higher than the typical 3-15 range, but it is justified by the comprehensive scope of DOCX manipulation (text, tables, images, styles, metadata, comments, etc.). It feels extensive rather than bloated, though slightly over the ideal range.

    Completeness4/5

    The tool set covers a wide range of DOCX operations including open/save, text handling, tables, images, styles, numbering, headers/footers, comments, changes, and metadata. Minor gaps exist (e.g., no explicit delete for tables or images, no create-new-document operation), but agents can likely work around these using existing tools.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      D
      quality
      D
      maintenance
      Enables reading, writing, editing, and converting Office documents (ODT, DOCX, ODS, XLSX, PDF, etc.) using MCP tools, with no external dependencies.
      11
      17 npm
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to generate, edit, validate, and render Word documents programmatically via MCP, ensuring correct OOXML structure and style.
      3
      MIT
    • A
      license
      B
      quality
      C
      maintenance
      Provides MCP tools for working with Microsoft Word documents, enabling reading, editing with tracked changes, formatting, table manipulation, comments, and PDF conversion via direct OOXML manipulation.
      37
      MIT
    • F
      license
      C
      quality
      D
      maintenance
      Enables comprehensive DOCX/OOXML document manipulation via MCP, covering text, tables, images, content controls, comments, tracked changes, and metadata.
      34
      -