MCP Markdown 转 PDF 服务器
✨ 资源
- 通过文件路径或内联内容提供的Markdown转换
- 格式选项(页面大小、边距、方向、页眉/页脚)
- 包含本地或远程样式表
- 将PDF以Base64格式返回和/或保存到磁盘的可能性
- 丰富的元数据(转换时间、文件大小、页数)
📦 先决条件
- Node.js 18或更高版本
- 已安装的依赖项
npm install - 能够运行无头模式Chromium的环境(由Puppeteer自动安装)
🚀 执行
安装依赖项```powershell
npm install
### 编译项目```powershell
npm run build
运行MCP服务器```powershell
npm start
该服务器通过STDIO运行。配置您的MCP客户端(例如,Claude Desktop)以指向编译后的二进制文件。 `dist/index.js`。
## 🛠️ 可用工具
### `convert_markdown_to_pdf`
入口(`JSON Schema`):
- `markdown_content` (字符串,可选)
- `markdown_file_path` (字符串,可选)
- `output_path` (字符串,可选)
- `pdf_options` (对象,可选)
- `format`: `A4`, `A3`, `A5`, `Letter`, `Legal`
- `orientation`: `portrait`, `landscape`
- `margin`字符串 CSS(`20mm 15mm`等
- `print_background`布尔类型(或布尔值)
- `stylesheet_urls` (字符串或字符串数组)
- `css` (字符串)
- `highlight_style` (字符串)
- `header_template` / `footer_template` (字符串 HTML)
- `include_default_styles` (boolean,默认 `true`)
- `return_pdf` (布尔值,默认 `false`)
输出:```json
{
"success": true,
"message": "PDF generated successfully at ...",
"outputPath": "...",
"pdfBase64": "...",
"metadata": {
"durationMs": 123,
"fileSizeBytes": 45678,
"fileSizeReadable": "45 KB",
"pageCount": 3,
"usedStylesheets": ["https://..."],
"highlightStyle": "github",
"sourceType": "file"
}
}
🧪 开发
npm run dev以 watch 模式重新编译npm test(保留用于未来的测试)
📁 结构```
src/
index.ts # Bootstrap do servidor MCP
server.ts # Registro das ferramentas
lib/ # Conversor, validação e config default
types.ts # Tipos compartilhados
```
⚖️ 许可证
根据ISC许可证分发。请参阅 package.json 以获取详情。
