Sponsored by Deepsite.site

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

Created By
mystique9208 months ago
MCP-Server that can control pandoc on host from docker environment using a local pandoc host service
Content

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.
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
ChatWiseThe second fastest AI chatbot™
Amap Maps高德地图官方 MCP Server
WindsurfThe new purpose-built IDE to harness magic
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Playwright McpPlaywright MCP server
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Tavily Mcp
DeepChatYour AI Partner on Desktop
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Serper MCP ServerA Serper MCP Server
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
CursorThe AI Code Editor
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors