mcpField
M
markitdown

markitdown

github.com/julianobarbosaドキュメント141.6k 回インストール2 日前に更新
リポジトリ

markitdown について

MarkItDown は、さまざまなファイルやコンテンツを LLM やテキスト分析向けの Markdown に変換する Microsoft の Python ツールです。文書、メディア、Web コンテンツ、データ、アーカイブ、メールに対応し、コマンドライン、Python API、プラグインを提供します。

主な機能

  1. 01PDF、Office 文書などを変換
  2. 02見出し、リスト、表、リンクの構造を保持
  3. 03コマンドラインと Python API を提供
  4. 04サードパーティ製変換プラグインに対応
  5. 05MCP サーバーとして LLM アプリに統合

活用シーン

  1. 01LLM 処理向けに文書を Markdown 化
  2. 02ディレクトリ内のファイルを一括変換
  3. 03YouTube の字幕、RSS、Wikipedia の内容を抽出
  4. 04Claude Desktop などの LLM アプリに変換機能を追加

MCP 対応

MarkItDown は、Claude Desktop などの LLM アプリと連携する MCP サーバーを提供します。MCP クライアントは、この連携を通じてファイル変換機能を利用できます。

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/julianobarbosa/claude-code-skills --skill markitdown

インストール後、Claude Code で/markitdownを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

references/
advanced-features.md
api-reference.md
cli-reference.md
examples.md
scripts/
batch-convert.py
batch-convert.sh
convert-jupyter.py

詳細

MarkItDown スキル

LLM やテキスト分析のパイプライン向けに、さまざまなファイル形式を Markdown に変換する Microsoft の Python ユーティリティです。

概要

MarkItDown は、構造(見出し、リスト、表、リンク)を保持したままドキュメントを変換します。人間が読みやすい出力ではなく、LLM が利用しやすい出力に最適化されています。

対応形式
カテゴリ形式
ドキュメントPDF、Word(DOCX)、PowerPoint(PPTX)、Excel(XLSX、XLS)
メディア画像(EXIF + OCR)、音声(WAV、MP3 の文字起こし)
WebHTML、YouTube URL、Wikipedia、RSS/Atom フィード
データCSV、JSON、XML、Jupyter ノートブック(.ipynb)
アーカイブZIP(内容を順に処理)、EPub
メールOutlook MSG ファイル

クイックスタート

インストール
# Full installation (recommended)
pip install 'markitdown[all]'

# Minimal with specific formats
pip install 'markitdown[pdf,docx,pptx]'

# Using uv
uv pip install 'markitdown[all]'
オプションの依存関係
Extra説明
[all]すべてのオプションの依存関係
[pdf]PDF ファイルのサポート
[docx]Word ドキュメント
[pptx]PowerPoint プレゼンテーション
[xlsx]Excel スプレッドシート
[xls]旧形式の Excel ファイル
[outlook]Outlook MSG ファイル
[az-doc-intel]Azure Document Intelligence
[audio-transcription]WAV/MP3 の文字起こし
[youtube-transcription]YouTube 動画の文字起こし
コマンドラインの使用方法
# Basic conversion
markitdown document.pdf > output.md

# Specify output file
markitdown document.pdf -o output.md

# Pipe input
cat document.pdf | markitdown > output.md

# With Azure Document Intelligence
markitdown document.pdf -o output.md -d -e "<endpoint>"
Python API
from markitdown import MarkItDown

# Basic conversion
md = MarkItDown()
result = md.convert("document.xlsx")
print(result.text_content)

# With LLM for image descriptions
from openai import OpenAI

client = OpenAI()
md = MarkItDown(
    llm_client=client,
    llm_model="gpt-4o",
    llm_prompt="Describe this image in detail"
)
result = md.convert("image.jpg")
print(result.text_content)

# With Azure Document Intelligence
md = MarkItDown(docintel_endpoint="<your-endpoint>")
result = md.convert("complex-document.pdf")
print(result.text_content)

一般的なユースケース

ディレクトリの一括変換
from markitdown import MarkItDown
from pathlib import Path

md = MarkItDown()
input_dir = Path("./documents")
output_dir = Path("./markdown")
output_dir.mkdir(exist_ok=True)

for file in input_dir.glob("*"):
    if file.is_file():
        try:
            result = md.convert(str(file))
            output_file = output_dir / f"{file.stem}.md"
            output_file.write_text(result.text_content)
            print(f"Converted: {file.name}")
        except Exception as e:
            print(f"Failed: {file.name} - {e}")
