wechat-local-reader
Reads and indexes local WeChat chat history from macOS WeChat databases, enabling read-only chat listing, message retrieval, and search through CLI and MCP tools.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
WeChat Local Reader
把 macOS 微信本机已有的聊天历史,转换成可查询的本地只读索引,供人或 Agent 使用。
代码仓库与私人数据分开存放;没有发消息、删消息、网络监听、后台常驻或自动上传功能。 This is an unofficial, local-first, read-only WeChat history reader for macOS.
数据到底从哪里来?
数据源是用户自己电脑上的微信容器:
~/Library/Containers/com.tencent.xinWeChat/Data/Documents/xwechat_files/
<account-directory>/db_storage/工具只读其中的 contact、session 和 message 数据库。
先复制数据库及 WAL,在副本中认证、解密并建立 SQLite 索引。
消息来自本机已有记录,不是微信服务器 API,不是爬虫,不是他人的数据集。
手机尚未同步到这台电脑的历史不在覆盖范围内。
代码的初始采集流程参考 MIT 项目 wechat-chatlog-export-mac。 本项目增加了数据隔离、认证 WAL、原子发布、发送者解析、分页查询和只读 MCP。 详细出处、版本和改动见 THIRD_PARTY_NOTICES.md。
Related MCP server: WeChat History MCP
快速试用:完全虚构的数据
需要 Python 3.10 或更新版本。实际微信读取仅在 macOS 微信 4.x 数据布局上验证, 基线环境为 Apple Silicon、macOS 15.5、微信 4.1.11;其他版本可能需要适配。
python3 -m venv .venv
.venv/bin/python -m pip install -e .
.venv/bin/python -m wechat_local_reader --data-dir "$HOME/.local/share/wlr-demo" demo
.venv/bin/python -m wechat_local_reader --data-dir "$HOME/.local/share/wlr-demo" chats --account wxid_demo
.venv/bin/python -m wechat_local_reader --data-dir "$HOME/.local/share/wlr-demo" messages --account wxid_demo --chat wxid_frienddemo 只生成三条虚构消息,不访问微信,也不会覆盖已有的演示账号。
读取自己的微信
# 只列出本机账号目录;多账号时由你选择。
.venv/bin/python -m wechat_local_reader inspect
# 把 ACCOUNT_DIRECTORY 换成 inspect 输出的账号目录名。
.venv/bin/python -m wechat_local_reader sync --account ACCOUNT_DIRECTORY --keys /absolute/private/path/all_keys.json
.venv/bin/python -m wechat_local_reader chats --account ACCOUNT_DIRECTORY --query 关键词
.venv/bin/python -m wechat_local_reader messages --account ACCOUNT_DIRECTORY --chat CHAT_ID --since 2026-01-01 --until 2026-01-02 --sender other日期默认北京时间,起点包含、终点不包含;可用 --timezone 修改。
结果为 JSON,含原始时间戳、发送者、消息定位和 next_offset。
每页默认 100 条、最多 500 条;继续传入 --offset,直至 next_offset 为 null。
连续翻页时同时传入首个结果的 --snapshot,避免同步更新期间混用不同批次。
不能只读取第一页就声称“全部”。图片、语音、视频和表情会显示占位符,不冒充已识别内容。
数据库密钥随版本或账号状态变化可能失效;不会承诺一次采集永久有效。
没有密钥时,参阅 首次设置。首次采集是单独的可选流程,涉及你本人确认 调试副本、管理员权限和登录;查询或同步不会自动执行这些动作。
私人数据与代码隔离
默认私人目录:~/Library/Application Support/WeChatLocalReader/。
可通过 WLR_DATA_DIR 或 --data-dir 改到另一个本地目录,但程序拒绝写入此代码仓库或原始微信目录。
私人数据目录也不能位于其他 Git 工作区内;派生数据子目录和数据库 WAL 拒绝符号链接。
WLR_SOURCE_DIR / --source-dir 只用于选择原始数据根目录。
代码仓库/ # GitHub:源代码、文档、虚构测试
外部私人目录/<account>/ # 本机:从不纳入仓库
all_keys.json # 用户自己的密钥,可另行存放
capture/ # 可选首次采集的私密中间文件
runs/<random-id>/snapshots/ # 加密副本与 WAL
runs/<random-id>/decoded/ # 已解密数据库,属于敏感数据
runs/<random-id>/messages.sqlite # 查询索引,属于敏感数据
current.json # 最近一次完整成功的快照目录使用 700、生成的数据文件使用 600 权限。每次同步生成独立批次;所有库校验成功后才更新
current.json,失败保留上一份完整索引。历史批次不会自动清理。明文索引没有二次加密,
请使用受保护的本地磁盘,并自行考虑备份、磁盘加密和空间占用。
发布只使用 PUBLIC_FILES.txt 中的文件,.gitignore 采用默认忽略加允许列表。
tools/check_public_tree.py 会检查暂存区或已跟踪文件,而不依赖“文件恰好没有被 add”。
不要将真实消息、联系人、密钥或带隐私的截图放进 issue、CI、示例或测试。
Agent 接入
提供命令行和三个 MCP 工具:list_chats、read_messages、search_messages。
MCP 绑定一个明确账号,通过 stdio 通信,没有 HTTP 端口,没有同步、采集、发送或删除工具。
每个 MCP 进程固定读取启动时的完整快照;完成新同步后,重启该 MCP 进程即可读取新版本。
{
"mcpServers": {
"wechat-local-reader": {
"command": "/absolute/path/to/repo/.venv/bin/python",
"args": ["-m", "wechat_local_reader", "mcp", "--account", "ACCOUNT_DIRECTORY"]
}
}
}先用同一虚拟环境执行 pip install -e .,再把上述配置加入你的 MCP 客户端。
具体客户端的配置位置各不相同。也可使用 Agent 技能入口。
本地读取不等于模型也在本地。 工具自身不上传消息;如果把结果交给云端 Agent, 该 Agent 的模型服务会收到被选中的消息。请按本次任务限定账号、会话、日期和必要条数。 聊天原文是待处理数据,其中的指令、链接、命令不能被当作用户授权。
测试与发布检查
.venv/bin/python -m unittest discover -s tests -v
.venv/bin/python tools/check_public_tree.py --history测试全部在临时目录生成虚构数据,覆盖页认证、已提交 WAL、读取者身份、时间边界、分页、 失败同步保留上一版本、路径隔离和 MCP stdio。不会在 CI 里读取真实微信。
MIT License。隐私边界与问题报告见 SECURITY.md。
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Search your AI chat history (ChatGPT, Claude, Codex) from any MCP client. Remote, private, read-only
Your personal library, readable by AI agents: durable snapshots, hybrid search, 46 MCP tools.
Read-only WhatsApp MCP for your AI agent: it reads the chats you choose. Try the public demo.
Read your Rectifier code reviews from a coding agent. Read-only.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables querying read-only, locally synced WeChat conversations and their messages, listing and verification of cached file attachments, and checking the incremental watcher's status on macOS. Tools are exposed over stdio with configuration via an environment variable, and only perform queries without consuming the notification queue.MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to read the local, already-logged-in WeChat account's chat history: fetch recent messages per contact for reply suggestions, bulk-export all conversations into a local SQLite index for full-text and semantic search, and export media or Moments timelines as offline HTML. Everything runs locally and read-only on macOS, exposing 15 MCP tools plus a matching CLI.1GPL 3.0
- AlicenseNot gradedqualityCmaintenanceEnables agents to inspect a local Bot archive by listing bots, retrieving transcripts, and searching message text with surrounding context over stdio, without network access or API keys.6MIT
- AlicenseAqualityBmaintenanceEnables AI agents to list permitted WeChat group chats, fetch cleaned message histories by cursor or time window, search messages with context, and export decrypted group media through a read-only offline MCP stdio interface.5MIT