小红书笔记监测 Skill
基于 xiaohongshu MCP Skill 构建的笔记互动量轮询监测系统。
前置条件
xiaohongshuSkill 已安装jq已安装
MCP 服务启动(重要)
关键约束:WorkBuddy 沙箱会在跨 turn 时 kill 后台进程,因此 MCP 服务不能独立保持运行,必须在每次操作的同一命令链中启动。
标准启动 + 操作模式
# 必须将启动和业务操作写在一条命令链中(&& 串联)
/Users/chengjianfen/.local/bin/xiaohongshu-mcp -port :18060 &>/tmp/rednote-mcp-tmp/mcp.log & sleep 5 && <后续操作>
获取 MCP Session ID
INIT=$(curl -s --noproxy '*' -i --max-time 10 -X POST http://localhost:18060/mcp \
-H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"m","version":"1"}}}')
SID=$(echo "$INIT" | grep -i 'mcp-session-id' | awk -F': ' '{print $2}' | tr -d '\r\n ')
curl -s --noproxy '*' --max-time 5 -X POST http://localhost:18060/mcp \
-H 'Content-Type: application/json' -H "mcp-session-id: $SID" \
-d '{"jsonrpc":"2.0","method":"notifications/initialized"}' > /dev/null
登录管理
Cookie 有效期约 30 天,过期后需扫码:
curl -s --noproxy '*' --max-time 30 -X POST http://localhost:18060/mcp \
-H 'Content-Type: application/json' -H "mcp-session-id: $SID" \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"get_login_qrcode","arguments":{}}}' \
| jq -r '.result.content[] | select(.type=="image") | .data' | base64 -d > /tmp/rednote-qr.png
然后 present_files 展示 /tmp/rednote-qr.png 给用户扫码。
架构
用户对话 → 助理调用脚本
│
┌───────────┼───────────┐
│ │ │
▼ ▼ ▼
add-task list-tasks delete-task
│ │
▼ ▼
tasks.json ←──── 管理操作 ────→ tasks.json
自动化定时触发
│
▼
check-all.sh
│
┌─────────┼─────────┐
│ │ │
▼ ▼ ▼
轮询MCP → 阈值判断 → 告警/静默
│
▼
data/{task_id}/YYYY-MM-DD.json
脚本清单
| 脚本 | 用途 |
|------|------|
| add-task.sh | 添加监测任务 |
| list-tasks.sh | 列出所有任务 |
| delete-task.sh | 删除任务 |
| show-task.sh | 查看单个任务详情 |
| check-all.sh | 遍历所有活跃任务,执行一次轮询检查 |
| check-feed.sh | 对单个笔记执行一次数据拉取 |
| send-alert.sh | 发送告警(企业微信/邮件) |
| gen-trend.sh | 生成交互数据趋势 HTML |
| utils.sh | 公共函数(随机等待、URL解析等) |
使用流程
1. 添加监测任务
用户提供笔记链接和监测条件,助理执行以下步骤:
Step 1:解析笔记链接
支持格式:
- https://www.xiaohongshu.com/explore/{feed_id}
- https://www.xiaohongshu.com/discovery/item/{feed_id}
- https://xhslink.com/...(短链,需先解析)
如果链接是短链(xhslink.com),先用 curl -sI "<url>" | grep -i location 获取重定向后的完整链接,再从中提取 feed_id。
Step 2:直接提取 xsec_token 和 feed_id
从用户提供的 URL 中直接提取:
source "${HOME}/.workbuddy/skills/rednote-monitor/scripts/utils.sh"
FID=$(parse_feed_id "$url")
XTOKEN=$(echo "$url" | sed -n "s/.*xsec_token=\([^&]*\).*/\1/p")
如果 URL 中不含 xsec_token(如短链),需先解析短链获取完整 URL 后再提取。
Step 3:拉取笔记详情确认
使用以下 MCP 调用获取笔记数据(需先启动 MCP 服务):
curl -s --noproxy '*' --max-time 30 -X POST http://localhost:18060/mcp \
-H 'Content-Type: application/json' -H "mcp-session-id: $SID" \
-d "{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"tools/call\",\"params\":{\"name\":\"get_feed_detail\",\"arguments\":{\"feed_id\":\"${FID}\",\"xsec_token\":\"${XTOKEN}\"}}}"
重要:API 返回的 JSON 路径为 data.note 而非 data.items[0].note_card。互动数据字段为 camelCase:
.data.note.title→ 标题.data.note.user.nickname→ 作者.data.note.interactInfo.likedCount→ 点赞.data.note.interactInfo.collectedCount→ 收藏.data.note.interactInfo.commentCount→ 评论.data.note.interactInfo.sharedCount→ 分享
确认笔记存在,记录标题和当前互动数据。
Step 4:确认监测参数
向用户确认以下参数(如用户未明确提供则询问):
- 监测指标与阈值:如
点赞≥1000、评论≥200、收藏≥100、分享≥50(可多选,也可单选) - 监测间隔:如
15分钟、30分钟、1小时(默认30分钟) - 告警方式:
wecom(企业微信 Webhook)或email - 告警配置:企业微信 Webhook URL 或邮箱地址
- 任务备注名:可选,方便识别
Step 5:写入任务
skill_dir="${HOME}/.workbuddy/skills/rednote-monitor/scripts"
bash "${skill_dir}/add-task.sh" \
'<json_payload>'
2. 查看监测列表
用户说「查看监测列表」时执行:
skill_dir="${HOME}/.workbuddy/skills/rednote-monitor/scripts"
bash "${skill_dir}/list-tasks.sh"
3. 查看任务详情
skill_dir="${HOME}/.workbuddy/skills/rednote-monitor/scripts"
bash "${skill_dir}/show-task.sh" <task_id>
4. 删除监测任务
skill_dir="${HOME}/.workbuddy/skills/rednote-monitor/scripts"
bash "${skill_dir}/delete-task.sh" <task_id>
5. 手动检查
可随时手动触发单次全量检查:
skill_dir="${HOME}/.workbuddy/skills/rednote-monitor/scripts"
bash "${skill_dir}/check-all.sh"
6. 生成趋势图
skill_dir="${HOME}/.workbuddy/skills/rednote-monitor/scripts"
bash "${skill_dir}/gen-trend.sh" <task_id>
自动化定时
创建 WorkBuddy 自动化,定时执行 check-all.sh。
注意:WorkBuddy 自动化最低频率为 HOURLY(不支持 MINUTELY)。
创建自动化时使用 automation_update:
scheduleType: "recurring"rrule: "FREQ=HOURLY"(最小间隔为每小时)status: "ACTIVE"- prompt 内容必须包含 MCP 启动步骤:
1. 启动 MCP 服务:/Users/chengjianfen/.local/bin/xiaohongshu-mcp -port :18060 &>/tmp/rednote-mcp-tmp/mcp.log & 并等待 5 秒
2. 运行:bash /Users/chengjianfen/.workbuddy/skills/rednote-monitor/scripts/check-all.sh
3. 如果输出包含 "ALERT",将告警内容展示给我;否则静默完成
告警方式
支持三种方式,通过 send-alert.sh 的 method 参数控制:
| method | target | 说明 |
|--------|--------|------|
| chat | 无需 | 输出 ALERT: 前缀文本,由自动化 prompt 捕获后在对话中通知 |
| wecom | Webhook URL | 企业微信群机器人,格式 https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx |
| email | 邮箱地址 | 通过系统 mail 命令或 Python SMTP 发送 |
企业微信 Webhook 获取:
- 电脑端企业微信:群聊 → 右键 → 群设置 → 群机器人 → 添加/查看 → 复制 Webhook 地址
- 注意区分「机器人管理页面 URL」(
work.weixin.qq.com/wework_admin/...)和「Webhook URL」(qyapi.weixin.qq.com/cgi-bin/webhook/send?key=...)
反检测机制
check-all.sh 内置以下防护:
- 频率抖动:实际执行间隔 = 设定间隔 ± 20% 随机值
- 操作间隔:每次 MCP 调用间随机等待 3-8 秒
- 单会话复用:所有任务共用同一 MCP 会话,避免频繁握手
- 批量延迟:一次轮询中如有 N 个任务,总耗时约 N×(3~8)秒,不触发并发检测
- 失败退避:连续失败 3 次后暂停该任务 1 小时,避免异常请求堆积
数据存储
rednote-monitor/
├── data/
│ ├── tasks.json # 任务配置
│ ├── {task_id}/
│ │ ├── 2026-06-30.json # 当日轮询数据
│ │ ├── 2026-07-01.json
│ │ └── ...
│ └── alerts.json # 告警记录(最近100条)
tasks.json 结构
{
"tasks": [
{
"id": "uuid",
"name": "备注名",
"feed_id": "笔记ID",
"xsec_token": "安全令牌",
"note_url": "原始链接",
"note_title": "笔记标题",
"metrics": {
"likes": { "threshold": 1000, "enabled": true },
"comments": { "threshold": 200, "enabled": true },
"collects": { "threshold": 100, "enabled": false },
"shares": { "threshold": 50, "enabled": false }
},
"interval": 900,
"alert": {
"method": "chat",
"wecom_webhook": "",
"email": ""
},
"status": "active",
"created_at": "2026-06-30T16:30:00+08:00",
"last_checked": null,
"last_metrics": {},
"alerted_metrics": {},
"consecutive_failures": 0
}
],
"settings": {
"anti_detect": {
"jitter_percent": 20,
"call_delay_min": 3,
"call_delay_max": 8,
"max_consecutive_failures": 3,
"cooldown_minutes": 60
}
}
}
每日数据文件结构
{
"task_id": "uuid",
"date": "2026-06-30",
"records": [
{
"time": "09:15:03",
"likes": 234,
"comments": 45,
"collects": 89,
"shares": 12,
"alerted": false
}
]
}
alerts.json 结构
{
"records": [
{
"task_id": "uuid",
"task_name": "备注名",
"time": "2026-06-30T09:15:00+08:00",
"metric": "likes",
"current_value": 1023,
"threshold": 1000,
"sent": true,
"method": "wecom"
}
]
}
注意事项
- 一次不要同时监测超过 20 条笔记(MCP 单次会话承载上限)
- xsec_token 可能过期,如果检查时发现数据拉取失败,尝试重新搜索获取新 token
- 企业微信 Webhook 每分钟限制 20 条消息
- 数据文件按天归档,超过 30 天的数据可考虑压缩归档
- 反检测措施能降低风险,但不能 100% 保证不被检测
Scan to join WeChat group