Mcp Document Converter

io.github.xt765由 GitHub 账号 xt765 发布v0.2.2更新于 Oct 24, 2026

Convert PDF, DOCX, HTML, Markdown, and Text for AI assistant context injection.

已验证STDIO仅桌面效率与工作流文件与存储

概览

AI 生成的概览

一个本地 MCP 服务器,可在 Markdown、HTML、DOCX、PDF 和纯文本之间转换文档,便于助手读取或生成这些格式。

可以做什么
转换文档:在格式之间转换,可指定源路径、输出路径、目标格式、CSS、模板和元数据选项,未指定源格式时按扩展名自动识别。查询格式支持:列出支持的格式、查看完整转换矩阵、检查某组源格式到目标格式是否可行,以及获取单个格式的详细信息。输出可带代码语法高亮、自定义 CSS 样式,并保留标题、作者和创建时间等元数据。
适用场景
当助手需要把 PDF、Word 文件、HTML 页面或 Markdown 笔记转成其他格式以便注入上下文,或从 Markdown 生成带样式的 HTML 或 PDF 时适用。文档格式转换是工作流中常见环节时值得添加。
运行要求
作为本地进程在用户机器上运行,可从 PyPI 安装(pip install mcp-document-converter)或用 uvx 启动;README 也给出从 Git 仓库运行的方式。需要 Python 及所列依赖,PDF 输出依赖 WeasyPrint。未声明认证、API 密钥或请求头。可选环境变量 MCP_CONVERTER_LOG_LEVEL 和 MCP_CONVERTER_TEMP_DIR 用于控制日志级别和临时目录。
安装前请注意
它会读取助手提供的路径下的文件并写出转换后的文件,因此只应指向你愿意暴露的目录,并留意输出位置。PDF 渲染依赖 WeasyPrint 及其系统库。不要求任何凭据,但转换的文档在本地处理,并可能进入助手的上下文。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Mcp Document Converter,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

MCP Document Converter

MCP (Model Context Protocol) Document Converter - A powerful MCP tool for converting documents between multiple formats, enabling AI agents to easily transform documents.

🌐 Language: English | 中文

[CSDN] [GitHub] [Gitee]

[License] [Python] [PyPI Version] [PyPI Downloads] [MCP Registry] [MCP Marketplace]

Features

  • Multi-format Support: Supports 5 mainstream document formats: Markdown, HTML, DOCX, PDF, and Text
  • Bidirectional Conversion: Any format can be converted to any other format (5×5=25 conversion combinations)
  • MCP Protocol: Compliant with MCP standards, can be used as a tool for AI assistants like Trae IDE
  • Plugin Architecture: Easy to extend with new parsers and renderers
  • Syntax Highlighting: HTML and PDF outputs support code syntax highlighting
  • Style Customization: Support for custom CSS styles
  • Metadata Preservation: Preserves document title, author, creation time, and other metadata during conversion

📚 Documentation

User Guide · API Reference · Contributing · Changelog · License


Architecture

mermaid
flowchart TB    subgraph Parsers["Parsers"]        MD[Markdown]        DOCX1[DOCX]        HTML1[HTML]        PDF1[PDF]        TXT1[Text]    end
    subgraph IR["Intermediate Representation (IR)"]        DT[Document Tree]        META[Metadata]        ASSETS[Assets]    end
    subgraph Renderers["Renderers"]        HTML2[HTML]        PDF2[PDF]        MD2[Markdown]        DOCX2[DOCX]        TXT2[Text]    end
    MD --> IR    DOCX1 --> IR    HTML1 --> IR    PDF1 --> IR    TXT1 --> IR        IR --> HTML2    IR --> PDF2    IR --> MD2    IR --> DOCX2    IR --> TXT2

Core Components

  1. DocumentIR (Intermediate Representation): Unified abstraction for all documents, containing document tree, metadata, assets, etc.
  2. BaseParser (Parser Base Class): Defines the parser interface, parses various formats into DocumentIR
  3. BaseRenderer (Renderer Base Class): Defines the renderer interface, renders DocumentIR into various formats
  4. ConverterRegistry (Registry): Manages all parsers and renderers, provides format lookup and auto-matching
  5. DocumentConverter (Conversion Engine): Coordinates parsers and renderers to complete document conversion

Supported Formats

Input Formats (Parsers)

