zcaceres/markdownify-mcp
关于
用于将几乎任何内容转换为 Markdown 的 Model Context Protocol 服务器
人工智能与机器学习可以做什么
- PDF, DOCX, XLSX, PPTX
- Images (EXIF/metadata extraction without external vision LLMs)
- Audio (speech transcription via markitdown[all], requires network speech recognition)
- General webpages and hosted documents (PDF, DOCX, XLSX, PPTX, images, etc.)
实测星标增长
- 24小时
- +1
- 7天
- -1
- 15天
- +2
- 1个月
- +9
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Markdownify MCP Server

Markdownify is a stateless Model Context Protocol (MCP) server (mcp-markdownify-server, built on MCP TypeScript SDK v2) and standalone local CLI (mcp-markdownify) that converts local files, web URLs, and public Git repositories to Markdown and retrieves existing Markdown files.
Docs: markdownify.zach.dev · LLM-friendly docs: markdownify.zach.dev/llms.txt
Features
- Convert local files to Markdown (absolute or
~/paths):- PDF, DOCX, XLSX, PPTX
- Images (EXIF/metadata extraction without external vision LLMs)
- Audio (speech transcription via
markitdown[all], requires network speech recognition)
- Convert web content to Markdown (public
http(s)URLs with hop-by-hop SSRF validation and connect-time IP pinning):- General webpages and hosted documents (PDF, DOCX, XLSX, PPTX, images, etc.)
- YouTube video transcripts
- Bing search results
- Convert public Git repositories to Markdown via Repomix (
http(s)URL or GitHubowner/reposhorthand with SSRF-validated proxy-pinned connections, optional branch/tag/commit, and Tree-sitter--compress) - Retrieve existing Markdown files (
.md/.markdown, case-insensitive, verbatim UTF-8 + resolvedrealpath) - Cross-provider MCP alignment (Anthropic Claude, Google Gemini, OpenAI ChatGPT / Agents SDK):
- Complete explicit
ToolAnnotations, top-levelTool.title, serverinstructions,Implementationmetadata, and staticcacheHints - Gemini-safe flat JSON Schema
inputSchemawith strict per-tool runtime argument validation - Typed
outputSchemaandstructuredContentalongside backwards-compatiblecontenttext blocks (untruncated; omitted onisError: true) - Operator-selectable Toolset: default 4-tool
compactsurface (convert-web-url,convert-local-file,convert-git-repo,get-markdown-file) or opt-in 11-toolclassicsurface (--toolset=classic/MCP_TOOLSET=classic)
- Complete explicit
Upgrading from v1.x (v2.0 breaking changes): v2.0 defaults to the 4-tool
compactToolset (pass--toolset=classicor setMCP_TOOLSET=classicto restore the 11 v1 tool names), fails closed on local file tools in HTTP mode unlessMD_ALLOWED_PATHSor--allow-unrestricted-pathsis set, requires absolute or~/file paths, and rejects unknown/cross-tool argument keys strictly.
Getting Started
Prerequisites:
- Node.js 22 or later (also used by Repomix).
- uv on
PATHwith Python 3.11–3.14 (uvinstalls Python automatically if needed; Python 3.15 is not supported).
Run via npx (no clone required):
npx -y mcp-markdownify-server
Or install globally to get both mcp-markdownify-server and the mcp-markdownify CLI:
npm install -g mcp-markdownify-server
During installation, preinstall runs uv sync --locked --extra all --no-dev to provision .venv with MarkItDown's full feature set at the exact versions in uv.lock. If lifecycle scripts are disabled, run node preinstall.js manually.
Building from source
Requires Bun in addition to Node.js 22+ and uv:
git clone https://github.com/zcaceres/markdownify-mcp.git
cd markdownify-mcp
bun install --frozen-lockfile
bun run build
bun start
Usage as a Standalone CLI (mcp-markdownify)
The package also ships a standalone local CLI (mcp-markdownify):
# Convert a public webpage, YouTube video, Bing page, or hosted document
mcp-markdownify web https://example.com
# Convert a local file (relative paths resolve against cwd)
mcp-markdownify file ./report.pdf
# Convert a public Git repository with optional branch and Tree-sitter compression
mcp-markdownify repo octocat/Hello-World --branch main --compress
# Retrieve an existing local Markdown file verbatim (or structured JSON with --json)
mcp-markdownify read ./README.md
mcp-markdownify read ./README.md --json
# Use "--" before a filename starting with "-"
mcp-markdownify file -- -report.pdf
- Output contract: Prints verbatim untruncated Markdown to
stdout(exit0), or a single JSON line ({"markdown":"..."}/{"path":"<realpath>","markdown":"..."}) when--jsonis passed. Errors print a single concise line tostderrwith emptystdoutand exit1. - Paths & limits: Relative paths resolve against
process.cwd().MD_ALLOWED_PATHSmatches MCPstdiosemantics (unrestricted when unset, enforced afterrealpathwhen set, fail-closed if set empty/delimiter-only). InvalidMD_*conversion limits fail fast at startup.
Usage with MCP Clients (stdio)
Compatible with Claude Desktop, Claude Code, Gemini CLI, Codex CLI, Cursor, and MCP Inspector:
{
"mcpServers": {
"markdownify": {
"command": "npx",
"args": ["-y", "mcp-markdownify-server"],
"env": {
"MD_ALLOWED_PATHS": "/path/to/allowed/docs"
}
}
}
}
Or in Claude Code:
claude mcp add markdownify -e MD_ALLOWED_PATHS="$HOME/Documents" -- npx -y mcp-markdownify-server
Markdownify MCP defaults to the 4-tool compact Toolset. Pass "--toolset=classic" in args (or set "MCP_TOOLSET": "classic" in env) to expose the 11 format-specific classic tools for legacy v1 clients. MD_ALLOWED_PATHS is optional in stdio mode (unrestricted when unset), and recommended whenever you want to bound local filesystem reads.
Usage with HTTP (Streamable HTTP transport)
By default the server runs over stdio. To run it as a stateless Streamable HTTP server (listening on 127.0.0.1:3000/mcp by default):
MD_ALLOWED_PATHS=/path/to/docs npx -y mcp-markdownify-server --http --port 3000
Or via environment variables:
MCP_TRANSPORT=http MCP_PORT=3000 MD_ALLOWED_PATHS=/path/to/docs npx -y mcp-markdownify-server
Server Configuration Flags & Environment Variables
CLI flags take precedence over environment variables and accept both --flag=value and space-separated --flag value forms (--http is shorthand for --transport=http). Enum values (--transport, --toolset, MCP_TRANSPORT, MCP_TOOLSET) are trimmed and lowercased; unknown flags, missing flag values, invalid values, or invalid non-empty MD_* conversion limits fail fast at startup on stderr with exit code 1.
| Flag / Env | Default | Purpose |
|---|---|---|
--transport=stdio|http / --http / MCP_TRANSPORT |
stdio |
Transport mode (stdio or stateless Streamable HTTP on /mcp and /). --http is shorthand for --transport=http. |
--host=HOST / MCP_HOST |
127.0.0.1 |
Bind address for HTTP mode. Defaults to loopback only. |
--port=N / MCP_PORT |
3000 |
Port for HTTP mode (1–65535; ignored in stdio mode). |
MCP_ALLOWED_HOSTS |
loopback hosts when bound to loopback | Comma-separated list of allowed Host headers (DNS-rebinding protection; returns HTTP 403 on mismatch). |
MCP_ALLOWED_ORIGINS |
loopback origins when bound to loopback | Comma-separated list of allowed browser Origin headers (returns HTTP 403 on mismatch). |
--allow-unrestricted-paths / MCP_ALLOW_UNRESTRICTED_PATHS |
false |
Opt out of HTTP fail-closed local file blocking when MD_ALLOWED_PATHS is unset. |
--toolset=compact|classic / MCP_TOOLSET |
compact |
Active Toolset: compact (default) exposes 4 capability-aligned tools (convert-web-url, convert-local-file, convert-git-repo, get-markdown-file) to save prompt tokens; classic (opt-in) exposes all 11 format-specific tools. |
--help / --version |
— | Print server usage or version to stdout and exit 0. |
Security note: The HTTP transport has no built-in authentication. When
MD_ALLOWED_PATHSis unset in HTTP mode, local file-input tools (*-to-markdown,convert-local-file, andget-markdown-file) fail closed withisError: trueunless you explicitly opt out with--allow-unrestricted-pathsorMCP_ALLOW_UNRESTRICTED_PATHS=true, while Web URL and Git Repository tools remain available. Keep--host=127.0.0.1for local use, or place the server behind an authenticating reverse proxy withMCP_ALLOWED_HOSTS/MCP_ALLOWED_ORIGINSconfigured.
Paths & Conversion Limit Environment Variables
All paths and limits default to sensible bounds; override only when needed.
| Variable | Default | Purpose |
|---|---|---|
MARKITDOWN_PATH |
<project>/.venv/bin/markitdown, then markitdown on PATH |
Absolute path to the markitdown executable (for example when using pipx install "markitdown[pdf]" instead of the bundled .venv). |
REPOMIX_PATH |
<project>/node_modules/.bin/repomix, then repomix on PATH |
Absolute path to the repomix executable used by git-repo-to-markdown / convert-git-repo. |
MD_ALLOWED_PATHS |
unset (unrestricted in stdio; local file tools disabled in http) |
Path-delimiter-separated list (: on POSIX, ; on Windows) of directories allowed for local reads (enforced after ~ expansion and realpath symlink resolution). Setting an empty or delimiter-only value fails closed for local file tools. |
MD_FETCH_TIMEOUT_MS |
30000 |
Per-request Web URL HTTP fetch timeout in milliseconds. |
MD_MAX_DOWNLOAD_BYTES |
26214400 (25 MB) |
Maximum downloaded response size in bytes for Web URL conversions. |
MD_MAX_REDIRECTS |
10 |
Maximum HTTP redirects followed per Web URL conversion (each hop is SSRF-validated). |
MD_MARKITDOWN_TIMEOUT_MS |
60000 |
Subprocess timeout in milliseconds for markitdown conversions. |
MD_REPOMIX_TIMEOUT_MS |
120000 |
Subprocess timeout in milliseconds for repomix Git repository packing. |
Usage with Docker
Build and run over stdio:
docker build -t markdownify-mcp .
docker run --rm -i \
-v "$HOME/Documents:/data:ro" \
-e MD_ALLOWED_PATHS=/data \
markdownify-mcp
Or run over Streamable HTTP:
docker run --rm \
-p 127.0.0.1:3000:3000 \
-v "$HOME/Documents:/data:ro" \
-e MD_ALLOWED_PATHS=/data \
-e MCP_ALLOWED_HOSTS=127.0.0.1:3000,localhost:3000 \
markdownify-mcp --transport=http --host=0.0.0.0 --port=3000
Notes for Docker (Dockerfile / mcp/markdownify):
- Mount any host directories you want the server to read into the container, then pass the container paths to the tools (e.g.
/data/foo.pdf, not/Users/you/Documents/foo.pdf). - Set
MD_ALLOWED_PATHSto the colon-separated list of mounted directories so the server enforces a read boundary matching the bind mount. - The Docker image installs the slim locked
pdfprofile (uv sync --locked --extra pdf) rather thanall. PDFs, webpages, Git repositories, Markdown retrieval, and image metadata work in the slim image, while Office documents (docx-to-markdown,xlsx-to-markdown,pptx-to-markdown) and audio transcription (audio-to-markdown) requiremarkitdown[all]and return an actionable error pointing to the full local install (bun install --frozen-lockfile).
Available Tools
Compact Toolset (default, --toolset=compact)
By default, Markdownify MCP exposes 4 capability-aligned tools designed for minimal token overhead across Anthropic, Gemini, and OpenAI hosts:
convert-web-url: Convert any publichttp(s)webpage, YouTube video, Bing search page, or hosted document to Markdownconvert-local-file: Convert any local non-Markdown file (PDF, DOCX, XLSX, PPTX, image, audio) to Markdownconvert-git-repo: Convert a public remote Git repository (http(s)URL or GitHubowner/reposhorthand) into a single Markdown document (optionalbranchandcompress)get-markdown-file: Retrieve an existing local.mdor.markdownfile (case-insensitive) verbatim along with its resolvedrealpath
Classic Toolset (opt-in, --toolset=classic / MCP_TOOLSET=classic)
For backwards compatibility with v1 clients or format-specific tool routing, pass --toolset=classic (or set MCP_TOOLSET=classic) to expose the 11 format-specific tools:
youtube-to-markdown: Convert YouTube videos to Markdownpdf-to-markdown: Convert local PDF files to Markdownbing-search-to-markdown: Convert Bing search result pages to Markdownwebpage-to-markdown: Convert publichttp(s)webpages and hosted documents to Markdownimage-to-markdown: Convert local images to Markdown with metadata (returns empty text when no metadata is present without an external vision LLM)audio-to-markdown: Convert local audio files to Markdown with speech transcription (requiresmarkitdown[all]and network access for Google Speech Recognition)docx-to-markdown: Convert local DOCX files to Markdown (requiresmarkitdown[all])xlsx-to-markdown: Convert local XLSX files to Markdown (requiresmarkitdown[all])pptx-to-markdown: Convert local PPTX files to Markdown (requiresmarkitdown[all])git-repo-to-markdown: Convert a public remote Git repository (http(s)URL or GitHubowner/reposhorthand) into a single Markdown document (optionalbranchandcompress)get-markdown-file: Retrieve an existing local.mdor.markdownfile (case-insensitive) verbatim along with its resolvedrealpath
Key Tool Behavior & Limits
- Strict argument validation: Every tool validates arguments strictly against the active Toolset and rejects unknown/cross-tool keys (e.g.
file_pathinstead offilepath) or unexposed tool names with a single-lineisError: trueerror. - Structured outputs: Successful calls return full untruncated Markdown in both
contenttext blocks andstructuredContent({ markdown }for conversions;{ path, markdown }forget-markdown-file). Error responses (isError: true) omitstructuredContent. - Local paths: All local file tools and
get-markdown-filerequire absolute or~/paths (bare relative paths are rejected), validateMD_ALLOWED_PATHSafterrealpathresolution before checking existence, and verify the target is a readable regular file. - Web URLs: Non-
http(s)schemes and private/loopback/link-local/reserved IPs are blocked on the initial URL and every redirect hop. Non-2xx responses fail with the HTTP status code, and unconverted raw HTML (such as client-only JS SPAs) fails cleanly.
Development & Testing
bun run dev # TypeScript compiler in watch mode
bun run lint # Biome lint + format check (bun run format to auto-fix)
bun run build # Typecheck and compile to dist/
bun test # Run Bun unit, boundary, HTTP, and scenario tests
bun run harness # Interactive mock DD harness (type help)
bun run harness run scenarios # Replay all deterministic mock scenarios
bun run harness live scenarios/live # Run live checks against real local tools/fs
bun run harness docker # Build and verify slim Docker container over MCP stdio
Multi-Form-Factor End-to-End Verification
Verify Markdownify end-to-end across all seven Form Factors (node-stdio, bun-stdio, local-http, docker-stdio, docker-http, npm-package, cli) and both MCP Toolsets (classic and compact):
# Fast local stdio run across curated corpus categories with output previews
bun run harness e2e --form=node-stdio --preview
# Offline local binaries across local stdio & HTTP in opt-in classic Toolset mode
bun run harness e2e --form=node-stdio,bun-stdio,local-http --toolset=classic --category=local-binary
# Ad-hoc probe against any URL or local file
bun run harness e2e --form=node-stdio --tool=convert-web-url --url=https://www.iana.org/domains/reserved
bun run harness e2e --form=node-stdio --tool=get-markdown-file --file=/path/to/README.md
# Full 7-Form-Factor matrix (requires Docker daemon and outbound network)
bun run harness e2e --all
Exit codes: 0 = all passed, 1 = one or more FAILs, 2 = zero FAILs with one or more upstream BLOCKED targets (rate limits / bot walls).
GitHub Actions runs offline 7-Form-Factor verification on every PR (.github/workflows/ci.yml) and full real-internet 7-Form-Factor verification weekly / on-demand (.github/workflows/e2e-live.yml).
Updating Dependencies
Normal installs consume the committed lockfiles; they do not upgrade packages.
- JavaScript: update the intended ranges in
package.json, runbun update --ignore-scripts, then commitpackage.jsonandbun.lock. - Python: update
pyproject.tomlas needed, runuv lock --upgrade, then commitpyproject.tomlanduv.lock. Both the localalland Dockerpdfprofiles are resolved in this one lockfile. - Verify with
uv lock --check,node preinstall.js,bun run lint,bun run build,bun test,bun run harness run scenarios, andbun run harness docker(orbash scripts/docker-smoke-test.sh) when Docker is available.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
More MCP & CLI Projects
- fetch-mcp — Lightweight, SSRF-hardened MCP server and CLI for fetching public web pages as HTML, Markdown, Readability articles, text, JSON, or YouTube transcripts.
- gtasks-mcp — Google Tasks MCP server for managing task lists and to-dos from AI agents.
- spotify-cli — Control Spotify playback, search tracks, and manage playlists from your AI agent or terminal.
- builtwith-mcp — Query website technology stacks via BuiltWith over MCP or the CLI.
License
This project is licensed under the MIT License - see the LICENSE file for details.
探索相关项目
加载中…