Word文档 MCP服务器
一个基于TypeScript的快速MCP服务器,用于从Markdown或结构化内容创建专业的Word文档。
🚀 以Markdown为先的工作流程 - 只需编写自然的Markdown,即可在约300毫秒内生成专业的Word文档!
快速设置
- 下载
index.js来自 发布 并保存到~/mcp-servers/docx/index.js
- 配置 Claude Desktop - 编辑
claude_desktop_config.json:
- macOS: ~/Library/Application Support/Claude/claude_desktop_config.json - Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"mcp-server-docx": {
"command": "node",
"args": ["/Users/YOUR_USERNAME/mcp-servers/docx/index.js"]
}
}
}将路径替换为你保存文件的位置(Windows:使用 C:\\Users\\... (使用双反斜杠)
- 重启 Claude Desktop(可译为“Claude桌面版”或根据具体语境简化为“Claude桌面”)
- 测试 通过询问克劳德:
Create a Word document at /tmp/test.docx from this markdown:
# Hello World
This is my **first** Word document with *markdown*!
## Features
- Easy to use
- Fast generation
- Professional formatting你应该得到一个格式正确的Word文档 /tmp/test.docx!
Build from Source (for contributors)
git clone
cd mcp-server-docx
nvm install && npm install && npm run build使用 dist/index.js 在你的 Claude 配置中,而不是使用下载的包。
特点/功能
🎯 纯Markdown模式(推荐)
创建Word文档的最简单方法 - 就像你平时一样,写自然的Markdown就好!
只需用纯Markdown语法告诉Claude你想要什么:
Create a Word document at /tmp/my-resume.docx from this markdown:
# JANE SMITH
jane@example.com | (555) 123-4567
## PROFESSIONAL SUMMARY
I am a **senior software engineer** with *10+ years* of experience building scalable web applications.
> "Jane is an exceptional technical leader and mentor." — Former Manager
## SKILLS
- Expert in **TypeScript**, **React**, and **Node.js**
- Strong experience with **AWS** cloud architecture
- Passionate about **clean code** and **best practices**
---
## WORK EXPERIENCE
### Senior Engineer at Tech Corp (2020-Present)
Key achievements:
1. Designed and implemented **microservices architecture**
2. Reduced system latency by *40%*
3. Mentored team of 5 junior engineers
### Software Engineer at Startup Inc (2015-2020)
- Built MVP from scratch using **React** and **TypeScript**
- Implemented REST API with **Express** and **PostgreSQL**你将获得:
- ✅ 专业Word文档生成时间约300毫秒
- ✅ 正确的标题样式并带有边框(H1,H2)
- ✅ 加粗和斜体格式
- ✅ 项目符号列表和编号列表
- ✅ 引文使用斜体格式
- ✅ 自动处理水平线
- ✅ 段落之间间距适当
- ✅ 采用 Times New Roman 字体(专业默认字体)
支持的Markdown格式:
######标题(H1/H2 有下边框)**bold**和*italic*内联格式化[text](url)用于可点击的超链接-或者*用于项目符号列表1.2.用于编号列表> quote用于长篇引用(以斜体显示)---***___水平规则(显示为线条)- 用于各部分之间间距的空行
幕后花絮: 用途 create_document_from_markdown 工具
______________________________________________________________________
🎨 Markdown自定义样式
想要Helvetica字体而不是Times New Roman?需要不同的字体大小吗? - 轻松自定义外观!
你可以通过传递一个参数来覆盖默认样式 styles 对象:
Create a Word document at /tmp/my-resume.docx from this markdown:
# JANE SMITH
## Professional Summary
I am a senior engineer.
Use these custom styles:
- All headings should be Helvetica
- H1 should be 36pt bold without bottom border
- H2 should be 24pt bold with bottom border
- Paragraphs should be Arial 12pt按元素选择样式选项:
heading1,heading2,heading3,heading4- 控制标题外观paragraph- 普通段落文本bullets- 项目符号列表项ordered- 编号列表项blockquote- 块引用文本(来自> quote)
每个元素可以具有:
fontName- 字体(例如,“Helvetica”,“Arial”,“Times New Roman”)fontSize- 字体大小(以点为单位,例如:12、14、36)bold- 粗体文本(真/假)italic- 斜体文本(真/假)color- 文本颜色以十六进制RGB表示(例如,“FF0000”)borderBottom- 标题的底边框(真/假)
示例样式对象:
styles: {
heading1: { fontName: 'Helvetica', fontSize: 36, bold: true, borderBottom: false },
heading2: { fontName: 'Helvetica', fontSize: 24, bold: true, borderBottom: true },
heading3: { fontName: 'Helvetica', fontSize: 18, bold: true },
paragraph: { fontName: 'Arial', fontSize: 12 },
bullets: { fontName: 'Arial', fontSize: 12 },
ordered: { fontName: 'Arial', fontSize: 12 },
blockquote: { fontName: 'Georgia', fontSize: 12, italic: true }
}默认样式 (在您未提供自定义样式时使用):
- 标题:使用Times New Roman字体,加粗,H1=24磅,H2=18磅,H3/H4=14/12磅
- H1/H2:有下边框,H3/H4:无边框
- 段落/列表:使用 Times New Roman 字体,12 号字
- 引用块:Times New Roman字体,12磅,斜体
专业提示: 您只需指定您想要更改的元素/属性!未指定的元素将使用默认值。
______________________________________________________________________
⚡ 批处理模式与结构化内容
当你需要精细控制时 - 指定确切的字体、大小和颜色
当Markdown不够灵活,且你需要对格式进行精确控制时,请使用此方法:
Create a resume at /tmp/my-resume.docx using create_document_from_content.
Make the name "JANE SMITH" in Helvetica 36pt bold.
Add a "PROFESSIONAL SUMMARY" H2 heading with a bottom border in Helvetica 14pt.
Add a paragraph about my experience in Times New Roman 12pt.
Add a "SKILLS" H2 heading with a bottom border.
Add bullet points for my skills in Times New Roman 12pt.示例结构:
content: [
{
text: 'JANE SMITH', // defaults to paragraph type
format: { fontName: 'Helvetica', fontSize: 36, bold: true },
},
{ text: '' }, // empty paragraph for spacing
{
type: 'heading',
text: 'PROFESSIONAL SUMMARY',
format: { level: 2, borderBottom: true },
},
{
text: 'Software engineer with 10+ years experience...',
format: { fontName: 'Times New Roman', fontSize: 12 },
},
{
type: 'bullets',
items: ['TypeScript & React', 'Node.js & Python', 'AWS & Docker'],
format: { fontName: 'Times New Roman', fontSize: 12 },
},
];内容项目选项:
type:'paragraph'(默认),'heading','bullets','ordered'text对于段落和标题(使用''(用于)间距items用于列表的字符串数组format:fontName,fontSize,bold,italic,color,level(标题),borderBottom(标题)
幕后故事: 用途 create_document_from_content 工具
______________________________________________________________________
📝 在结构化内容中使用Markdown格式
即使在结构化模式下,你也可以使用Markdown风格的格式!
纯Markdown方法和结构化内容都支持内联(编辑/插入) **bold** 并且 *italic* 格式化:
// Markdown formatting works in any text field:
{
text: 'Led **4-engineer team** building *next-gen platform*',
format: { fontSize: 12 }
}
// Also works in list items:
{
type: 'bullets',
items: [
'Expert in **TypeScript** and **React**',
'Passionate about *clean code* and *best practices*'
]
}这会自动转换为带有加粗和斜体段落的正确Word格式。
______________________________________________________________________
贡献与本地发展
安装
git clone
cd mcp-server-docx
nvm install # Use the correct Node.js version from .nvmrc
npm install
npm run build创建发布版本
这个项目使用了GitHub的自动化发布功能。参见 发布说明.md 详情如下。
快速总结:
- 在(软件/系统等)中更新版本
package.json(例如。,npm version patch) - 创建拉取请求(PR)并合并到
main - GitHub Actions 会自动创建一个包含打包内容的发布版本
index.js
发布工作流仅在以下更改时触发:
src/**(不包括测试)package.jsonpackage-lock.json
测试
由(某技术/工具)驱动的包含54项测试的综合测试套件 Vitest(维特斯,但通常直接音译为“维特斯”可能不如保持原英文名直观,因此在技术或开发语境下,一般直接使用“Vitest”这一名称):
npm test # Run tests once
npm run test:watch # Watch mode with fast HMR
npm run test:coverage # Coverage report
npm run test:ui # Visual UI mode测试覆盖率:
- Markdown 解析(标题、列表、块引用、水平线、内联格式、链接)
- 自动会话创建
- 段落、标题和列表格式化
- 在段落、标题和列表中支持链接
- 水平线渲染
- 所有元素类型的颜色格式化
- 批量文档创建
- 错误处理
- 复杂的多章节文档
- 元素之间的间距
演出 所有54项测试在约400毫秒内完成
代码质量
npm run lint # Run ESLint (fails on warnings)
npm run lint:fix # Auto-fix linting issues
npm run format # Format code with Prettier
npm run format:check # Check formatting (CI)
npm run typecheck # TypeScript type checking
npm run ci # Run all checks (lint + format + test + typecheck)标准:
- 启用严格模式的 TypeScript
- ESLint(不允许有任何警告)
- Prettier(使用单引号,2个空格缩进,100字符宽度)
- 所有拉取请求(PR)上的GitHub Actions持续集成(CI)
项目结构
mcp-server-docx/
├── src/
│ ├── __tests__/
│ │ ├── document-manager.test.ts # Document management tests
│ │ └── markdown-parser.test.ts # Markdown parsing tests
│ ├── index.ts # MCP server implementation
│ ├── document-manager.ts # Core document logic
│ ├── markdown-parser.ts # Markdown to content converter
│ └── types.ts # TypeScript type definitions
├── dist/ # Compiled JavaScript
├── vitest.config.ts # Test configuration
├── package.json
├── tsconfig.json
└── README.md______________________________________________________________________
性能与架构
关键绩效指标:
- 单文档创建时间:约300毫秒
- 完整简历处理(批处理模式):约300毫秒 vs 3-5秒(增量处理)vs 约35秒(Python)
- 速度快100倍 相较于Python的实现
- 减少了20-30倍 MCP调用(1次批量调用 vs 20-30次增量调用)
设计原则:
- 批处理操作 - 通过单次MCP调用创建整个文档
- 内存存储 - 文档存储在内存中,直到保存(消除了文件I/O开销)
- 自动会话创建 - 无需显式初始化,立即开始添加内容
- 智能Markdown解析 - 一次性解析,内联处理
**bold**/*italic*支持 - 默认样式 - 自动应用Times New Roman字体,呈现专业外观
- 类型安全 - 完整的TypeScript定义以确保正确性
未来改进方向
- 表格和图片
- 自定义样式定义
- 页眉、页脚和分页符
- 搜索与替换功能
许可证
ISC(国际安全认证/互联网安全中心等,具体含义根据上下文确定)
作者
詹姆斯·梅霍特
______________________________________________________________________
致谢
这个项目是基于两个优秀的开源库构建的:
文档生成: docx(文件扩展名,表示Word文档)
docx.js.org | **** - 一个强大的JavaScript/TypeScript库,用于生成Word文档(.docx文件)。如果没有docx为创建和操作Office Open XML文档提供的坚实基础,这个MCP服务器将无法实现。
Markdown 解析: 备注
remark.js.org(可译为“remark项目官方网站”,但通常直接保留原域名形式,因为网址本身即为明确标识) | **** - 一个由插件驱动的强大Markdown处理器,属于统一集合的一部分。Remark的符合标准的解析功能确保了Markdown到Word文档的准确转换。
多亏了
- 多兰·缪(注:这里的“Dolan Miu”可能是一个人名,根据音译原则,翻译为“多兰·缪”,但具体翻译可能因文化和语境差异而有所不同) 以及所有对……的贡献者 docx 库
- 这个 人类中心团队(或译为“以人为本团队”,具体翻译可能根据上下文调整) 用于构建模型上下文协议和Claude代码
- 这个(或“该”) 开源社区 使得制造这样的工具成为可能
