Skip to main content
Glama
WeChat Readonly MCP
by Sereneoned
README.md
# WeChat Readonly MCP (`wechat-readonly-mcp`)

[English](README.md) | [简体中文](README.zh-CN.md)

**A local-first, strictly read-only MCP server & Antigravity plugin for Windows WeChat 4.x — giving AI agents real-time access to chats, received documents (PDF/Office/ZIP/code), V2/WXGF decrypted images, offline SenseVoiceSmall voice transcription, favorites, official accounts, and moments without screenshots or copy-pasting.**

> **Disclaimer**: Intended strictly for reading **your own** local WeChat data on your own machine to assist personal productivity. Zero network upload, zero message sending, zero UI automation, zero client modification.

---

## Why This Exists

When working with AI coding/research agents (Antigravity, Claude Code, Codex, Cursor), critical context constantly arrives inside WeChat: project requirements in group chats, PDFs/Excel sheets sent by collaborators, screenshots stored as encrypted `.dat` files, and 40-second voice notes.

Instead of manually screenshotting, exporting files, or transcribing voice memos by hand, **WeChat Readonly MCP** exposes a **strictly read-only**, real-time local MCP bridge covering **text + files + images + voice** end-to-end.

---

## Key Features (v1.1.0)

- **Real-time incremental SQLCipher 4 WAL sync**: Tracks `mtime` + WAL salts and incrementally patches only new WAL frames instead of re-decrypting huge `message_*.db` shards on every message.
- **Automatic WeChat 4.2 V2 & `WXGF` (HEVC) image decryption**:
  - Supports Legacy XOR, V1 AES, V2 AES+XOR, and Tencent's proprietary **`wxgf`** (HEVC-wrapped) image container.
  - Derives per-account V2 image keys **100% offline** from `kvcomm` statistic filenames (zero memory scan needed, with read-only live fallback) and transcodes `WXGF` -> standard JPEG in memory via `PyAV` / `ffmpeg`.
- **100% offline SILK v3 voice-to-text transcription**:
  - Reads `SILK v3` voice blobs directly from `message/media_0.db`, decodes to 16 kHz PCM in memory (`silk-python`), and transcribes locally via `sherpa-onnx` + **`SenseVoiceSmall int8`** (`zh` / `en` / `ja` / `ko` / `yue` + punctuation).
  - Caches transcripts per `(chat_id, local_id)` locally so repeated reads are instantaneous and automatically inline into `wechat_get_messages`.
- **Full-format received document reader**:
  - Directly extracts text from **PDF** (PyMuPDF / pypdf), **DOCX** (paragraphs + tables), **XLSX** (all sheets), **PPTX** (slides + speaker notes), **TXT / MD / JSON / CSV / HTML / source code**, and **ZIP** archives (with Windows CP437 -> GB18030 Chinese filename repair).
- **15 strictly read-only MCP tools** over lightweight JSON-RPC 2.0 `stdio` (supports both LSP `Content-Length` and newline framing; no heavyweight MCP SDK required).
- **Antigravity Plugin Ready**: Ships with `plugin.json`, `mcp_config.json`, `rules/AGENTS.md` (proactive auto-query rule), and `skills/wechat-readonly/SKILL.md`.

---

## 15 Read-Only MCP Tools

| Tool | Capability |
| :--- | :--- |
| `wechat_list_sessions` | List recent DMs & group chats with unread counts, timestamps, and last message |
| `wechat_resolve_chat` | Fuzzy-match contact remark, nickname, alias, or group name to exact `chat_id` |
| `wechat_get_messages` | Read paginated chat messages by period (`today`, `7d`, date range) or type; parses quotes, merged forwards, files, images, and cached/on-demand voice text (`transcribe_voice=true`) |
| `wechat_search_messages` | Keyword search inside one chat or globally across all chats (handles `zstd`-compressed rows) |
| `wechat_get_context` | Fetch N messages before and after any `local_id` search hit |
| `wechat_get_group_members` | List group owner and all members of a `@chatroom` |
| `wechat_list_files` | Browse/filter received files on disk (`msg/file/`) by name, extension, or month |
| `wechat_read_file` | Extract full text from PDF, DOCX, XLSX, PPTX, ZIP (list or read inner entries), HTML, and source code |
| `wechat_get_image` | Decrypt `.dat` images (Legacy/V1/V2/WXGF -> JPEG/PNG) by MD5, path, or recent chat images |
| `wechat_get_voice` | Extract SILK v3 voice messages from `media_0.db` and transcribe offline via SenseVoiceSmall |
| `wechat_get_favorites` | Browse or search WeChat Favorites (收藏) |
| `wechat_get_biz_messages` | Browse or search Official Account (公众号) articles and pushes |
| `wechat_get_moments` | Browse or search Moments (朋友圈) posts |
| `wechat_get_stats` | Aggregate message counts, type breakdown, and top senders |
| `wechat_status` | Inspect unlocked DBs, ASR readiness, cache stats, and trigger `refresh_keys=true` after a WeChat restart |

---

## Quick Start (Windows WeChat 4.x)

Prerequisites: **Windows 10/11**, **WeChat 4.x** (tested on `4.2.0.53`), **Python 3.10+**.

### Option 1: One-Click Antigravity Plugin Install

```bash
git clone https://github.com/Sereneoned/wechat-readonly-mcp.git
cd wechat-readonly-mcp
python scripts/install.py --install-deps --download-asr
```

- `--install-deps` installs Python dependencies from `requirements.txt`.
- `--download-asr` downloads the ~160 MB offline `SenseVoiceSmall int8` model into `~/.wechat-readonly-mcp/asr_models/` (skip this flag if you don't need voice transcription).
- Keep WeChat logged in, restart Antigravity, and ask naturally: *"Check my unread WeChat messages"* or *"Summarize the latest PDF received on WeChat"*.

### Option 2: Generic MCP Client (Claude Code / Codex / Cursor)

```bash
pip install -r requirements.txt
```

Add to your client's MCP config:

```json
{
  "mcpServers": {
    "wechat-readonly": {
      "command": "python",
      "args": ["-u", "/absolute/path/to/wechat-readonly-mcp/server/mcp_server.py"]
    }
  }
}
```

---

## Security & Privacy Guarantees

- **Zero write / zero send surface**: Only read-only SQLite URI connections (`?mode=ro`) and read-only `OpenProcess(0x0410)` / `ReadProcessMemory` calls for key derivation; no message-sending or UI-control APIs exist anywhere in the codebase.
- **100% local execution**: Database decryption, image decoding, document parsing, and SenseVoiceSmall ASR all run locally — no data is sent to any third-party cloud service.
- **Prompt-injection hygiene**: Every tool output is wrapped with an explicit `UNTRUSTED_WECHAT_DATA` framing notice, and all tools declare `readOnlyHint: true`, `destructiveHint: false`.
- **Never commit local state**: Local keys (`all_keys.json`, `media_keys.json`), decrypted DB caches, decoded images, and voice caches live exclusively under `${PLUGIN_DATA}` / `~/.wechat-readonly-mcp/` outside the repository.

---

## Architecture & Credits

See [docs/architecture.md](docs/architecture.md) for the internal pipeline diagram and [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) for open-source acknowledgements.

Licensed under the [MIT License](LICENSE).