Skip to main content
Glama
MCP Word Commander

MCP Word Commander

by chyinan

📄 MCP Word Commander

强大的 Word 文档处理 MCP 服务器,支持图片读取/插入、表格操作等功能

Python License MCP

让 AI 助手直接读取、编辑和操作 Word 文档

English | 中文


📖 简介

MCP Word Commander 是一个基于 MCP (Model Context Protocol) 的 Word 文档处理服务,允许 AI 助手直接读取、编辑 Word 文档。

✨ 核心功能

功能模块

描述

🖼️ 图片处理

读取图片并直接展示给 AI、插入图片、删除/替换图片

📊 表格操作

读取表格、在指定位置插入表格、修改单元格、添加/删除行

📝 段落编辑

添加、替换、插入段落,支持完整的格式设置

🔍 搜索替换

在文档中搜索并替换文本


Related MCP server: Word Document MCP Server

📦 依赖

  • Python 3.10+

  • Docker(可选,用于容器化部署)

  • 详见 requirements.txt


🚀 快速开始

方式一:本地运行

# Windows
.venv\Scripts\activate
pip install -r requirements.txt
python server.py

# macOS / Linux
source venv/bin/activate
pip install -r requirements.txt
python server.py

方式二:Docker 部署

🐳 使用 Docker Compose(推荐)

# 构建并启动
docker-compose up -d --build

# 查看日志
docker-compose logs -f

# 停止服务
docker-compose down

🐳 使用 Docker 命令

# 构建镜像
docker build -t mcp-word-commander:latest .

# 运行容器(挂载本地 documents 目录)
docker run -it --rm \
  -v $(pwd)/documents:/documents \
  mcp-word-commander:latest

# Windows PowerShell
docker run -it --rm `
  -v ${PWD}/documents:/documents `
  mcp-word-commander:latest

方式三:在 Claude Desktop / Cursor 中配置

本地运行配置

{
  "mcpServers": {
    "word-commander": {
      "command": "python",
      "args": ["D:/Program/mcp_word_edit/server.py"],
      "env": {}
    }
  }
}

Docker 配置

{
  "mcpServers": {
    "word-commander": {
      "command": "docker",
      "args": [
        "run", "-i", "--rm",
        "-v", "D:/Documents:/documents",
        "mcp-word-commander:latest"
      ],
      "env": {}
    }
  }
}

⚠️ 注意:使用 Docker 时,文档路径需要是容器内的路径(如 /documents/example.docx),而非宿主机路径。


🛠️ 功能列表

📄 文档基础操作

工具

功能描述

create_new_document

创建新的空白 Word 文档

get_document_info

获取文档基本信息(段落数、表格数等)

read_document_structure

分段读取文档内容和样式

📝 段落操作

工具

功能描述

add_formatted_paragraph

在文档末尾添加带格式的段落

replace_paragraph

替换指定段落的内容

insert_paragraph_after

在指定段落后插入新段落

search_and_replace

搜索并替换文本

🖼️ 图片操作

工具

功能描述

get_images_info

获取文档中所有图片的元信息

read_images

🌟 读取图片并直接返回给 AI 查看

add_image

在文档末尾添加图片

insert_image_after_paragraph

在指定段落后插入图片

delete_image

删除指定索引的图片

replace_image

替换指定索引的图片

📊 表格操作

工具

功能描述

read_tables

读取表格内容

create_table_with_data

在文档末尾创建表格

insert_table_after_paragraph

在指定段落后插入表格

update_table_cell

修改表格单元格内容

add_table_row

向表格添加新行

delete_table_row

删除表格中的行

delete_table

删除整个表格


💡 使用示例

🖼️ 读取文档中的图片

# AI 可以直接"看到"文档中的图片
read_images("document.docx")

# 只读取第一张图片
read_images("document.docx", image_index=0)

📸 在指定位置插入图片

# 在第 3 段后插入图片,设置宽度为 4 英寸,居中对齐
insert_image_after_paragraph(
    file_path="document.docx",
    after_index=2,
    image_path="image.png",
    width_inches=4.0,
    alignment="CENTER"
)

📊 在指定位置插入表格

