Skip to main content
Glama

MD2Doc

将 Markdown 文件转换为符合公文格式规范的 Word (.docx) 文件。

功能

  • 基于 pandoc + python-docx 的 Markdown → Word 转换

  • 内置中国公文格式规范(黑体标题、仿宋正文、固定行距 28 磅等)

  • 支持通过格式要求文件自定义样式

  • 支持 HTML 表格转换(含 colspan/rowspan 合并单元格)

  • 自动处理东亚字体、图片行距、表格自动适配

  • MCP Server:可在 Claude Code 中直接调用转换和分析工具

  • 语义分析:检查文档结构和内容,生成修改建议报告

  • Markdown → Excel:将文档中的 HTML/管道表格转换为带样式的 .xlsx(微软雅黑、细边框、合并单元格、自动列宽行高)

Related MCP server: Word MCP Server

安装

环境要求

  • Python >= 3.12

  • pandoc(需在 ~/.local/bin/pandoc 或 PATH 中)

安装依赖

git clone <repo-url>
cd md2doc
uv sync

CLI 命令行使用

基本用法

# 使用默认公文格式转换
uv run python scripts/md2docx.py <input.md>

# 指定输出路径
uv run python scripts/md2docx.py <input.md> -o output.docx

# 跳过格式设置(纯 pandoc 输出)
uv run python scripts/md2docx.py <input.md> --no-format

自定义格式

# 使用自定义格式要求文件
uv run python scripts/md2docx.py <input.md> -f 格式要求.md

# 叠加参考模板(模板样式覆盖格式要求)
uv run python scripts/md2docx.py <input.md> -f 格式要求.md -r template.docx

格式要求文件格式

参照项目根目录下的 格式要求.md

## H1(一级标题)
- 字体:黑体,三号,加粗
- 对齐方式:左对齐
- 行距:固定值28磅
- 间距:段前0行,段后0行
- 大纲级别:1级
- 特殊格式:无

## H2(二级标题)
- 字体:仿宋_GB2312,小三,加粗
- 对齐方式:左对齐
- 行距:固定值28磅
- ...

## 正文
- 字体:仿宋_GB2312,四号
- 对齐方式:两端对齐
- 行距:固定值28磅
- 特殊格式:首行缩进2字符

## 表格
- 字体:仿宋_GB2312,五号
- 对齐方式:居中对齐
- 行距:单倍行距

支持的字号:三号(16pt)、小三(15pt)、四号(14pt)、小四(12pt)、五号(10.5pt)、小五(9pt)


MCP Server

md2doc 提供 MCP(Model Context Protocol)服务器,可在 Claude Code 中直接使用。

配置 MCP 服务器

~/.claude.jsonmcpServers 中添加:

{
  "mcpServers": {
    "md2doc": {
      "type": "stdio",
      "command": "uv",
      "args": [
        "run",
        "--directory",
        "/path/to/md2doc",
        "md2doc-mcp"
      ]
    }
  }
}

/path/to/md2doc 替换为实际的项目路径。配置后重启 Claude Code 即可生效。使用 /mcp 命令查看是否加载成功。

可用工具

1. convert_markdown_to_docx — 转换 Markdown 为 Word

将 Markdown 文件转换为符合公文格式规范的 .docx 文件。

参数

类型

必填

说明

input_path

string

输入的 Markdown 文件绝对路径

output_path

string

输出 .docx 路径,默认为 <输入目录>/<文件名>.docx

format_spec

string

格式要求 Markdown 文件路径(如 格式要求.md)

reference_docx

string

参考 .docx 模板,样式会叠加在格式要求之上

extract_media

string

提取媒体文件的目标目录

skip_format

bool

设为 true 跳过所有格式设置(纯 pandoc 输出)

no_cache_template

bool

设为 true 强制重新生成缓存的参考模板

格式设置的优先级:未指定 format_spec 时,自动使用项目根目录下的 格式要求.md(可通过修改 mcp_server.py 中的 DEFAULT_FORMAT_SPEC_PATH 配置);如果该文件也不存在,则使用内置的默认公文格式。

使用示例对话

用户:帮我把 report.md 转成 Word 文档

Claude:好的。你有特定格式要求吗?可以提供格式要求的 markdown 文件,或者参考的 docx 模板。

用户:没有特殊要求,用默认格式就行

Claude:调用 convert_markdown_to_docx,使用默认格式转换

用户:用 custom-format.md 的格式转换

Claude:调用 convert_markdown_to_docx,format_spec="custom-format.md"

2. convert_markdown_to_xlsx — 转换 Markdown 为 Excel

将 Markdown 文档中的表格转换为带样式的 .xlsx 文件。按文档顺序提取所有 HTML <table> 与 Markdown 管道表格,每个表格生成一个 worksheet

参数

类型

必填

说明

input_path

string

输入的 Markdown 文件绝对路径

output_path

string

输出 .xlsx 路径,默认为 <输入目录>/<文件名>.xlsx

font_name

string

字体名(默认微软雅黑)

body_size

int

正文字号(默认 11)

保留的格式

  • HTML 表格:colspan/rowspan 合并单元格、<b> 粗体、<th> 表头、<br> 换行、style 中的 text-align 对齐

  • 管道表格:首行为表头;分隔行 :--- / ---: / :---: 决定列对齐

  • 样式:微软雅黑、细边框、表头加粗 + 浅灰底纹、垂直居中、自动换行、按内容估算列宽与行高

  • Sheet 名取表格前最近的 # 标题,否则为 表格N

使用示例对话

用户:把这个课程大纲 md 转成 Excel

Claude:调用 convert_markdown_to_xlsx,自动生成 .xlsx

用户:帮我把 report.md 里所有表格导出成 xlsx

Claude:调用 convert_markdown_to_xlsx,输出每个表格一个 sheet

3. analyze_and_suggest — 文档语义分析

分析 Markdown 文档的结构和内容,在同目录下生成 xx-修改建议.md 修改建议报告。

参数

类型

必填

说明

input_path

string

输入的 Markdown 文件绝对路径

分析类别(共 6 类):

类别

检查内容

标题层级问题

层级跳跃(H1→H3)、缺少主标题、多个 H1、标题过长

必要章节检查

公文常见要素:标题模式、发文机关、日期、附件/附录

格式问题

失效的图片引用、HTML 表格标签不匹配

内容问题

空章节、占位符文本、重复段落、段落过长

编号连续性

编号间隙、重新编号、格式不一致

中文标点规范

半角标点、英文引号、缺少句末标点

输出文件格式

# 修改建议 — report.md

> 生成时间: 2026-06-28 14:30:00
> 分析文件: /path/to/report.md
> 总行数: 1523
> 发现问题: 12 项(错误 2 项,警告 7 项,提示 3 项)

---

## 一、标题层级问题(2项)

| 行号 | 严重度 | 问题描述 |
|------|--------|----------|
| 42   | 警告   | 标题层级跳跃: H1 → H3,缺少 H2 |
| --   | 错误   | 缺少一级标题 (H1) |

## 二、必要章节检查(1项)

| 行号 | 严重度 | 问题描述 |
|------|--------|----------|
| --   | 警告   | 未检测到「日期信息」,建议检查是否遗漏 |
...

使用示例对话

用户:帮我检查一下这篇文档有什么问题

Claude:调用 analyze_and_suggest,分析后返回修改建议文件路径和问题摘要


MCP 服务器配置项

默认格式要求文件的路径在 src/md2doc/mcp_server.py 中配置:

# 修改此行即可更改默认格式
DEFAULT_FORMAT_SPEC_PATH: str | None = str(
    Path(__file__).parent.parent.parent / "格式要求.md"
)
  • 设为其他路径:使用该路径的格式要求文件

  • 设为 None:跳过加载默认格式文件,直接使用内置的硬编码默认格式


项目结构

md2doc/
├── scripts/
│   ├── md2docx.py          # Markdown → Word CLI 转换脚本(独立运行)
│   └── md2xlsx.py          # Markdown → Excel CLI 转换脚本(独立运行)
├── src/md2doc/
│   ├── __init__.py          # 包元数据
│   ├── converter.py         # Markdown → Word 核心包装器(异常驱动的 API)
│   ├── xlsx_converter.py    # Markdown → Excel 核心包装器(异常驱动的 API)
│   ├── analyzer.py          # 语义分析引擎
│   └── mcp_server.py        # MCP 服务器入口
├── 格式要求.md               # 默认公文格式规范
├── 测试用例/                 # 测试文档
│   ├── AI场景落地全流程实战.md
│   └── 模版.xlsx
└── pyproject.toml

默认公文格式规范

样式

字体

字号

加粗

对齐

行距

缩进

H1(一级标题)

黑体

三号 16pt

左对齐

固定 28pt

H2(二级标题)

仿宋_GB2312

小三 15pt

左对齐

固定 28pt

H3(三级标题)

仿宋_GB2312

四号 14pt

左对齐

固定 28pt

正文

仿宋_GB2312

四号 14pt

两端对齐

固定 28pt

首行缩进 2 字符

表格

仿宋_GB2312

五号 10.5pt

居中

单倍行距

许可证

MIT

Available Tools

3 tools
analyze_and_suggestA

Analyze a Markdown document and generate modification suggestions.

Performs semantic analysis across six categories:

  1. Heading hierarchy — skipped levels, missing/multiple H1, long titles

  2. Required 公文 sections — expected elements in Chinese government docs

  3. Format issues — broken image references, HTML table problems

  4. Content issues — empty sections, placeholder text, duplicates, long paragraphs

  5. Numbered list continuity — gaps and restarts in ordered lists

  6. Chinese punctuation — half-width marks, missing sentence endings

Generates a structured report at /-修改建议.md with findings organized by category, each showing line numbers, severity, and specific suggestions.

Args: input_path: Absolute path to the input Markdown file.

Returns: Summary string with input path, suggestions file path, and issue count.

ParametersJSON Schema
NameRequiredDescriptionDefault
input_pathYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.5/5.0
Behavior4/5

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

The description discloses that the tool generates an output file at a specific path with a defined naming convention, and returns a summary string. It also details six analysis categories, providing transparency about the scope of analysis. No annotations are provided, so the description must carry the behavioral burden, which it largely does.

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 well-structured with a brief introductory sentence followed by a bulleted list of analysis categories, and ends with parameter and return documentation. Every sentence earns its place with no redundancy or filler.

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

Completeness5/5

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

Given the tool has only 1 parameter, no annotations, an output schema, and two clearly different sibling tools, the description is complete. It explains what the tool does, what it analyzes, what it produces, and the output format.

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 description adds meaning beyond the input schema by specifying the parameter is an absolute path and that the file must be a Markdown file. With schema description coverage at 0%, the description effectively documents the single parameter. A baseline of 4 is appropriate because there is only 1 parameter and the description covers it well.

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 uses a specific verb ('Analyze and generate') and resource ('Markdown document'), clearly distinguishing it from sibling tools that convert to other formats. The six bulleted categories provide a detailed breakdown of what the analysis covers.

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 explicitly states the tool performs semantic analysis and generates a structured report, implying its use case as a quality-check step. It doesn't explicitly mention when not to use it versus alternatives, which is acceptable given the sibling tools have very different purposes (format conversion).

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

convert_markdown_to_docxA

Convert a Markdown file to Word (.docx) with formatting.

Applies Chinese government document formatting (公文格式规范) by default:

  • Headings: 黑体 (H1 三号16pt, H2 小三15pt, H3 四号14pt) bold, left-aligned

  • Body: 仿宋_GB2312 四号14pt, justified, 2-char first-line indent

  • Tables: 仿宋_GB2312 五号10.5pt, center-aligned

  • Line spacing: fixed 28pt for body/headings, single for tables

Args: input_path: Absolute path to the input Markdown file. output_path: Output .docx path. Defaults to /.docx. format_spec: Path to a format description markdown file (like 格式要求.md). Overrides the default format. The file defines fonts, sizes, spacing, and alignment per Word style (H1/H2/H3/正文/表格). reference_docx: Path to a .docx template whose styles overlay on top of the format spec. Useful for matching an existing document's styles. extract_media: Directory to extract media files to. skip_format: If True, bypass ALL formatting (pure pandoc output). no_cache_template: If True, force regeneration of the cached reference template (needed when format spec changes). auto_suggest: If True, automatically generate a modification suggestions report (xx-修改建议.md) after conversion. The report covers heading hierarchy, required sections, format issues, content problems, list continuity, and Chinese punctuation.

Returns: Summary string with input path, output path, file size, and optionally the modification suggestions report path and issue count.

ParametersJSON Schema
NameRequiredDescriptionDefault
input_pathYes
format_specNo
output_pathNo
skip_formatNo
auto_suggestNo
extract_mediaNo
reference_docxNo
no_cache_templateNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.5/5.0
Behavior4/5

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

With no annotations provided, the description carries full burden. It transparently discloses the default formatting behavior, the option to specify a custom format spec, reference docx overlay, and the ability to skip formatting entirely. It also explains caching behavior and auto-suggest report generation. However, it does not state if the operation is destructive, requires authentication, or has rate limits, though conversion tools typically are non-destructive and the output is a new file.

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

Conciseness4/5

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

The description is well-structured with a brief introductory sentence, detailed default formatting specs, then a clear parameter list with explanations. It is somewhat verbose in the formatting details but each section adds value. The parameter list is front-loaded after the formatting block, which is appropriate. Could be slightly more concise by reducing formatting specifics to a summary, but the detail is helpful for this domain.

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

Completeness5/5

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

Given the complexity (8 parameters, 1 required), zero schema coverage, and the presence of an output schema (which is noted but not needed since the description explains the return value), the description is complete. It covers all parameters, provides usage context, explains default behavior, and describes the return value. The automatic detection of the output schema is not required due to the detailed summary documentation.

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

Parameters5/5

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

Schema description coverage is 0%, so the description completely compensates by documenting all 8 parameters with clear explanations of their purpose, defaults, and behavior (e.g., 'skip_format: If True, bypass ALL formatting (pure pandoc output)'). It adds meaning beyond the schema, such as the effect of 'no_cache_template' and the auto-suggest report details.

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 tool converts Markdown to Word with formatting, identifies the default Chinese government formatting, and provides detailed style specs. It is specific about the verb ('Convert'), resource ('Markdown file to Word (.docx)'), and distinguishes from siblings like 'convert_markdown_to_xlsx' which converts to a different format.

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 Markdown to .docx with specific formatting) and explains the default formatting. It doesn't explicitly state when not to use it or mention alternatives among siblings, but the specificity of the conversion and the siblings (e.g., xlsx conversion, analysis) implies when this is appropriate. It could be improved by stating it's for Chinese government document formatting and not for simple conversions.

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

convert_markdown_to_xlsxA

Convert Markdown tables to an Excel (.xlsx) file.

Extracts every HTML and Markdown pipe table from the document (in document order) and writes each to its own worksheet. Preserves colspan/rowspan merged cells, inline bold, and text-align alignment.

Styling:

  • Font: 微软雅黑 (11pt body), thin borders on all cells

  • Header cells (HTML or the first row of a pipe table): bold + light gray fill

  • All cells: vertical center, wrap text

  • Column widths and row heights estimated from content

Args: input_path: Absolute path to the input Markdown file. output_path: Output .xlsx path. Defaults to /.xlsx. font_name: Optional font name override (default 微软雅黑). body_size: Optional body font size override (default 11).

Returns: Summary string with input path, output path, file size, and sheet count.

ParametersJSON Schema
NameRequiredDescriptionDefault
body_sizeNo
font_nameNo
input_pathYes
output_pathNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.7/5.0
Behavior5/5

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

The description thoroughly discloses behavioral traits: it extracts tables in document order, creates separate worksheets, preserves styling (merged cells, bold, alignment), and details font, header, cell formatting, and column width estimation. Since no annotations are provided, this comprehensive disclosure fully covers the tool's behavior beyond what annotations would have provided.

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 exceptionally concise and well-structured: a brief overview sentence, bullet-pointed styling details, and a labeled Args section with clear parameter explanations. Every sentence adds value without redundancy, and the front-loaded overview immediately conveys the tool's core function.

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

Completeness5/5

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

Given the tool has 4 parameters and no annotations, the description is remarkably complete. It explains the conversion process, styling, default behaviors, and return value (summary string). With an output schema present, the description doesn't need to detail return values further, making this fully adequate for an AI agent to use correctly.

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 description adds significant meaning beyond the plain input schema: it explains input_path's purpose (absolute path to Markdown file), output_path's default calculation, and the optional overrides for font_name and body_size. With 0% schema description coverage, the description brilliantly compensates by detailing the exact role of each parameter, though it could link parameters to specific parts of the text more explicitly.

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 tool converts Markdown tables to an .xlsx file, specifying both content sources (HTML <table> and Markdown pipe tables) and the output format (Excel). It distinguishes itself from siblings like convert_markdown_to_docx by focusing on .xlsx 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 implies when to use this tool (when needing to convert Markdown tables to Excel), but doesn't explicitly state when not to use it or provide alternatives. However, the sibling list includes convert_markdown_to_docx, offering a clear differentiation without explicit when-not language.

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. Dates show when Glama detected each change.

  1. 3 tool updatesv0.1.0
    • First observedanalyze_and_suggest
    • First observedconvert_markdown_to_docx
    • First observedconvert_markdown_to_xlsx

TDQS

A4.4/5.0
Disambiguation5/5

Each tool has a clearly distinct purpose: converting to docx, converting to xlsx, and analyzing the document. There is no overlap or ambiguity between them.

Naming Consistency4/5

Two tools follow a consistent 'convert_markdown_to_*' pattern, but the third tool 'analyze_and_suggest' breaks that pattern, using a different verb structure. This minor inconsistency prevents a perfect score.

Tool Count4/5

Three tools is a small but reasonable set for the server's purpose. Each tool serves a clear function, and the count feels appropriate for the focused scope of Markdown-to-document conversion and analysis.

Completeness3/5

The server covers the core conversion to Word and Excel, plus analysis, but lacks other common output formats like PDF or HTML. For a document conversion tool, this is a notable gap, though the specialized Chinese government formatting focus partly justifies the limitation.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/fengredrum/md2doc'

If you have feedback or need assistance with the MCP directory API, please join our Discord server