Cover image
Try Now
2025-04-07

可以使用本地Pandoc主机服务应用程序从Docker环境中控制主机上的Pandoc的MCP-Server

3 years

Works with Finder

1

Github Watches

0

Github Forks

0

Github Stars

mcp-pandoc-ts: A Document Conversion MCP Server (TypeScript/Host Service Version)

⚠️ Status: Preview Release ⚠️

This is an initial release. While core functionality (Markdown, HTML, PDF, DOCX, TXT conversion) has been tested, other formats like LaTeX and EPUB are currently untested. Please report any issues.

This project provides document conversion capabilities via the Model Context Protocol (MCP). It uses a two-component architecture:

  1. mcp-pandoc-ts (This Directory): A TypeScript-based MCP server designed to run inside a container (e.g., within LibreChat). It receives MCP requests via stdio.
  2. pandoc-host-service (Separate Directory): A Python Flask service designed to run on the host machine. It listens for HTTP requests from the container service and executes the host's pandoc command.

This architecture allows leveraging a pandoc installation on the host machine without needing to install it inside the container.

Prerequisites

For the Host Machine (running pandoc-host-service):

  1. Python: Version 3.7+ recommended.
  2. pip: Python package installer.
  3. Pandoc: The core conversion tool. Must be installed and accessible in your system's PATH. See pandoc installation instructions.
  4. TeX Live / MiKTeX (for PDF output): Required only if you need to convert documents to PDF format via the host service.
    • Ubuntu/Debian: sudo apt-get install texlive-xetex
    • macOS: brew install texlive
    • Windows: Install MiKTeX or TeX Live.

For the Container Environment (running mcp-pandoc-ts):

  1. Node.js: Version 16 or later recommended.
  2. npm or yarn: Package manager for Node.js.
  3. Network connectivity to the host machine where pandoc-host-service is running.
  4. Host Service URL Configuration (CRITICAL): This server must know the URL of the running pandoc-host-service. This is configured via the PANDOC_HOST_URL environment variable.
    • Deployment (e.g., LibreChat, Docker Compose): Set the PANDOC_HOST_URL environment variable directly in your deployment configuration. This is the recommended and most reliable method for deployed environments. See the "MCP Integration" section for an example. This method overrides any .env file.
    • Local Development/Testing: For convenience during local development only, you can create a .env file in the project root (copy .env.example to .env) and set the PANDOC_HOST_URL there. The server will load this value if no external environment variable is set.
    • Value Examples:
      • Docker Desktop (Mac/Win): http://host.docker.internal:5001
      • Linux (typical bridge network): http://172.17.0.1:5001 (Verify host IP on Docker network)
    • Failure to configure this variable (either externally or via .env for local testing) will prevent the server from contacting the host service and result in errors.

Setup and Running

Step 1: Set up and Run the Host Service (pandoc-host-service)

  1. Navigate to the pandoc-host-service directory (sibling to mcp-pandoc-ts) on your host machine.
  2. (Recommended) Create and activate a Python virtual environment:
    python -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
    
  3. Install dependencies:
    pip install -r requirements.txt
    
  4. Run the Host Service using Waitress:
    • Open a new, separate terminal window on your host machine.
    • Ensure you are still inside the pandoc-host-service directory and that your virtual environment (if created) is active.
    • Make the run script executable (if you haven't already): chmod +x run_host_service.sh
    • Execute the run script:
      ./run_host_service.sh
      
    • You should see output from Waitress indicating it's serving the app (e.g., Serving on http://0.0.0.0:5001). The Flask development server warnings should not appear.
    • Important: This terminal window must remain open for the host service to keep running and handle requests from the mcp-pandoc-ts container service. If you close this terminal, the host service stops.
    • (Optional - Advanced): For a more permanent setup where the service runs even after closing the terminal, consider using tools like nohup (nohup python app.py &), screen, or tmux, or setting it up as a system service.

Step 2: Set up and Run the Container Service (mcp-pandoc-ts)

  1. Navigate to the mcp-pandoc-ts directory (this directory).
  2. Install dependencies:
    npm install
    # or
    yarn install
    
  3. Compile the TypeScript code:
    npm run build
    # or
    yarn build
    
    This creates the dist/server.js file.
  4. Configure Host Service URL: Ensure PANDOC_HOST_URL is configured using one of the methods described in the "Prerequisites" section (either create and edit a .env file or set the environment variable externally).
  5. Run the MCP server (e.g., via LibreChat configuration or directly):
    # The server will load PANDOC_HOST_URL from .env or the external environment
    npm start
    # or
    yarn start
    # or directly
    node dist/server.js
    
    This server will listen on stdin for MCP requests and forward conversion tasks to the host service using the configured PANDOC_HOST_URL. If the variable is not configured (via .env or external environment), the server will log an error and fail to process requests.

MCP Integration (Example for LibreChat)

Configure your MCP client (LibreChat, or similar) to launch the mcp-pandoc-ts server using Node.js. The recommended and most reliable way to configure the connection is by setting the PANDOC_HOST_URL environment variable directly within the MCP client's configuration for this server. This ensures the setting is correctly applied in the deployment environment.

Example configuration snippet (adapt path as needed):

{
  "mcpServers": {
    "mcp-pandoc-ts": {
      "command": "node",
      "args": ["/path/to/your/mcp-pandoc-ts/dist/server.js"],
      "env": {
        "PANDOC_HOST_URL": "http://host.docker.internal:5001" // <-- SET THIS TO THE CORRECT URL FOR YOUR ENVIRONMENT
      }
    }
  }
}

Tools

convert-contents

  • Description: Converts content between different formats by sending requests to the host Pandoc service.
  • 🚨 CRITICAL REQUIREMENTS:
    • The pandoc-host-service must be running on the host machine.
    • The PANDOC_HOST_URL must be correctly configured (via .env file or external environment variable) when launching this server, pointing to the running pandoc-host-service.
    • Host machine requires Pandoc (and TeX Live for PDF).
  • Current Limitations:
    • Only contents input is supported. input_file is not currently handled due to path complexities between container and host.
    • output_file is supported for all output formats. For binary formats (like pdf, docx), the host service sends the file content encoded in base64, and this container service decodes and saves it to the specified path. For text formats, the plain text is saved.
  • Supported Formats (via host): markdown, html, pdf, docx, rst, latex (Untested), epub (Untested), txt
  • Input Schema:
    • contents (string): Content to convert (required).
    • input_file (string): NOT CURRENTLY SUPPORTED.
    • input_format (string, optional, default: markdown): Source format.
    • output_format (string, optional, default: markdown): Target format.
    • output_file (string, optional): Absolute path within the container to save output. Only functional for basic formats (txt, html, markdown pdf docx etc.)

Development

  • Container Service: Source code is in mcp-pandoc-ts/src. Run npm run build to compile.
  • Host Service: Source code is in pandoc-host-service. Run python app.py to start.

相关推荐

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • https://zenepic.net
  • Embark on a thrilling diplomatic quest across a galaxy on the brink of war. Navigate complex politics and alien cultures to forge peace and avert catastrophe in this immersive interstellar adventure.

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • ravitemer
  • 一个功能强大的Neovim插件,用于管理MCP(模型上下文协议)服务器

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

  • pontusab
  • 光标与风浪冲浪社区,查找规则和MCP

  • patruff
  • Ollama和MCP服务器之间的桥梁,使本地LLMS可以使用模型上下文协议工具

  • av
  • 毫不费力地使用一个命令运行LLM后端,API,前端和服务。

  • appcypher
  • 很棒的MCP服务器 - 模型上下文协议服务器的策划列表

  • chongdashu
  • 使用模型上下文协议(MCP),启用Cursor,Windsurf和Claude Desktop等AI助手客户,以通过自然语言控制虚幻引擎。

  • Mintplex-Labs
  • 带有内置抹布,AI代理,无代理构建器,MCP兼容性等的多合一桌面和Docker AI应用程序。

    Reviews

    4 (1)
    Avatar
    user_KGyN5SVp
    2025-04-17

    I recently started using mcp-pandoc-ts by mystique920, and it has significantly streamlined my document conversion workflow. The integration with Pandoc is seamless, and the performance is impressive. If you need a reliable tool for text processing and document transformation, I highly recommend giving mcp-pandoc-ts a try. It's well-documented and easy to use, making it perfect for both beginners and advanced users.