Wechat Article For Aiのロゴ

Wechat Article For Ai

コミュニティ
bzd6661

微信公众号文章转 Markdown 工具 | AI Agent 可直接调用的 MCP Server + Skill | Camoufox 反检测、自动重试、批量处理、图片本地化

公開者bzd6661
リポジトリwechat-article-for-ai
言語Python
フォーク
14
スター
103
利用可能なツール
0
通信方式stdio
カテゴリ
リンク
  • ツールをAIワークフローに接続

    Wechat Article For Aiは、対応するAIクライアントやAIエージェントから利用できるMCP機能を提供します。

  • 0個の利用可能なツール

    呼び出し可能なアクションを以下で確認できます。サーバーから提供されている場合は、名前や説明も表示されます。

  • コピーして使える設定

    セットアップ用の設定例を使って、お好みのMCPクライアントにこのサーバーを設定できます。

  • オープンソースの注目度

    リンク先のリポジトリには103件のスターと14件のフォークがあります。

wechat-article-for-ai

English | 中文


English

A modular Python tool that converts WeChat Official Account (微信公众号) articles into clean Markdown files with locally downloaded images. Designed for both human use (CLI) and AI agent integration (MCP server + SKILL.md).

Features

  • Anti-detection scraping — Uses Camoufox (stealth Firefox) to bypass WeChat's bot detection
  • Smart page loading — networkidle wait instead of hardcoded sleep
  • Retry logic — 3× exponential backoff for page fetching, 3× linear backoff for image downloads
  • CAPTCHA detection — Explicit detection with actionable error messages
  • Batch processing — Multiple URLs via args or file input
  • Image localization — Concurrent async downloads with Content-Type based extension inference
  • Code block preservation — Language detection, CSS counter garbage filtering
  • Media extraction — Handles WeChat's <mpvoice> audio and <mpvideo> video elements
  • YAML frontmatter — Structured metadata (title, author, date, source)
  • MCP server — Expose as tools for any MCP-compatible AI client
  • SKILL.md — Ready for Claude Code skill integration

Installation

bash
git clone https://github.com/bzd6661/wechat-article-for-ai.git
cd wechat-article-for-ai
pip install -r requirements.txt

Camoufox browser will be auto-downloaded on first run.

Usage

CLI — Single Article

bash
python main.py "https://mp.weixin.qq.com/s/ARTICLE_ID"

CLI — Batch from File

bash
python main.py -f urls.txt -o ./output -v

CLI Options

FlagDescription
urlsOne or more WeChat article URLs
-f, --file FILEText file with URLs (one per line, # for comments)
-o, --output DIROutput directory (default: ./output)
-c, --concurrency NMax concurrent image downloads (default: 5)
--no-imagesSkip image download, keep remote URLs
--no-headlessShow browser window (for solving CAPTCHAs)
--forceOverwrite existing output
--no-frontmatterUse blockquote metadata instead of YAML frontmatter
-v, --verboseEnable debug logging

MCP Server

Run as an MCP server for AI tool integration:

bash
python mcp_server.py

Tools exposed:

  • convert_article — Convert a single WeChat article to Markdown
  • batch_convert — Convert multiple articles in one call

MCP client configuration (e.g. claude_desktop_config.json):

json
{
  "mcpServers": {
    "wechat-to-md": {
      "command": "python",
      "args": ["mcp_server.py"],
      "cwd": "/path/to/wechat-article-for-ai"
    }
  }
}

Output Structure

output/
  <article-title>/
    <article-title>.md
    images/
      img_001.png
      img_002.jpg
      ...

Project Structure

wechat_to_md/
  __init__.py        # Package init, public API
  errors.py          # CaptchaError, NetworkError, ParseError
  utils.py           # Logging, filename sanitizer, timestamp, image ext inference
  scraper.py         # Camoufox + networkidle + retry with exponential backoff
  parser.py          # BeautifulSoup: metadata, code blocks, media, noise removal
  converter.py       # markdownify + YAML frontmatter + image URL replacement
  downloader.py      # httpx async + retry per image + Content-Type inference
  cli.py             # argparse CLI with batch support
  mcp_server.py      # FastMCP server with convert_article / batch_convert
main.py              # CLI entry point
mcp_server.py        # MCP server entry point
SKILL.md             # AI skill definition

Troubleshooting

ProblemSolution
CAPTCHA / verification pageRun with --no-headless to solve manually
Empty contentWeChat may be rate-limiting; wait and retry
Image download failuresFailed images keep remote URLs; re-run with --force

License

MIT


中文

一个模块化的 Python 工具,将微信公众号文章转换为干净的 Markdown 文件并下载图片到本地。同时支持人工使用(CLI)和 AI 智能体集成(MCP 服务器 + SKILL.md)。

功能特点

  • 反检测抓取 — 使用 Camoufox(隐身 Firefox)绕过微信的反爬机制
  • 智能页面等待 — 使用 networkidle 替代硬编码的 sleep
  • 重试机制 — 页面加载 3 次指数退避重试,图片下载 3 次线性退避重试
  • 验证码检测 — 明确识别验证码页面并给出可操作的错误提示
  • 批量处理 — 支持多个 URL 参数或从文件读取
  • 图片本地化 — 异步并发下载,基于 Content-Type 推断图片格式
  • 代码块保留 — 自动检测编程语言,过滤 CSS 计数器垃圾文本
  • 媒体提取 — 处理微信的 <mpvoice> 音频和 <mpvideo> 视频元素
  • YAML 元数据 — 结构化的 frontmatter(标题、作者、日期、来源)
  • MCP 服务器 — 暴露为工具,供任何 MCP 兼容的 AI 客户端调用
  • SKILL.md — 可直接作为 Claude Code 技能使用

安装

bash
git clone https://github.com/bzd6661/wechat-article-for-ai.git
cd wechat-article-for-ai
pip install -r requirements.txt

Camoufox 浏览器会在首次运行时自动下载。

使用方法

CLI — 单篇文章

bash
python main.py "https://mp.weixin.qq.com/s/文章ID"

CLI — 批量转换

bash
python main.py -f urls.txt -o ./output -v

CLI 参数

参数说明
urls一个或多个微信文章链接
-f, --file 文件包含 URL 的文本文件(每行一个,# 为注释)
-o, --output 目录输出目录(默认:./output)
-c, --concurrency N图片下载最大并发数(默认:5)
--no-images跳过图片下载,保留远程链接
--no-headless显示浏览器窗口(用于手动解决验证码)
--force覆盖已有的输出目录
--no-frontmatter使用引用块格式的元数据,而非 YAML frontmatter
-v, --verbose启用调试日志

MCP 服务器

作为 MCP 服务器运行,供 AI 工具集成:

bash
python mcp_server.py

暴露的工具:

  • convert_article — 转换单篇微信文章为 Markdown
  • batch_convert — 批量转换多篇文章

MCP 客户端配置(如 claude_desktop_config.json):

json
{
  "mcpServers": {
    "wechat-to-md": {
      "command": "python",
      "args": ["mcp_server.py"],
      "cwd": "/path/to/wechat-article-for-ai"
    }
  }
}

输出结构

output/
  <文章标题>/
    <文章标题>.md
    images/
      img_001.png
      img_002.jpg
      ...

项目结构

wechat_to_md/
  __init__.py        # 包初始化,公共 API
  errors.py          # CaptchaError, NetworkError, ParseError
  utils.py           # 日志、文件名清理、时间戳、图片格式推断
  scraper.py         # Camoufox + networkidle + 指数退避重试
  parser.py          # BeautifulSoup:元数据、代码块、媒体、噪音移除
  converter.py       # markdownify + YAML frontmatter + 图片 URL 替换
  downloader.py      # httpx 异步 + 逐图重试 + Content-Type 推断
  cli.py             # argparse CLI,支持批量处理
  mcp_server.py      # FastMCP 服务器
main.py              # CLI 入口
mcp_server.py        # MCP 服务器入口
SKILL.md             # AI 技能定义文件

常见问题

问题解决方法
出现验证码 / 环境异常使用 --no-headless 手动解决验证码
内容为空微信可能在限流,等几分钟再试
图片下载失败失败的图片会保留远程链接,用 --force 重新运行

许可证

MIT

インストール

TypingMind
{
  "mcpServers": {
    "wechat-article-for-ai": {
      "command": "python",
      "args": [
        "mcp_server.py"
      ]
    }
  }
}

Wechat Article For AiのMCPを複数のAIモデルで活用

TypingMindはワークスペース単位でMCPツールに接続します。そのため、一度Wechat Article For Aiに接続すれば、モデルごとに個別に設定することなく、TypingMind内のさまざまなAIモデルで利用できます。 このMCPは、デバイス上のTypingMind MCPコネクタを通じてローカルで動作します。

ローカルコネクタのセットアップガイド

MCPサーバーが、お使いのコンピューター上のローカルファイル、アプリ、非公開リソースにアクセスする必要がある場合は、この方法を使います。

1

MCP設定を開く

TypingMindで「設定」、「詳細設定」、「MCP」の順に進み、「コネクタを設定」を選択してください。

  1. ブラウザでTypingMindを開いてください。
  2. 設定アイコンをクリックしてください。
  3. 「詳細設定」に移動してください。
  4. 「MCP」セクションを開いてください。
  5. 「コネクタを設定」をクリックし、「このデバイス」を選択してください。
「このデバイス」が選択されたTypingMindのMCPコネクタ設定画面
2

コネクタのコマンドを実行

「このデバイス」を選択し、TypingMindからコマンドをコピーしてターミナルで実行してください。MCPの使用中は、プロセスを実行したままにしてください。

  1. TypingMindに表示されるセットアップコマンドをコピーしてください。
  2. macOSではターミナルを、WindowsではWindows Terminalを開いてください。
  3. コマンドを貼り付けて実行してください。
  4. ターミナルで続行の確認を求められた場合は、パッケージのインストールを承認してください。
  5. MCPツールの使用中は、ターミナルウィンドウを開いたまま、プロセスの実行を継続してください。
3

Wechat Article For Aiをサーバーとして追加

コネクタのステータスが「準備完了」になったら、「サーバーを編集」をクリックし、MCPサーバーの設定を貼り付けてください。

  1. コネクタのステータスが「準備完了」になるまでお待ちください。
  2. 「サーバーを編集」をクリックしてください。
  3. Wechat Article For AiのMCPサーバー設定を貼り付けてください。
  4. サーバー一覧を保存してください。
  5. コネクタが引き続き使用可能か確認するには、更新してください。
稼働中のサーバーと「サーバーを編集」ボタンが表示されたTypingMindのMCP設定画面
{
  "mcpServers": {
    "wechat-article-for-ai": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

複数のモデルで同じ接続を使用

サーバー一覧を保存し、「プラグイン」を開いてWechat Article For AiのMCPツールを有効にしてください。その後、TypingMindで対応するAIモデルを選択し、チャットでツールを使うか、AIエージェントに割り当ててください。

  1. TypingMindの「プラグイン」ページを開いてください。
  2. Wechat Article For AiのMCPツールを有効にしてください。
  3. チャットを開始し、使用するAIモデルを選択してください。
  4. MCPツールをチャットで使うか、AIエージェントに割り当ててください。
  5. MCPに再接続することなく、必要に応じて別のAIモデルに切り替えられます。
選択したAIモデルと有効なMCPツールを使用したTypingMindのチャット
Wechat Article For Aiを使ってこのタスクを手伝ってもらえますか?
Wechat Article For Ai
はい、読みました。
Wechat Article For Aiで調べた結果をお伝えします。

よくある質問

Wechat Article For Ai MCPサーバーは何に使いますか?

Wechat Article For Aiは、対応するAIクライアントを外部ツールやコンテキストに接続するためのMCPサーバーです。TypingMindでは、このMCPサーバーを一度追加するだけで、AIワークスペース内でそのツールを利用できるようになります。

TypingMindでWechat Article For Ai MCPを複数のAIモデルと併用できますか?

はい。TypingMindはワークスペース単位でMCPツールに接続するため、モデルごとにMCPサーバーを設定する必要はありません。Claude、ChatGPT、Geminiや、TypingMindで設定したその他のAIモデルでWechat Article For Aiを利用できます。

TypingMindでWechat Article For Ai MCPを使うメリットは何ですか?

TypingMindは、複数のAIモデル、プロンプト、プラグイン、AIエージェント、APIキー、MCPツールを1つのワークスペースにまとめられる、LLMチャット向けの優れたフロントエンドです。Wechat Article For Aiを接続すると、TypingMindでチャットのワークフローを整理しながら、お好みのモデルでそのMCPツールを利用できます。

Wechat Article For Ai MCPをTypingMindに接続するにはどうすればよいですか?

Wechat Article For AiはTypingMindのローカルMCPコネクタ経由で動作します。MCPサーバーがコンピューター上のローカルファイル、デスクトップアプリ、コマンドラインツール、プライベートリソースにアクセスする必要がある場合に最適です。

TypingMindでWechat Article For Ai MCPのどのようなツールを利用できますか?

Wechat Article For AiはMCP機能を提供しています。TypingMindのプラグインページで有効にすると、チャットで使用したり、AIエージェントに割り当てたりできます。

Wechat Article For Ai MCPを使うには、APIキーをTypingMindと共有する必要がありますか?

いいえ。TypingMindはローカルファーストの設計で、モデルプロバイダー、APIキー、プロンプト、MCP設定をご自身で管理できます。Wechat Article For Aiで認証が必要な場合は、接続の作成時に、そのMCPサーバーに必要なヘッダー、OAuth設定、またはローカル設定を追加してください。

関連するMCPサーバー

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