DOCX MCP Server

DOCX MCP Server

Enables creation, editing, and management of Word documents through JSON schema with support for rich content including text formatting, tables, images, code blocks, and lists. Provides comprehensive DOCX operations including opening existing documents, modifying content, and saving files to disk.

Category
访问服务器

README

docx-mcp

A Node.js MCP server that lets clients create, query, edit, and save DOCX documents using a JSON schema, powered by the docx library.

Features

  • Complete DOCX operations: Create, edit, and save Word documents via Model Context Protocol (MCP)
  • JSON Schema validation: Structured document definition with comprehensive validation
  • Rich content blocks:
    • Text & Headings: 6 heading levels with advanced formatting
    • Lists: Ordered/unordered lists with multiple numbering styles and nesting
    • Code Blocks: Syntax highlighting for 180+ languages with themes and line numbers
    • Tables: Full table support with styling and cell formatting
    • Images: URL downloads with fallback, local files, and base64 embedding
    • Page Control: Page breaks and section breaks
  • Advanced text formatting:
    • Basic: Bold, italic, underline, strikethrough, colors
    • Enhanced: Superscript, subscript, font families, highlights, small caps
    • Spacing: Character spacing, paragraph alignment, indentation
  • Document management: In-memory registry with unique IDs
  • Metadata support: Complete document properties and custom metadata
  • File operations: Open existing DOCX files and save to disk
  • Error handling: Graceful fallbacks and comprehensive validation

JSON Schema

See src/schema.ts for the full schema. Key concepts:

  • meta: Document metadata (title, subject, creator, etc.)
  • pageSettings: Page size, orientation, margins, header/footer margins (NEW in v0.3.0)
  • headers: Page header configuration with default/first/even page support (NEW in v0.4.0)
  • footers: Page footer configuration with default/first/even page support (NEW in v0.4.0)
  • content: Array of blocks: heading, paragraph, table, image, codeBlock, list, pageBreak, horizontalRule, blockquote, infoBox, textBox
  • Enhanced blocks:
    • CodeBlock: { type: "codeBlock", language: "javascript", code: "...", showLineNumbers: true }
    • List: { type: "list", ordered: true, items: [...] } with nesting support
    • Table: Enhanced with backgroundColor, borders, verticalAlign, cell margins (NEW in v0.3.0)
    • HorizontalRule: { type: "horizontalRule", style: "single", color: "#666" } (NEW in v0.3.0)
    • Blockquote: { type: "blockquote", children: [...], borderColor: "#ccc" } (NEW in v0.3.0)
    • InfoBox: { type: "infoBox", boxType: "info", title: "Note", children: [...] } (NEW in v0.3.0)
    • TextBox: { type: "textBox", children: [...] } with border styling (NEW in v0.3.0)
    • Enhanced TextRun: Supports fontFamily, superScript, subScript, highlight, etc.
  • Each paragraph/heading uses inline runs (text, hyperlink) with rich formatting options

Headers & Footers Configuration (NEW in v0.4.0)

{
  "headers": {
    "default": {
      "alignment": "center",
      "children": [
        {
          "type": "documentTitle",
          "bold": true,
          "size": 14,
          "color": "#1f4788"
        }
      ]
    },
    "first": {
      "alignment": "right",
      "children": [
        {
          "type": "text",
          "text": "Confidential Document",
          "bold": true,
          "color": "#cc0000"
        }
      ]
    }
  },
  "footers": {
    "default": {
      "alignment": "center", 
      "children": [
        {
          "type": "text",
          "text": "Page "
        },
        {
          "type": "pageNumber",
          "format": "decimal"
        },
        {
          "type": "text",
          "text": " of "
        },
        {
          "type": "pageNumber",
          "format": "totalPages"
        }
      ]
    }
  }
}

Supported header/footer elements:

  • text: Static text with styling options
  • pageNumber: Auto page numbering (decimal, upperRoman, lowerRoman, upperLetter, lowerLetter)
  • currentDate: Auto-updating date with custom format strings
  • documentTitle: References document meta.title
  • image: Images in headers/footers (base64, path, url)