# 在第 5 段后插入 3x3 表格
insert_table_after_paragraph(
    file_path="document.docx",
    after_index=4,
    rows=3,
    cols=3,
    data=[
        ["姓名", "年龄", "城市"],
        ["张三", "25", "北京"],
        ["李四", "30", "上海"]
    ],
    header_bold=True
)

✏️ 修改表格单元格

# 修改第一个表格的 (1, 2) 单元格
update_table_cell(
    file_path="document.docx",
    table_index=0,
    row=1,
    col=2,
    new_text="新内容",
    font_name="Microsoft YaHei",
    font_size=12,
    is_bold=True
)

📁 项目结构

mcp_word_edit/
├── 📄 server.py           # MCP 服务器主文件
├── 📋 requirements.txt    # Python 依赖
├── 🐳 Dockerfile          # Docker 镜像配置
├── 🐳 docker-compose.yml  # Docker Compose 配置
├── 🚫 .dockerignore       # Docker 构建忽略文件
├── 📖 README.md           # 说明文档
└── 📂 documents/           # 文档目录(Docker 挂载点)

🐳 Docker 相关

💾 数据持久化

使用 Docker 时,建议将本地目录挂载到容器的 /documents 目录:

docker run -it --rm -v /path/to/your/docs:/documents mcp-word-commander:latest

📦 镜像信息

项目

详情

基础镜像

python:3.12-slim

预计大小

约 200MB

工作目录

/documents


⚡ 技术特点

特性

说明

🖼️ 图片直接展示

使用 MCP 的 Image 类型,AI 可以直接"看到"文档中的图片内容

🔤 支持中文字体

完整支持中文字体设置(宋体、黑体等)

📍 灵活的位置插入

支持在任意段落后插入图片和表格

📊 完整的表格操作

支持增删改查表格及其内容

🐳 Docker 支持

提供完整的容器化部署方案


🤝 贡献

欢迎提交 Issue 或 Pull Request!

在提交前,请确保:

  • ✅ 代码风格一致

  • ✅ 包含必要的说明文档

  • ✅ 通过相关测试


📜 许可证

本项目使用 MIT 许可证,详见 LICENSE 文件。



📄 MCP Word Commander (English)

A powerful Word document processing MCP server with image and table support

Python License MCP

Enable AI assistants to directly read, edit, and manipulate Word documents

中文 | English


📖 Overview

MCP Word Commander is a Word document processing service based on MCP (Model Context Protocol), enabling AI assistants to directly read and edit Word documents.

✨ Core Features

Module

Description

🖼️ Image Processing

Read images and display them directly to AI, insert/delete/replace images

📊 Table Operations

Read tables, insert tables at specific positions, modify cells, add/delete rows

📝 Paragraph Editing

Add, replace, insert paragraphs with full formatting support

🔍 Search & Replace

Find and replace text in documents


📦 Requirements

  • Python 3.10+

  • Docker (optional, for containerized deployment)

  • See requirements.txt for details


🚀 Quick Start

Option 1: Local Installation

# Windows
.venv\Scripts\activate
pip install -r requirements.txt
python server.py

# macOS / Linux
source venv/bin/activate
pip install -r requirements.txt
python server.py

Option 2: Docker Deployment

# Build and start
docker-compose up -d --build

# View logs
docker-compose logs -f

# Stop service
docker-compose down

🐳 Using Docker Command

# Build image
docker build -t mcp-word-commander:latest .

# Run container (mount local documents directory)
docker run -it --rm \
  -v $(pwd)/documents:/documents \
  mcp-word-commander:latest

# Windows PowerShell
docker run -it --rm `
  -v ${PWD}/documents:/documents `
  mcp-word-commander:latest

Option 3: Configure in Claude Desktop / Cursor

Local Configuration

{
  "mcpServers": {
    "word-commander": {
      "command": "python",
      "args": ["/path/to/mcp_word_edit/server.py"],
      "env": {}
    }
  }
}

Docker Configuration

{
  "mcpServers": {
    "word-commander": {
      "command": "docker",
      "args": [
        "run", "-i", "--rm",
        "-v", "/path/to/documents:/documents",
        "mcp-word-commander:latest"
      ],
      "env": {}
    }
  }
}