LLM コンテキスト向けの処理
from markitdown import MarkItDown

def prepare_for_llm(file_path: str) -> str:
    """Convert document to LLM-ready markdown."""
    md = MarkItDown()
    result = md.convert(file_path)

    # Add source reference
    content = f"# Source: {file_path}\n\n{result.text_content}"
    return content

# Use with your LLM
context = prepare_for_llm("report.pdf")
YouTube の文字起こしを抽出
# CLI
markitdown "https://www.youtube.com/watch?v=VIDEO_ID" > transcript.md
# Python
from markitdown import MarkItDown

md = MarkItDown()
result = md.convert("https://www.youtube.com/watch?v=VIDEO_ID")
print(result.text_content)
AI による説明付きの画像 OCR
from markitdown import MarkItDown
from openai import OpenAI

# Initialize with LLM support
client = OpenAI()
md = MarkItDown(
    llm_client=client,
    llm_model="gpt-4o"
)

# Convert image with AI description
result = md.convert("screenshot.png")
print(result.text_content)
Jupyter ノートブックの変換
from markitdown import MarkItDown

md = MarkItDown()
result = md.convert("analysis.ipynb")
print(result.text_content)  # Code cells, outputs, markdown
Wikipedia のコンテンツを抽出
from markitdown import MarkItDown

md = MarkItDown()
result = md.convert("https://en.wikipedia.org/wiki/Python")
print(result.text_content)  # Main article content only
RSS フィードの解析
from markitdown import MarkItDown

md = MarkItDown()
result = md.convert("https://example.com/feed.xml")
print(result.text_content)  # Feed entries as markdown

プラグインシステム

MarkItDown は、機能を拡張するサードパーティ製プラグインに対応しています。

# List installed plugins
markitdown --list-plugins

# Enable plugins during conversion
markitdown --use-plugins document.pdf
# Enable plugins in Python
md = MarkItDown(enable_plugins=True)
result = md.convert("document.pdf")

GitHub で #markitdown-plugin を検索すると、利用可能なプラグインを見つけられます。

MCP サーバーとの統合

MarkItDown は、Claude Desktop などの LLM アプリケーションと統合するための MCP(Model Context Protocol)サーバーを提供しています。

# Install MCP server
pip install markitdown-mcp

# Or from source
git clone https://github.com/microsoft/markitdown.git
cd markitdown/packages/markitdown-mcp
pip install -e .

設定の詳細は、markitdown-mcp を参照してください。

Docker の使用方法

# Build image
docker build -t markitdown:latest .

# Convert file
docker run --rm -i markitdown:latest < document.pdf > output.md

トラブルシューティング

問題解決策
依存関係が不足しているpip install 'markitdown[all]' でインストールしてください
PDF の抽出に失敗する複雑な PDF には Azure Document Intelligence をお試しください
画像内のテキストが抽出されないOCR の依存関係がインストールされていることを確認するか、LLM モードを使用してください
大きなファイルがタイムアウトするチャンクに分けて処理するか、ストリーミングを使用してください
プラグインが見つからないmarkitdown --list-plugins を実行して、インストールを確認してください
よくあるエラー
# ModuleNotFoundError for specific format
pip install 'markitdown[pdf]'  # Install missing dependency

# Azure authentication
export AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT="<endpoint>"
export AZURE_DOCUMENT_INTELLIGENCE_KEY="<key>"

要件

  • Python >= 3.10
  • 仮想環境の使用を推奨
# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # Linux/macOS
.venv\Scripts\activate     # Windows

# Install
pip install 'markitdown[all]'

参考資料


注意点

  • 埋め込み画像を含む DOCX:画像は別ファイルに抽出され、Markdown では絶対パスが使用されます — Markdown ファイルだけを移動すると、画像参照が壊れます。
  • PDF OCR の信頼度は出力されません — 信頼度の低いテキストも確実な情報であるかのように返されるため、後続の LLM 利用で誤りを確信を持って出力するおそれがあります。
  • XLSX の結合セルは、アンカー以外の位置が空の値を持つ個別のセルとして抽出されます — ピボット形式のレポートでは、列グループが気付かないうちに失われます。
  • HTML から Markdown への変換では、CSS によるレイアウトが失われます — 列の位置で配置された表は行優先の直線的な出力に変わり、複雑な表は解析できなくなります。
  • 画像の説明に使う --use-llm フラグは、OPENAI_API_KEY がない場合にファイル名へ暗黙にフォールバックします — 出力は埋まっているように見えますが、実際の説明は含まれません。

コメント