Content
# wx-mcp-analyzer
WeChat article parsing MCP server that fetches and cleans WeChat articles for downstream processing.
## Features
- **Article Fetching**: Uses Playwright to render WeChat articles from `mp.weixin.qq.com`
- **HTML Cleaning**: Removes scripts, styles, and inline events; normalizes images
- **MCP Integration**: Compatible with Claude Desktop and other MCP clients
## Quick Start
### Prerequisites
- Python 3.12+
- [uv](https://docs.astral.sh/uv/) package manager
### Installation and Run
```bash
# Install dependencies (including Playwright browsers)
uv sync
uv run playwright install chromium
# Run the MCP server
uv run python src/server/app.py
```
### Available Tools
1. **`health_check`**: Verify server status and environment
2. **`fetch_wechat_article`**: Fetch and clean WeChat articles
Example `fetch_wechat_article` usage:
```json
{
"url": "https://mp.weixin.qq.com/s/article-id",
"timeout_sec": 20,
"inline_images": false
}
```
### Usage with Claude Desktop
有几种方式在 Claude Desktop 中配置此 MCP 服务器:
#### 方式一:使用本地开发模式(推荐用于开发)
```json
{
"mcpServers": {
"wx-mcp-analyzer": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/wx-mcp-analyzer-mcp-openspec",
"run",
"python",
"wx_mcp_analyzer/server/app.py"
]
}
}
}
```
#### 方式二:使用 uvx 从本地 wheel 文件
```json
{
"mcpServers": {
"wx-mcp-analyzer": {
"command": "uvx",
"args": [
"--from",
"/absolute/path/to/wx-mcp-analyzer-mcp-openspec/dist/wx_mcp_analyzer-0.1.0-py3-none-any.whl",
"wx-mcp-analyzer"
]
}
}
}
```
#### 方式三:使用 uvx 从当前目录(如果在项目目录下)
```json
{
"mcpServers": {
"wx-mcp-analyzer": {
"command": "uvx",
"args": [
"--from",
".",
"wx-mcp-analyzer"
],
"cwd": "/absolute/path/to/wx-mcp-analyzer-mcp-openspec"
}
}
}
```
**注意**: 将 `/absolute/path/to/wx-mcp-analyzer-mcp-openspec` 替换为此项目的实际绝对路径。
### 发布到 PyPI(可选)
如果你想发布到 PyPI 以便其他人使用:
```bash
# 发布到 PyPI(需要 PyPI 账户和 token)
uv publish
# 然后其他人可以直接使用
uvx wx-mcp-analyzer
```
Claude Desktop 配置(发布后):
```json
{
"mcpServers": {
"wx-mcp-analyzer": {
"command": "uvx",
"args": ["wx-mcp-analyzer"]
}
}
}
```
## Development
### Running Tests
```bash
# Run fast tests only (recommended for development)
uv run pytest -m "not slow"
# Run all tests including slow integration tests
uv run pytest
# Run specific test file
uv run pytest tests/test_cleaner.py -v
```
### Project Structure
```
src/
├── server/ # FastMCP server and tool definitions
├── fetcher/ # Playwright-based page fetching
└── cleaner/ # HTML cleaning and normalization
tests/
├── test_cleaner.py # Unit tests for HTML cleaner
└── test_fetcher.py # Smoke tests for fetcher (marked as slow)
```