get_recent_messages
Retrieve recent private and group QQ messages from the local in-memory cache to poll live traffic or filter by chat type, target ID, or keyword.
Instructions
读取 MCP 服务后台通过 WebSocket 实时监听并保存在本地环形内存缓存池(上限 200 条,按登录账号隔离)中的近期 QQ 消息列表。
适用场景:快速轮询或按条件检索服务运行期间实时收到的最新私聊与群聊消息。不适用与替代:若需查询 MCP 启动之前的历史聊天记录或向更早页码翻页,请通过 call_napcat_api 调用 get_friend_msg_history 或 get_group_msg_history;若需查看加群/加好友审批请求或群撤回通知,请调用 get_recent_notices_and_requests。
参数约束与交互:当指定 target_id 时,若 chat_type='group' 则按群号过滤,若 chat_type='private' 则按发送者 QQ 号过滤,若 chat_type='all' 则同时匹配群号或 QQ 号;keyword 对净化后的消息文本 clean_text 与发送者昵称做大小写不敏感子串匹配。
行为与返回:纯内存只读操作(零外部网络延迟,不修改缓存状态);返回 ws_connected、count 及 messages 数组(每项含 message_id, chat_type, user_id, group_id, sender_name, clean_text, time)。
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_recent_messages"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| count | No | 返回的最大最新消息条数(范围 1~200,默认 20) | |
| keyword | No | 按消息正文或发送者昵称/群名片包含的子串关键词过滤;留空不过滤 | |
| chat_type | No | 会话范围过滤枚举: 'all'(全部消息)、'private'(仅私聊)、'group'(仅群聊),默认 'all' | all |
| target_id | No | 限定特定群号(group_id)或特定好友 QQ 号(user_id)的正整数 ID;留空不过滤 | |
| include_self_sent | No | 为 True 时包含当前登录账号自己发出的消息,为 False 时仅返回他人发来的消息,默认 False |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| data | No | 接口返回的业务负载数据(对象或数组,具体字段依工具而定) | |
| status | No | 执行状态标识,成功为 'ok'(或特定生命周期状态),失败为 'failed' 或 'error' | |
| message | No | 状态说明或错误诊断详情 | |
| retcode | No | OneBot 11 响应状态码,0 表示成功,非 0 表示协议端或网络错误 |