Skip to main content

A secure MCP server for document format conversion using pypandoc

Project description

Huoshui File Converter

A secure MCP (Model Context Protocol) server for document format conversion within a specified working directory.

Features

  • 🔒 Sandbox Security: All operations restricted to a configured working directory
  • 📄 Format Support: Convert between Markdown, DOCX, HTML, PDF, and TXT
  • 🚀 MCP Integration: Full MCP protocol support with prompts, resources, and tools
  • ⚙️ Flexible Configuration: CLI arguments, environment variables, or current directory
  • 🔍 Smart Detection: Intelligent file format detection by content analysis

Quick Start

Installation

# Install via uvx (recommended)
uvx huoshui-file-converter

# Or install globally
pip install huoshui-file-converter

Basic Usage

# Use current directory
uvx huoshui-file-converter

# Specify working directory (recommended)
uvx huoshui-file-converter --dir "/path/to/documents"

# Short form
uvx huoshui-file-converter -d "~/Documents"

MCP Client Configuration

For Claude Desktop or other MCP clients:

{
  "mcpServers": {
    "huoshui-converter": {
      "command": "uvx",
      "args": ["huoshui-file-converter", "--dir", "/Users/yourname/Documents"]
    }
  }
}

Configuration Options

Priority Order

  1. CLI Argument (highest priority): --dir or -d
  2. Environment Variable: HUOSHUI_WORKING_DIR
  3. Smart Default: Documents folder if current directory is problematic
  4. Current Directory (fallback)

Examples

# CLI argument (best for MCP clients)
uvx huoshui-file-converter --dir "/project/docs"

# Environment variable
export HUOSHUI_WORKING_DIR="/project/docs"
uvx huoshui-file-converter

# Current directory fallback
cd /project/docs
uvx huoshui-file-converter

Supported Conversions

From To
Markdown DOCX, HTML, PDF
DOCX Markdown, HTML, PDF
HTML Markdown, DOCX, PDF
TXT Markdown, DOCX, HTML, PDF

MCP Tools & Resources

Tools

  • convert_document: Convert files between formats
  • detect_format: Intelligent format detection

Resources

  • file_list: Browse directory contents (optimized for large directories)
    • limit: Control number of files shown (default: 100)
    • supported_only: Show only convertible files
  • file_get: Get detailed file information
  • conversion_capability_list: List supported conversions

Prompts

  • role_and_rules: AI assistant behavior guidelines

Performance Features

  • Fast Directory Listing: Extension-based format detection for large directories
  • Smart File Limits: Default 100-file limit prevents UI freezing
  • Large File Handling: Files >50MB are marked and handled specially
  • Selective Display: Option to show only supported file formats
  • Memory Efficient: Avoids reading file contents during directory browsing

Security Features

  • Path Validation: Prevents directory traversal attacks
  • Working Directory Restriction: All operations sandboxed to configured directory
  • Startup Validation: Checks directory existence and permissions
  • Relative Path Enforcement: Absolute paths are rejected

Command Line Options

$ uvx huoshui-file-converter --help

usage: huoshui-file-converter [-h] [--dir PATH] [--version]

Huoshui Document Converter - MCP Server for file conversion within a working directory

options:
  -h, --help         show this help message and exit
  --dir PATH, -d PATH
                     Working directory for file operations (default: current directory or HUOSHUI_WORKING_DIR env var)
  --version, -v      show program's version number and exit

Examples:
  uvx huoshui-file-converter                    # Use current directory
  uvx huoshui-file-converter --dir /docs        # Use specific directory
  uvx huoshui-file-converter -d ./project       # Use relative directory

Configuration Priority:
  1. CLI argument (--dir/-d)
  2. Environment variable (HUOSHUI_WORKING_DIR)
  3. Current working directory

Error Handling

The server validates the working directory on startup:

✅ Working directory configured: /Users/name/Documents
📂 Source: CLI argument

Common errors and solutions:

Error Solution
Directory not found Create directory or fix path
No write access Check permissions (chmod on Unix)
Path outside sandbox Use relative paths only

Development

Requirements

  • Python 3.8+
  • pypandoc
  • pandoc (system dependency)
  • LaTeX (for PDF conversion)

Testing

# Test configuration
uvx huoshui-file-converter --dir "/tmp/test"

# Check startup messages
# ✅ Working directory configured: /tmp/test
# 📂 Source: CLI argument

Documentation

License

[Your license here]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

huoshui_file_converter-0.1.0.tar.gz (16.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

huoshui_file_converter-0.1.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file huoshui_file_converter-0.1.0.tar.gz.

File metadata

File hashes

Hashes for huoshui_file_converter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 88c8f58425424a8ee38ddbbc2429ee1a7ca9adc9fa36295d58fb3cd00f97c0c3
MD5 5673a2314f91923feeefe546f1d3a448
BLAKE2b-256 0790a966a4010e74afd984993764a7f3820f88a56cc5eafd0b371994283211e0

See more details on using hashes here.

File details

Details for the file huoshui_file_converter-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for huoshui_file_converter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0fcd2c6712a3c7dc005c313d67bcdd6c97491c56a9e935b87923d7cd3047885a
MD5 fd975ba55f2355327463655522798b4e
BLAKE2b-256 3bb8b14e53eca8e511e7ab6e7bbe4265965a31570dd8b1c64a2ce8a21379deb6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page