Skip to main content
Glama

MD-DOCX 转换器

一个用于 Markdown (.md) 和 Microsoft Word (.docx) 之间双向转换的 Python 工具。旨在方便在 Word 文档与 Claude、ChatGPT 和 GitHub Copilot 等 AI 工具之间迁移内容。

功能特点

  • .md 转换为 .docx,并保持正确的标题层级(标题、标题 1–9)

  • .docx 转换为干净的 GitHub Flavored Markdown (GFM)

  • 通过简单的桌面快捷方式运行 — 无需命令行知识

  • 支持标题、粗体/斜体/删除线、列表、任务列表、表格、引用块、代码块、图像和超链接

请参阅 MarkdownSyntax.md 以获取完整的元素映射以及关于哪些内容被保留、近似处理或丢弃的说明。

Related MCP server: Document Reading and Converter Tool

系统要求

  • Windows 10/11

  • Python 3.11+

  • 以下 Python 包(通过 pip 安装):

pip install markdown-it-py python-docx

设置

1. 克隆仓库

git clone https://github.com/cjwpenner/md-docx-converter.git
cd md-docx-converter

2. 安装依赖

pip install markdown-it-py python-docx

3. 创建桌面快捷方式

pip install pywin32
python create_shortcut.py

这将在您的 Windows 桌面上创建一个 MD-DOCX Converter 快捷方式。pywin32 仅用于创建快捷方式 — 运行转换器本身不需要它。

4. 运行转换器

双击桌面上的 MD-DOCX Converter。控制台窗口将打开并提示:

MD ↔ DOCX Converter
--------------------
Enter file path:

粘贴或输入您的 .md.docx 文件的完整路径并按回车键。转换后的文件将保存在同一目录下,并替换扩展名。

您也可以直接从命令行运行:

python md_docx_converter/converter.py

转换说明

标题层级

标题级别的映射取决于上下文:

  • MD → DOCX:如果文档中只有一个 #,它将成为 Word 的 标题 (Title)。所有其他标题下移一级。如果有多个 # 标题,它们都将成为 标题 1 (Heading 1),且没有标题样式。

  • DOCX → MD:如果文档具有 标题 (Title) 样式,它将变为 #。所有标题相应上移。如果没有标题样式,标题 1 (Heading 1) 将变为 #

有损元素

没有 Markdown 等效项的 Word 格式将近似处理为 粗体

Word 格式

Markdown 输出

下划线

**粗体**

高亮

**粗体**

小型大写字母

**粗体**

字体颜色

去除(保留文本)

图像

  • DOCX → MD:嵌入的图像会被提取到输出 .md 文件旁边的 {filename}_images/ 文件夹中。

  • MD → DOCX:通过相对路径引用的图像会被重新嵌入。缺失的图像将显示为 [image not found: path]

Claude Code 集成

此工具可以作为 插件(推荐 — 两条命令即可完成所有操作)或独立的 MCP 服务器(用于手动设置或 Claude Desktop)与 Claude Code 集成。

选项 A:Claude Code 插件(推荐)

该插件捆绑了 MCP 服务器配置和一个 /convert 技能。在 Claude Code 中运行以下两条命令:

/plugin marketplace add cjwpenner/md-docx-converter
/plugin install md-docx-converter@md-docx-converter

就是这样 — 无需进一步配置。运行 /reload-plugins 后,Claude 将获得转换工具,您可以直接调用该技能:

/md-docx-converter:convert path/to/file.md
/md-docx-converter:convert path/to/report.docx

或者直接自然地提问:“Convert this to a Word document”,Claude 将自动使用这些工具。

选项 B:仅 MCP 服务器(手动设置)

如果您只想使用 MCP 工具而不需要插件,或者您正在配置 Claude Desktop 而不是 Claude Code,请使用此选项。

安装包:

pip install mcp-md-docx

Claude Code — 注册 MCP 服务器:

claude mcp add md-docx-converter --transport stdio -- uvx mcp-md-docx

Claude Desktop — 添加到 %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "md-docx-converter": {
      "type": "stdio",
      "command": "uvx",
      "args": ["mcp-md-docx"]
    }
  }
}

公开的工具

工具

功能

read_docx

读取 .docx 文件 — 将完整的 Markdown 文本返回给 AI

write_docx

根据 AI 编写的 Markdown 文本创建 .docx

convert_md_file_to_docx

将磁盘上的 .md 文件转换为 .docx

convert_docx_file_to_md

将磁盘上的 .docx 文件转换为 .md

配置完成后,您可以说:

  • “Read report.docx and summarise it”

  • “Turn this into a Word document and save it to my Desktop”

  • “Convert all the bullet points in notes.docx into a table”

项目结构

md_docx_converter/
├── converter.py       # CLI entry point
├── md_to_docx.py      # Markdown → Word conversion
├── docx_to_md.py      # Word → Markdown conversion
├── heading_mapper.py  # Heading hierarchy pre-scan logic
├── image_handler.py   # Image extraction and embedding
└── launch.pyw         # Desktop shortcut launcher
mcp_md_docx/
├── server.py          # MCP server (four tools)
└── __main__.py        # Entry point for python -m mcp_md_docx
create_shortcut.py     # One-time shortcut setup script
pyproject.toml         # PyPI packaging config

许可证

本项目采用 GNU 通用公共许可证 v3.0 (GPLv3) 授权。您可以自由使用、修改和分发本软件,前提是任何衍生作品也必须在相同的许可证下分发。

请参阅 LICENSE 获取完整的许可证文本。

第三方库

本项目依赖于以下开源库,均采用 MIT 许可证:

用途

许可证

mcp

模型上下文协议服务器框架

MIT

markdown-it-py

GitHub Flavored Markdown 解析器

MIT

python-docx

读取和写入 Word .docx 文件

MIT

完整的许可证文本已在 THIRD_PARTY_NOTICES.md 中转载。

Available Tools

4 tools
convert_docx_file_to_mdA

Convert a Word (.docx) file to a Markdown (.md) file. The output is saved alongside the input file. Returns the Markdown content.

ParametersJSON Schema
NameRequiredDescriptionDefault
pathYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden. It discloses key behaviors: output file location (saved alongside input) and return value (Markdown content). However, it doesn't mention error handling, file size limits, format compatibility, or permission requirements, leaving gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences with zero waste: first states core function, second adds crucial behavioral details (output location and return value). It's front-loaded with the primary purpose and efficiently covers additional context without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (file conversion), no annotations, and an output schema (which handles return values), the description is mostly complete. It covers purpose and key behaviors but lacks parameter details and some operational constraints, leaving minor gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It doesn't explain the 'path' parameter at all—no details on format, expected input type, or constraints. The description adds no parameter semantics beyond what the bare schema provides, failing to address the coverage gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action (convert), source format (.docx), target format (.md), and distinguishes from siblings like convert_md_file_to_docx (reverse operation) and read/write_docx (different actions). It precisely defines the tool's function without ambiguity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context (converting Word to Markdown) but doesn't explicitly state when to use this vs. alternatives like convert_md_file_to_docx or read_docx. It provides clear operational context but lacks explicit guidance on tool selection or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

convert_md_file_to_docxA

Convert a Markdown (.md) file to a Word (.docx) file. The output is saved alongside the input file with the same name and .docx extension.

ParametersJSON Schema
NameRequiredDescriptionDefault
pathYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.2/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden. It discloses the output location behavior (saved alongside input with same name and .docx extension), which is valuable. However, it doesn't mention error handling, file size limits, formatting preservation, or authentication requirements that might be relevant for a file conversion tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences, zero waste. First sentence states the core purpose, second sentence provides crucial behavioral detail about output location. Perfectly front-loaded and appropriately sized for this simple tool.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has an output schema (which handles return values), a single parameter, and no annotations, the description is reasonably complete. It covers the conversion purpose and output location behavior. However, for a file operation tool, additional context about error conditions or limitations would make it more complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0% (parameter 'path' has no description in schema), so the description must compensate. While it doesn't explicitly explain the 'path' parameter, the context makes it clear this should be the path to a Markdown file. The description adds meaning by specifying the file type (.md) and the conversion outcome, though it could be more explicit about parameter expectations.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action (convert), source format (Markdown .md file), and target format (Word .docx file). It distinguishes from sibling tools like convert_docx_file_to_md (reverse conversion) and read_docx/write_docx (different operations).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool (converting from Markdown to Word format). It doesn't explicitly state when not to use it or name specific alternatives, but the sibling tool names make the distinction obvious (e.g., use convert_docx_file_to_md for reverse conversion).

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