⚠️ Note: When using Docker, document paths should be container paths (e.g., /documents/example.docx), not host paths.


🛠️ Feature List

📄 Basic Document Operations

Tool

Function

create_new_document

Create a new blank Word document

get_document_info

Get basic document information (paragraph count, table count, etc.)

read_document_structure

Read document content and styles in segments

📝 Paragraph Operations

Tool

Function

add_formatted_paragraph

Add a formatted paragraph at the end of document

replace_paragraph

Replace content of a specific paragraph

insert_paragraph_after

Insert a new paragraph after a specific paragraph

search_and_replace

Search and replace text

🖼️ Image Operations

Tool

Function

get_images_info

Get metadata of all images in the document

read_images

🌟 Read images and return them directly for AI to view

add_image

Add image at the end of document

insert_image_after_paragraph

Insert image after a specific paragraph

delete_image

Delete image by index

replace_image

Replace image by index

📊 Table Operations

Tool

Function

read_tables

Read table content

create_table_with_data

Create table at the end of document

insert_table_after_paragraph

Insert table after a specific paragraph

update_table_cell

Modify table cell content

add_table_row

Add new row to table

delete_table_row

Delete row from table

delete_table

Delete entire table


💡 Usage Examples

🖼️ Read Images from Document

# AI can directly "see" images in the document
read_images("document.docx")

# Read only the first image
read_images("document.docx", image_index=0)

📸 Insert Image at Specific Position

# Insert image after paragraph 3, set width to 4 inches, center alignment
insert_image_after_paragraph(
    file_path="document.docx",
    after_index=2,
    image_path="image.png",
    width_inches=4.0,
    alignment="CENTER"
)

📊 Insert Table at Specific Position

# Insert a 3x3 table after paragraph 5
insert_table_after_paragraph(
    file_path="document.docx",
    after_index=4,
    rows=3,
    cols=3,
    data=[
        ["Name", "Age", "City"],
        ["John", "25", "Beijing"],
        ["Jane", "30", "Shanghai"]
    ],
    header_bold=True
)

✏️ Modify Table Cell

# Modify cell (1, 2) of the first table
update_table_cell(
    file_path="document.docx",
    table_index=0,
    row=1,
    col=2,
    new_text="New Content",
    font_name="Microsoft YaHei",
    font_size=12,
    is_bold=True
)

📁 Project Structure

mcp_word_edit/
├── 📄 server.py           # MCP server main file
├── 📋 requirements.txt    # Python dependencies
├── 🐳 Dockerfile          # Docker image configuration
├── 🐳 docker-compose.yml  # Docker Compose configuration
├── 🚫 .dockerignore       # Docker build ignore file
├── 📖 README.md           # Documentation
└── 📂 documents/          # Documents directory (Docker mount point)

🐳 Docker Information

💾 Data Persistence

When using Docker, mount a local directory to /documents in the container:

docker run -it --rm -v /path/to/your/docs:/documents mcp-word-commander:latest

📦 Image Details

Item

Details

Base Image

python:3.12-slim

Estimated Size

~200MB

Working Directory

/documents


⚡ Technical Features

Feature

Description

🖼️ Direct Image Display

Uses MCP's Image type, allowing AI to directly "see" image content in documents

🔤 Chinese Font Support

Full support for Chinese font settings (SimSun, SimHei, etc.)

📍 Flexible Position Insertion

Support inserting images and tables after any paragraph

📊 Complete Table Operations

Support CRUD operations for tables and their content

🐳 Docker Support

Complete containerized deployment solution


🤝 Contributing

Issues and PRs are welcome!

Before submitting, please ensure:

  • ✅ Code style consistency

  • ✅ Necessary documentation included

  • ✅ Related tests passed


📜 License

This project is licensed under the MIT License. See LICENSE for details.


Made with ❤️ for the MCP community

Available Tools

20 tools
add_formatted_paragraphA

向文档追加带有特定样式的段落。支持设置中文字体(如宋体/黑体)。

