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 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 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 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  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 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 Wechat Article For Ai MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 Wechat Article For Ai 帮我完成这项任务吗?
Wechat Article For Ai
当然,我看过了。
以下是我使用 Wechat Article For Ai 得到的结果。

常见问题

Wechat Article For Ai MCP 服务器有什么用途?

Wechat Article For Ai 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 Wechat Article For Ai MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您无需为每个模型单独配置 MCP 服务器,就能在 Claude、ChatGPT、Gemini 或您在 TypingMind 中配置的其他 AI 模型中使用 Wechat Article For Ai。

为什么在 TypingMind 中使用 Wechat Article For Ai MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是最出色的大语言模型聊天前端之一。连接 Wechat Article For Ai 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 Wechat Article For Ai MCP 连接到 TypingMind?

Wechat Article For Ai 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

Wechat Article For Ai MCP 在 TypingMind 中提供哪些工具?

Wechat Article For Ai 提供 MCP 功能,您可以在 TypingMind 的插件页面启用这些功能,然后在聊天中使用,或将其分配给 AI 智能体。

使用 Wechat Article For Ai MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行选择模型提供商,并自行管理 API 密钥、提示词和 MCP 配置。如果 Wechat Article For Ai 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