read_docxA

Read a Word (.docx) document and return its full content as Markdown text. Use this when the user asks you to read, summarise, edit, or work with a Word document.

ParametersJSON Schema
NameRequiredDescriptionDefault
pathYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.2/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses the tool's behavior by stating it reads and returns content as Markdown, but lacks details on error handling, file size limits, or performance aspects. It adds basic context but does not fully compensate for the absence of annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose in the first sentence, followed by usage guidelines in the second. Both sentences are essential and waste no words, making it highly efficient and easy to scan.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (one parameter) and the presence of an output schema (which handles return values), the description is mostly complete. It covers purpose and usage well but could benefit from more behavioral details like error cases or limitations to fully compensate for the lack of annotations.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 0%, so the description must compensate. It implies the 'path' parameter is for the document location but does not specify format or constraints. With only one parameter, the baseline is high, and the description adds some meaning by linking it to Word documents, though more detail would improve clarity.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Read a Word (.docx) document') and the resource type, with a precise outcome ('return its full content as Markdown text'). It distinguishes from siblings like 'convert_docx_file_to_md' by emphasizing reading rather than conversion, and from 'write_docx' by focusing on input rather than output.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use this tool ('when the user asks you to read, summarise, edit, or work with a Word document'), which covers common scenarios. However, it does not specify when not to use it or mention alternatives like 'convert_docx_file_to_md' for different purposes, leaving some ambiguity.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

write_docxA

Convert Markdown text to a Word (.docx) document and save it to disk. Use this when the user asks you to create or save a Word document from text or Markdown content. The output_path should be an absolute path ending in .docx.

ParametersJSON Schema
NameRequiredDescriptionDefault
markdownYes
output_pathYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses that the tool saves to disk (a behavioral trait) and specifies the output path format, but lacks details on error handling, file overwriting behavior, or performance characteristics. It adequately covers the core action but misses some operational nuances.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose, followed by usage guidance and parameter specifics in three concise sentences. Each sentence adds value without redundancy, making it efficient and well-structured for quick comprehension.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (2 parameters, no annotations, but has an output schema), the description is mostly complete. It covers purpose, usage, and parameter semantics adequately. The output schema likely handles return values, so the description doesn't need to explain those. Minor gaps remain in behavioral details like error handling.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description must compensate. It explains that 'markdown' is the input text and 'output_path' should be an absolute path ending in .docx, adding crucial semantic context beyond the bare schema. However, it doesn't detail markdown formatting support or path validation rules.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Convert Markdown text to a Word (.docx) document and save it to disk') and distinguishes it from siblings like 'convert_md_file_to_docx' (which likely processes files rather than text) and 'read_docx' (which reads rather than writes). It uses precise verbs and specifies the resource type.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly states when to use this tool ('when the user asks you to create or save a Word document from text or Markdown content'), providing clear context for its application. It also implies differentiation from siblings by focusing on text input rather than file processing.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

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

  1. 4 tool updatesv0.1.2
    • First observedconvert_docx_file_to_md
    • First observedconvert_md_file_to_docx
    • First observedread_docx
    • First observedwrite_docx

TDQS

A3.9/5.0

Scored across 4 tools

Disambiguation2/5

The tools have significant overlap in purpose, particularly between convert_docx_file_to_md and read_docx (both convert DOCX to Markdown), and between convert_md_file_to_docx and write_docx (both convert Markdown to DOCX). The descriptions attempt to differentiate use cases (file conversion vs. content reading/writing), but an agent could easily misselect between these pairs due to unclear functional boundaries.

Naming Consistency4/5

The tool names follow a consistent verb_noun pattern with snake_case throughout (e.g., convert_docx_file_to_md, read_docx). The only minor deviation is that some names include 'file' while others do not, but overall the naming is predictable and readable.

Tool Count3/5

With 4 tools, the count is reasonable for a conversion-focused server, but it feels borderline thin given the overlapping functionality. A more streamlined set might have 2-3 tools instead, as the current count includes redundancy that doesn't add clear value to the surface.

Completeness4/5

For a DOCX-Markdown conversion domain, the tools cover the core bidirectional conversion operations and basic file handling. However, there are minor gaps, such as no tool for editing or manipulating the content in between conversions, which agents might need to work around by combining tools or external processing.

Maintenance

ActivitySlowing
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

Appeared in Searches