Args: file_path: 文档路径 text: 段落内容 font_name: 字体名称 (默认 "SimSun" 即宋体, 可选 "Microsoft YaHei", "Times New Roman" 等) font_size: 字号 (pt) is_bold: 是否加粗 alignment: 对齐方式 ("LEFT", "CENTER", "RIGHT", "JUSTIFY") indent_first_line: 首行缩进字符数 (例如 2.0 代表缩进两个字符) line_spacing: 行距 (pt),例如 20.0 代表固定值20磅

Inputs: text (required), file_path (required), is_bold, alignment, +4 more. Returns: result

add_imageA

在文档末尾添加图片。

Args: file_path: 文档路径 image_path: 图片文件路径 (支持 PNG, JPG, GIF, BMP 等格式) width_inches: 图片宽度 (英寸),不指定则使用原始宽度 height_inches: 图片高度 (英寸),不指定则按宽度等比缩放 alignment: 对齐方式 ("LEFT", "CENTER", "RIGHT")

Inputs: file_path (required), image_path (required), alignment, width_inches, +1 more. Returns: result

add_table_rowA

向表格中添加新行。

Args: file_path: 文档路径 table_index: 表格索引 (0-based) row_data: 新行的数据列表 position: 插入位置 (0-based),不指定则添加到末尾

Inputs: row_data (required), file_path (required), table_index (required), position. Returns: result

create_new_documentB

创建一个新的空白 Word 文档。

Args: file_path: 保存文档的路径 (例如: "output.docx")

Inputs: file_path (required). Returns: result

create_table_with_dataA

在文档末尾创建一个表格并填充数据。

Args: file_path: 文档路径 rows: 行数 cols: 列数 data: 二维数组,包含要填充的数据 [['Header1', 'Header2'], ['Val1', 'Val2']] header_bold: 第一行是否加粗

Inputs: cols (required), data (required), rows (required), file_path (required), +1 more. Returns: result

delete_imageB

删除文档中指定索引的图片。 使用 get_images_info 工具可以查看所有图片的索引。

Args: file_path: 文档路径 image_index: 要删除的图片索引 (0-based)

Inputs: file_path (required), image_index (required). Returns: result

delete_tableC

删除文档中指定索引的表格。

Args: file_path: 文档路径 table_index: 要删除的表格索引 (0-based)

Inputs: file_path (required), table_index (required). Returns: result

delete_table_rowB

删除表格中的指定行。

Args: file_path: 文档路径 table_index: 表格索引 (0-based) row_index: 要删除的行索引 (0-based)

Inputs: file_path (required), row_index (required), table_index (required). Returns: result

get_document_infoC

获取 Word 文档的基本信息概览,包括段落数、表格数、各段落的简要信息。 用于在读取完整内容前快速了解文档结构。

Args: file_path: 文档路径

Returns: JSON 格式的文档概览信息。

Inputs: file_path (required). Returns: result

get_images_infoA

获取 Word 文档中所有图片的元信息,不返回图片内容。 用于在读取图片前了解文档中图片的结构和位置。

Args: file_path: 文档路径 include_tables: 是否包含表格中的图片 (默认True)

Returns: JSON 格式的图片元信息列表。

Inputs: file_path (required), include_tables. Returns: result

insert_image_after_paragraphA

在指定段落之后插入图片。

Args: file_path: 文档路径 after_index: 在此段落索引之后插入 (0-based) image_path: 图片文件路径 width_inches: 图片宽度 (英寸) height_inches: 图片高度 (英寸) alignment: 对齐方式 ("LEFT", "CENTER", "RIGHT")

Inputs: file_path (required), image_path (required), after_index (required), alignment, +2 more. Returns: result

insert_paragraph_afterB

在指定段落之后插入新段落。

Args: file_path: 文档路径 after_index: 在此段落索引之后插入 (0-based) text: 新段落内容 font_name: 字体名称 font_size: 字号 (pt) is_bold: 是否加粗 alignment: 对齐方式 indent_first_line: 首行缩进字符数 line_spacing: 行距 (pt)

Inputs: text (required), file_path (required), after_index (required), is_bold, +5 more. Returns: result

insert_table_after_paragraphB

在指定段落之后插入表格。

