mcp-pandoc-ts
by mystique920
This project provides document conversion capabilities via the Model Context Protocol (MCP). It uses a two-component architecture: a TypeScript-based MCP server and a Python Flask host service to leverage a `pandoc` installation on the host machine without needing to install it inside the container.
Last updated: N/A
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:
- 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.
- 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- pandoccommand.
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):
- Python: Version 3.7+ recommended.
- pip: Python package installer.
- Pandoc: The core conversion tool. Must be installed and accessible in your system's PATH. See pandoc installation instructions.
- TeX Live / MiKTeX (for PDF output): Required only if you need to convert documents to PDF format via the host service.
For the Container Environment (running mcp-pandoc-ts):
- Node.js: Version 16 or later recommended.
- npm or yarn: Package manager for Node.js.
- Network connectivity to the host machine where pandoc-host-serviceis running.
- Host Service URL Configuration (CRITICAL): This server must know the URL of the running pandoc-host-service. This is configured via thePANDOC_HOST_URLenvironment variable.- Deployment (e.g., LibreChat, Docker Compose): Set the PANDOC_HOST_URLenvironment 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.envfile.
- Local Development/Testing: For convenience during local development only, you can create a .envfile in the project root (copy.env.exampleto.env) and set thePANDOC_HOST_URLthere. 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)
 
- Docker Desktop (Mac/Win): 
- Failure to configure this variable (either externally or via .envfor local testing) will prevent the server from contacting the host service and result in errors.
 
- Deployment (e.g., LibreChat, Docker Compose): Set the 
Setup and Running
Step 1: Set up and Run the Host Service (pandoc-host-service)
- Navigate to the pandoc-host-servicedirectory (sibling tomcp-pandoc-ts) on your host machine.
- (Recommended) Create and activate a Python virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
- Install dependencies:
pip install -r requirements.txt
- Run the Host Service using Waitress:
- Open a new, separate terminal window on your host machine.
- Ensure you are still inside the pandoc-host-servicedirectory 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-tscontainer 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, ortmux, or setting it up as a system service.
 
Step 2: Set up and Run the Container Service (mcp-pandoc-ts)
- Navigate to the mcp-pandoc-tsdirectory (this directory).
- Install dependencies:
npm install # or yarn install
- Compile the TypeScript code:
npm run build # or yarn builddist/server.jsfile.
- Configure Host Service URL: Ensure PANDOC_HOST_URLis configured using one of the methods described in the "Prerequisites" section (either create and edit a.envfile or set the environment variable externally).
- 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.jsPANDOC_HOST_URL. If the variable is not configured (via.envor 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-servicemust be running on the host machine.
- The PANDOC_HOST_URLmust be correctly configured (via.envfile or external environment variable) when launching this server, pointing to the runningpandoc-host-service.
- Host machine requires Pandoc (and TeX Live for PDF).
 
- The 
- Current Limitations:
- Only contentsinput is supported.input_fileis not currently handled due to path complexities between container and host.
- output_fileis 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.
 
- Only 
- 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- docxetc.)
 
Development
- Container Service: Source code is in mcp-pandoc-ts/src. Runnpm run buildto compile.
- Host Service: Source code is in pandoc-host-service. Runpython app.pyto start.