FormatExtensionsMIME TypeFeatures
Markdown.md, .markdown, .mdown, .mkdtext/markdownYAML Front Matter, GFM extensions
HTML.html, .htmtext/htmlSemantic tag parsing
DOCX.docxapplication/vnd.openxmlformats-officedocument.wordprocessingml.documentStyles, tables, images
PDF.pdfapplication/pdfText extraction and structure recognition
Text.txt, .texttext/plainAuto encoding detection and structure recognition

Output Formats (Renderers)

FormatExtensionMIME TypeFeatures
HTML.htmltext/htmlBeautiful styling, code highlighting, responsive design
Markdown.mdtext/markdownStandard Markdown format, YAML Front Matter
DOCX.docxapplication/vnd.openxmlformats-officedocument.wordprocessingml.documentWord document format, style preservation
PDF.pdfapplication/pdfGenerated with WeasyPrint, pagination support
Text.txttext/plainPlain text, basic formatting preserved

Conversion Matrix

mermaid
flowchart LR    subgraph Sources["Source Formats"]        MD_S[Markdown]        HTML_S[HTML]        DOCX_S[DOCX]        PDF_S[PDF]        TXT_S[Text]    end
    subgraph Targets["Target Formats"]        MD_T[Markdown]        HTML_T[HTML]        DOCX_T[DOCX]        PDF_T[PDF]        TXT_T[Text]    end
    MD_S --> Targets    HTML_S --> Targets    DOCX_S --> Targets    PDF_S --> Targets    TXT_S --> Targets

Installation

Using pip (Recommended)

bash
pip install mcp-document-converter

From Source

bash
git clone https://github.com/xt765/mcp-document-converter.gitcd mcp-document-converterpip install -e .

MCP Tools

This server provides the following tools:

convert_document

Convert a document from one format to another.

Arguments:

  • source_path (string, required): Path to the source document.
  • target_format (string, required): Target format (html, pdf, markdown, docx, text).
  • output_path (string, optional): Path for the output file.
  • source_format (string, optional): Format of the source file (auto-detected if not provided).
  • options (object, optional): Additional options like template, css, and preserve_metadata.

Configuration

Using in Trae IDE / Claude Desktop

Add the following to your MCP configuration file:

Option 1: Using PyPI (Recommended)

json
{  "mcpServers": {    "mcp-document-converter": {      "command": "uvx",      "args": [        "mcp-document-converter"      ]    }  }}

Option 2: Using GitHub repository

json
{  "mcpServers": {    "mcp-document-converter": {      "command": "uvx",      "args": [        "--from",        "git+https://github.com/xt765/mcp-document-converter",        "mcp-document-converter"      ]    }  }}

Option 3: Using Gitee repository (Faster access in China)

json
{  "mcpServers": {    "mcp-document-converter": {      "command": "uvx",      "args": [        "--from",        "git+https://gitee.com/xt765/mcp-document-converter",        "mcp-document-converter"      ]    }  }}

Option 4: Using pip (Manual installation)

First install the package:

bash
pip install mcp-document-converter

Then add to configuration:

json
{  "mcpServers": {    "mcp-document-converter": {      "command": "mcp-document-converter",      "args": []    }  }}

Using in Cherry Studio

Cherry Studio is a powerful open-source desktop AI client assistant that supports integrating various tools through the MCP protocol

Configuration Example:

[Cherry Studio Configuration]

Usage Example:

[Cherry Studio Usage]

Usage

As an MCP Tool

After configuration, AI assistants can directly call the following tools:

1. convert_document (Recommended)

Use a unified interface to convert any supported document type.

python
# Markdown to HTMLconvert_document(    source_path="document.md",    target_format="html")
# HTML to PDFconvert_document(    source_path="document.html",    target_format="pdf")
# DOCX to Markdownconvert_document(    source_path="document.docx",    target_format="markdown")
# Conversion with optionsconvert_document(    source_path="document.md",    target_format="html",    output_path="output.html",    options={        "css": "custom.css",        "preserve_metadata": True    })
2. list_supported_formats

List all supported document formats.

python
list_supported_formats()
3. get_conversion_matrix

Get the complete format conversion matrix.

python
get_conversion_matrix()
4. can_convert

Check if conversion from source format to target format is supported.

python
can_convert(source_format="markdown", target_format="pdf")
5. get_format_info

Get detailed information about a specific format.

python
get_format_info(format="markdown")

As a Python Library

python
from mcp_document_converter import DocumentConverterfrom mcp_document_converter.registry import get_registryfrom mcp_document_converter.parsers import MarkdownParser, HTMLParserfrom mcp_document_converter.renderers import HTMLRenderer, PDFRenderer
# Register parsers and renderersregistry = get_registry()registry.register_parser(MarkdownParser())registry.register_parser(HTMLParser())registry.register_renderer(HTMLRenderer())registry.register_renderer(PDFRenderer())
# Create converterconverter = DocumentConverter(registry)
# Convert documentresult = converter.convert(    source="input.md",    target_format="html",    output_path="output.html")
if result.success:    print(f"✅ Conversion successful: {result.output_path}")else:    print(f"❌ Conversion failed: {result.error_message}")

Tool Interface Details

convert_document

Convert a document from one format to another.

Parameters:

ParameterTypeRequiredDescription
source_pathstring✅Source file path, supports absolute or relative paths
target_formatstring✅Target format: html, pdf, markdown, docx, text
output_pathstring❌Output file path (optional, defaults to source filename)
source_formatstring❌Source format (optional, auto-detected from file extension)
optionsobject❌Conversion options

Options:

OptionTypeDefaultDescription
templatestring-Template name
cssstring-Custom CSS styles
preserve_metadatabooleantrueWhether to preserve metadata
extract_imagesbooleantrueWhether to extract images

Example:

json
{  "source_path": "/path/to/document.md",  "target_format": "html",  "output_path": "/path/to/output.html",  "options": {    "css": "body { font-family: Arial; }",    "preserve_metadata": true  }}

Extension Development

Adding a New Parser

python
from typing import List, Unionfrom pathlib import Pathfrom mcp_document_converter.core.parser import BaseParserfrom mcp_document_converter.core.ir import DocumentIR, Node, NodeType
class MyParser(BaseParser):    @property    def supported_extensions(self) -> List[str]:        return [".myext"]        @property    def format_name(self) -> str:        return "myformat"        @property    def mime_types(self) -> List[str]:        return ["application/x-myformat"]        def parse(self, source: Union[str, Path, bytes], **options) -> DocumentIR:        # Read source file        content = self._read_source(source)                # Parse into DocumentIR        document = DocumentIR()        document.title = "My Document"                # Add content nodes        document.add_node(Node(            type=NodeType.PARAGRAPH,            content=[Node(type=NodeType.TEXT, content="Hello World")]        ))                return document

Adding a New Renderer

python
from typing import Anyfrom mcp_document_converter.core.renderer import BaseRendererfrom mcp_document_converter.core.ir import DocumentIR
class MyRenderer(BaseRenderer):    @property    def output_extension(self) -> str:        return ".myext"        @property    def format_name(self) -> str:        return "myformat"        @property    def mime_type(self) -> str:        return "application/x-myformat"        def render(self, document: DocumentIR, **options: Any) -> str:        # Render DocumentIR to target format        parts = []                if document.title:            parts.append(f"# {document.title}")                for node in document.content:            # Render each node            pass                return "\n".join(parts)

Registering Extensions

python
from mcp_document_converter.registry import get_registry
# Register new parser and rendererregistry = get_registry()registry.register_parser(MyParser())registry.register_renderer(MyRenderer())

Testing

bash
# Run all testspython tests/test_conversion.py
# Run specific testpython tests/test_conversion.py::test_markdown_to_html

Environment Variables

VariableDescriptionDefault
MCP_CONVERTER_LOG_LEVELLog levelINFO
MCP_CONVERTER_TEMP_DIRTemporary files directorySystem temp directory

Dependencies

Core Dependencies

  • mcp >= 1.26.0 - MCP protocol implementation
  • pydantic >= 2.12.5 - Data validation

Parser Dependencies

  • markdown >= 3.5.0 - Markdown parsing
  • beautifulsoup4 >= 4.12.0 - HTML parsing
  • python-docx >= 1.1.0 - DOCX parsing
  • pypdf >= 6.7.4 - PDF parsing
  • chardet >= 5.0.0 - Encoding detection
  • pyyaml >= 6.0.0 - YAML parsing

Renderer Dependencies

  • weasyprint >= 60.0 - PDF rendering
  • pygments >= 2.17.0 - Code highlighting
  • jinja2 >= 3.1.6 - Template engine
  • reportlab >= 4.0.0 - PDF generation

Development Dependencies

  • pytest >= 7.0.0 - Testing framework
  • pytest-asyncio >= 0.21.0 - Async testing support
  • pytest-cov >= 4.0.0 - Coverage reporting
  • basedpyright >= 1.0.0 - Type checking
  • ruff >= 0.1.0 - Linting and formatting

License

MIT License

Contributing

Issues and Pull Requests are welcome!

Related Projects

来源:README.md,提交 2b57af4

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.2.2最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分