New in v0.4.0 - Document Structure & Headers/Footers

  • Headers & Footers System: Comprehensive page header and footer support
    • Default, first page, and even page headers/footers
    • Rich content: text, page numbers, dates, document title, images
    • Flexible alignment: left, center, right
    • Advanced styling: fonts, colors, sizes, bold/italic
  • Dynamic Content Elements:
    • pageNumber: Automatic page numbering with multiple formats (decimal, roman, letters)
    • currentDate: Auto-updating dates with custom formats
    • documentTitle: Reference document metadata
    • text: Static text with full styling options
    • image: Headers/footers images support
  • Professional Layout Control:
    • Different headers/footers for first page vs. rest of document
    • Odd/even page variations for book-style layouts
    • Precise margin control for headers and footers
    • Integration with existing page settings system

New in v0.3.0 - Styles & Layout

  • Page Settings: Page size (A4, Letter, etc.), orientation, margins control
  • Enhanced Tables: Background colors, border styles, vertical alignment, table templates
  • New Block Types: Horizontal rules, blockquotes, info boxes, text boxes
  • Advanced Styling: More comprehensive table and cell formatting options

Previous Updates

v0.2.0 - Enhanced Document Operations

  • Code Blocks: Syntax highlighting for 180+ programming languages
  • Lists: Ordered and unordered lists with multiple styles and nesting
  • Page Breaks: Control document pagination
  • Enhanced Text: Superscript, subscript, font families, highlights
  • Improved Schema: More comprehensive validation and type safety

Run locally

  1. Install deps
npm install
  1. Dev mode
npm run dev
  1. Build and start
npm run build
npm start

Tools

  • docx-getSchema { } // Get JSON schema - call this first!
  • docx-create { json }
  • docx-open { id?, path } // open .docx file from disk
  • docx-queryMeta { id }
  • docx-queryObjects { id }
  • docx-editMeta { id, patch }
  • docx-editContent { id, index, block }
  • docx-insertContent { id, index, block }
  • docx-removeContent { id, index }
  • docx-save { id, path }
  • docx-exportJson { id }

Example JSON

{
  "meta": { "title": "Demo", "creator": "DOCX MCP v0.2.0" },
  "content": [
    { "type": "heading", "level": 1, "children": [ { "type": "text", "text": "Title" } ] },
    { "type": "paragraph", "children": [ 
      { "type": "text", "text": "Hello ", "bold": true }, 
      { "type": "text", "text": "world", "color": "FF0000" } 
    ]},
    { 
      "type": "codeBlock", 
      "language": "javascript", 
      "showLineNumbers": true,
      "code": "console.log('Hello, World!');" 
    },
    {
      "type": "list",
      "ordered": false,
      "items": [
        { "children": [{ "type": "text", "text": "First item" }] },
        { "children": [{ "type": "text", "text": "Second item" }] }
      ]
    },
    { "type": "image", "url": "https://picsum.photos/300/200", "width": 300, "height": 200 },
    { "type": "pageBreak" },
    { "type": "table", "rows": [ { "cells": [ 
      { "children": [ { "type": "paragraph", "children": [ { "type": "text", "text": "A" } ] } ] }, 
      { "children": [ { "type": "paragraph", "children": [ { "type": "text", "text": "B" } ] } ] } 
    ] } ] }
  ]
}

Image Support

Images can be included in three ways:

  • URL: { "type": "image", "url": "https://example.com/image.png", "width": 300, "height": 200 }
  • Local file path: { "type": "image", "path": "/path/to/image.png", "width": 300, "height": 200 }
  • Base64 data: { "type": "image", "data": "base64string", "format": "png", "width": 150, "height": 100 }

URL Image Features:

  • Automatic download from HTTP/HTTPS URLs
  • Fallback to generated placeholder image if download fails
  • Placeholder shows original URL and dimensions
  • Support for common image formats (PNG, JPEG, JPG)
  • Note: Fontconfig warnings on Windows are harmless and can be ignored

Supported formats: PNG, JPEG, JPG

Notes

  • Hyperlinks are rendered visually as underlined blue text. Full hyperlink relationships can be added later.
  • Images support URL downloads, local file paths, and base64 data.
  • This server runs over stdio to be compatible with MCP hosts.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选