MCP Server for md2x
January 23, 2026 ยท View on GitHub
This document describes the Model Context Protocol (MCP) server implementation for the md2x markdown converter.
Overview
The md2x MCP server exposes markdown conversion capabilities via the Model Context Protocol, allowing AI assistants and other MCP clients to convert markdown content to various formats (PDF, DOCX, HTML, PNG, JPG, JPEG, WEBP).
Installation
The MCP server is built into the md2x CLI. Install dependencies:
cd node
pnpm install
pnpm build
Usage
Starting the MCP Server
Start the server in MCP mode using the --mcp flag:
node dist/md2x.js --mcp
Or if installed globally:
md2x --mcp
The server uses stdio transport for communication, making it compatible with any MCP client.
Available Tools
1. convert_markdown
Convert markdown files to PDF, DOCX, HTML, or Image formats.
Parameters:
markdownFilePath(string, required): Path to markdown file to convertformat(string, default: "pdf"): Output format (pdf, docx, html, png, jpg, jpeg, webp)theme(string, default: "default"): Theme name to applydiagramMode(string, optional): Diagram rendering mode (img, live, none)hrAsPageBreak(boolean, optional): Convert horizontal rules to page breakstitle(string, optional): Document titlebasePath(string, optional): Base path for resolving relative pathsliveRuntime(string, optional): HTML live runtime injection strategy (inline, cdn)liveRuntimeBaseUrl(string, optional): Custom runtime base URL when liveRuntime is cdnoutputPath(string, optional): Output file path (defaults to same directory as markdown file)
Returns: JSON object containing:
format: The output format usedoutputPath: Path to the converted filesize: Size of the file in bytesmessage: Success message
For split images (multiple parts):
outputPath: Path to the first partoutputPaths: Array of all part pathsparts: Number of partssize: Total size of all parts
Example:
{
"name": "convert_markdown",
"arguments": {
"markdownFilePath": "/path/to/document.md",
"format": "pdf",
"theme": "academic",
"title": "My Document"
}
}
2. list_themes
List all available themes for markdown conversion.
Parameters: None
Returns: JSON object containing:
themes: Array of theme objects withid,category, andfeaturedstatuscount: Total number of themes
Example:
{
"name": "list_themes",
"arguments": {}
}
Features
- Multiple Output Formats: PDF, DOCX, HTML, PNG, JPG, JPEG, WEBP
- Rich Markdown Support:
- Diagrams (Mermaid, Graphviz, Vega)
- Math equations (KaTeX)
- Code highlighting
- Tables, images, and more
- Themes: 30+ built-in themes
- Stdio Transport: Compatible with any MCP client
Testing
Run the MCP server tests using Node's built-in test runner:
node --test test/mcp-server.test.mjs
Or run all tests:
pnpm test
The test suite verifies:
- MCP connection initialization
- Tool listing functionality
- Theme listing
- Markdown file conversion to HTML
Integration with Claude Desktop
To use this MCP server with Claude Desktop, add the following to your Claude Desktop configuration:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"md2x": {
"command": "node",
"args": ["/path/to/markdown-viewer-extension/node/dist/md2x.js", "--mcp"]
}
}
}
Replace /path/to/markdown-viewer-extension with the actual path to your installation.
Implementation Details
Files
- src/host/mcp-server.ts: MCP server implementation
- src/host/cli.ts: CLI with MCP mode support
- test/mcp-server.test.mjs: Test suite for MCP server
Architecture
The MCP server:
- Uses
@modelcontextprotocol/sdkfor MCP protocol handling - Implements stdio transport for communication
- Reads markdown files from disk and converts them using the
convert()API - Saves converted files to disk (same directory as source file by default)
- Returns file paths to the converted documents
Dependencies
@modelcontextprotocol/sdk: MCP protocol implementationzod: Schema validation for tool parameters
Troubleshooting
Server not starting
Ensure all dependencies are installed:
pnpm install
pnpm build
Conversion errors
Check that:
- Puppeteer is properly installed
- The markdown file exists and is readable
- The markdown content is valid
- The specified theme exists (use
list_themesto see available themes) - The output directory is writable
Connection issues
The server uses stdio transport. Ensure your MCP client is configured to communicate via stdin/stdout.
License
ISC