Args: file_path: 文档路径 after_index: 在此段落索引之后插入表格 (0-based) rows: 表格行数 cols: 表格列数 data: 二维数组,包含要填充的数据 [['Header1', 'Header2'], ['Val1', 'Val2']] header_bold: 第一行是否加粗 (默认True) style: 表格样式 (默认 "Table Grid")

Inputs: cols (required), data (required), rows (required), file_path (required), +3 more. Returns: result

read_document_structureA

分段读取 Word 文档的内容和样式信息。支持分页读取大文档。

Args: file_path: 文档路径 start_index: 从第几个段落开始读取 (0-based) limit: 最多读取多少个段落 (默认50) include_empty: 是否包含空段落 (默认False)

Returns: JSON 格式的字符串,包含段落文本和对应的样式信息。

Inputs: file_path (required), limit, start_index, include_empty. Returns: result

read_imagesA

读取 Word 文档中的图片,直接返回给 AI 查看。

Args: file_path: 文档路径 image_index: 指定读取第几张图片 (0-based),不指定则读取所有图片 include_tables: 是否包含表格中的图片 (默认True)

Returns: Image 对象列表,AI 可以直接"看到"这些图片。 如果发生错误,返回错误信息字符串。

Inputs: file_path (required), image_index, include_tables.

read_tablesB

读取 Word 文档中的表格内容。

Args: file_path: 文档路径 table_index: 指定读取第几个表格 (0-based),不指定则读取所有表格

Returns: JSON 格式的表格数据。

Inputs: file_path (required), table_index. Returns: result

replace_imageC

替换文档中指定索引的图片。 使用 get_images_info 工具可以查看所有图片的索引。

Args: file_path: 文档路径 image_index: 要替换的图片索引 (0-based) new_image_path: 新图片文件路径 width_inches: 新图片宽度 (英寸),不指定则使用原图片尺寸 height_inches: 新图片高度 (英寸)

Inputs: file_path (required), image_index (required), new_image_path (required), width_inches, +1 more. Returns: result

replace_paragraphA

替换指定段落的内容,并应用新的格式。

Args: file_path: 文档路径 paragraph_index: 要替换的段落索引 (0-based) new_text: 新的段落内容 font_name: 字体名称 font_size: 字号 (pt) is_bold: 是否加粗 alignment: 对齐方式 indent_first_line: 首行缩进字符数 line_spacing: 行距 (pt)

Inputs: new_text (required), file_path (required), paragraph_index (required), is_bold, +5 more. Returns: result

search_and_replaceB

在文档中搜索并替换文本(保持原有格式)。

Args: file_path: 文档路径 search_text: 要搜索的文本 replace_text: 替换为的文本 match_case: 是否区分大小写 (默认True)

Inputs: file_path (required), search_text (required), replace_text (required), match_case. Returns: result

update_table_cellB

修改表格中指定单元格的内容。

Args: file_path: 文档路径 table_index: 表格索引 (0-based) row: 行索引 (0-based) col: 列索引 (0-based) new_text: 新的单元格内容 font_name: 字体名称 (可选) font_size: 字号 pt (可选) is_bold: 是否加粗 (可选)

Inputs: col (required), row (required), new_text (required), file_path (required), +4 more. Returns: result

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A3.6/5.0

    Scored across 20 tools

    Disambiguation4/5

    Tools cover distinct operations (add, create, delete, get, insert, read, replace, search, update) on different elements (paragraphs, images, tables, rows, cells). Some overlap between add_ and insert_ functions but descriptions clarify positional difference (end vs after specific index), making disambiguation manageable.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun snake_case pattern (e.g., add_image, create_table_with_data, delete_table_row). Verbs are descriptive and nouns indicate target element. Minor exceptions like 'search_and_replace' are still clear and fit the pattern.

    Tool Count4/5

    20 tools is slightly above the typical recommended range but well-scoped for comprehensive Word document manipulation. Each tool serves a clear purpose and covers essential creation, reading, editing, and deletion operations across paragraphs, images, tables, and cells.

    Completeness4/5

    The tool set covers core CRUD operations for paragraphs, images, tables, and cells, plus document info and search/replace. Missing some advanced features like headers/footers, page setup, styles, or bookmarks, but the surface is sufficient for common document editing tasks.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers