npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@xilonglab/js-docx-mcp

v1.0.6

Published

基于 cursor-xml-automation 的 DOCX 文档自动化 MCP 服务器,通过 Claude Code 连接并创建、编辑 DOCX 文档。

Readme

DOCX MCP Server

基于 cursor-xml-automation 的 DOCX 文档自动化 MCP 服务器,通过 Claude Code 连接并创建、编辑 DOCX 文档。

功能特性

  • ✅ 通过 MCP 协议提供 DOCX 文档创建和编辑功能
  • ✅ 支持自定义 XML 语法(xl-p, xl-table, xl-span 等)
  • ✅ 基于模板的文档生成
  • ✅ 支持模板变量和数据绑定
  • ✅ 与 Claude Code 无缝集成

安装

npm install

配置 Claude Code

Windows

在 Claude Code 的配置文件中添加 MCP 服务器配置。配置文件通常位于:

  • %APPDATA%\Claude\claude_desktop_config.json

添加以下配置:

{
  "mcpServers": {
    "docx-mcp-server": {
      "command": "node",
      "args": ["D:/git/libs/docx-mcp-server/index.js"]
    }
  }
}

macOS/Linux

配置文件通常位于:

  • ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)
  • ~/.config/Claude/claude_desktop_config.json (Linux)
{
  "mcpServers": {
    "docx-mcp-server": {
      "command": "node",
      "args": ["/path/to/docx-mcp-server/index.js"]
    }
  }
}

注意:

  • 请将路径替换为您的实际项目路径
  • 使用绝对路径而不是相对路径
  • 路径中的反斜杠需要使用正斜杠或转义

使用方法

1. 创建 DOCX 文档

// 通过 MCP 调用 create_docx 工具
{
  "name": "create_docx",
  "arguments": {
    "templatePath": "path/to/template.docx",
    "xmlContent": "<xl-p>Hello World</xl-p>",
    "outputPath": "path/to/output.docx",
    "data": {}
  }
}

2. 编辑 DOCX 文档

// 通过 MCP 调用 edit_docx 工具
{
  "name": "edit_docx",
  "arguments": {
    "docxPath": "path/to/document.docx",
    "xmlContent": "<xl-p>Updated content</xl-p>",
    "outputPath": "path/to/output.docx"
  }
}

3. 渲染 XML

// 通过 MCP 调用 render_xml 工具
{
  "name": "render_xml",
  "arguments": {
    "xmlContent": "<xl-p style=\"align:center;font-size:32;\">Title</xl-p>"
  }
}

4. 获取 XML 语法参考

// 通过 MCP 调用 get_xml_reference 工具
{
  "name": "get_xml_reference",
  "arguments": {}
}

XML 语法示例

段落

<xl-p>普通段落</xl-p>
<xl-p style="align:center;font-size:32;font-weight:bold;">居中加粗标题</xl-p>

文本样式

<xl-p>这是<xl-span style="font-weight:bold;color:FF0000;">红色加粗</xl-span>文本</xl-p>

表格

<xl-table grid="3000/3000/3000" style="align:center;">
  <xl-tr>
    <xl-tc><xl-p>列1</xl-p></xl-tc>
    <xl-tc><xl-p>列2</xl-p></xl-tc>
    <xl-tc><xl-p>列3</xl-p></xl-tc>
  </xl-tr>
</xl-table>

项目结构

docx-mcp-server/
├── index.js                 # MCP 服务器主文件
├── package.json            # 项目配置
├── xml_syntax_reference.txt # XML 语法参考
├── utils/                  # 工具类
│   ├── FakeZip.js         # ZIP 文件操作
│   ├── WordFile.js        # Word 文档操作
│   ├── XmlCompiler.js     # XML 编译器
│   ├── XmlTree.js         # XML 树操作
│   ├── RelationMixin.js  # 关系映射
│   └── Sheet.js           # Sheet 类
└── processors/            # 处理器
    ├── paragraphProcessor.js  # 段落处理器
    └── tableProcessor.js      # 表格处理器

依赖

  • @modelcontextprotocol/sdk: MCP SDK
  • @xmldom/xmldom: XML DOM 操作
  • adm-zip: ZIP 文件处理
  • nunjucks: 模板引擎

开发

# 启动服务器(用于测试)
npm start

# 或直接运行
node index.js

测试

您可以通过以下方式测试 MCP 服务器:

  1. 测试导入

    node -e "import('./index.js')"
  2. 在 Claude Code 中使用

    • 重启 Claude Code 以加载 MCP 配置
    • 在对话中,Claude 可以调用 create_docxedit_docx 等工具

示例对话

用户: "请创建一个 DOCX 文档,包含标题和一段文字"

Claude: [调用 create_docx 工具]

  • templatePath: 指向您的模板文件
  • xmlContent: <xl-p style="align:center;font-size:32;font-weight:bold;">标题</xl-p><xl-p>这是一段文字。</xl-p>
  • outputPath: 输出文件路径

注意事项

  1. 模板文件: 确保您有一个有效的 DOCX 模板文件
  2. 路径格式: Windows 路径使用正斜杠或双反斜杠
  3. 权限: 确保对输出目录有写入权限
  4. 编码: XML 内容使用 UTF-8 编码

许可证

ISC